Backup mails – backup and restore
After setting up a Dovecot instance and having imapsync running, how could I do the main task, the backup?
I use tar with its incremental option (infos about can be found here and here). Also I compress the backup, if you have pigz on your computer, use it, it makes the backup a lot faster because it uses all cpu cores.
Create first backup
sudo su -
cd /var/lib/docker/volumes/dovecot-server_dovecot-server-home-volume/_data/testaccount
tar -cvzf /root/testaccount-mail-backup-20240817.tgz -g /root/testaccount-mail-backup-20240817.inc Maildir/
To use all cores while compression:
tar -cvf /root/testaccount-mail-backup-20240817.tgz -g /root/testaccount-mail-backup-20240817.inc --use-compress-program=pigz Maildir/
Create next incremtal backup
cp /root/testaccount-mail-backup-20240817.inc /root/testaccount-mail-backup-20240818.inc
tar -cvf /root/testaccount-mail-backup-20240818.tgz -g /root/testaccount-mail-backup-20240818.inc --use-compress-program=pigz Maildir/
Restore mails vom backups
cd /var/lib/docker/volumes/dovecot-server_dovecot-server-home-volume/_data/testaccount
tar -xvf /root/testaccount-mail-backup-full-20240817.tgz --use-compress-program=pigz Maildir/ -g /dev/null
tar -xvf /root/testaccount-mail-backup-full-20240818.tgz --use-compress-program=pigz Maildir/ -g /dev/null
ls -la
# (1003:1003 is the group and user-id of the testaccount, change to the values for your account)
chown -R 1003:1003 Maildir/