This demo shows a cron-based sync of IMAP to a local Maildir in /mail, and a cron-based backup of mail using restic, in the same container.
Start the container(s):
docker-compose upisync service is now running:
/mbsyncrcconfig file is created/backup.shis created/notify.shis created- A crontab is created that runs
/sync,/backup.sh, andnotify.shdaily at00:00 crondis started
View /mbsyncrc config:
docker-compose exec isync cat /mbsyncrcRun a first-time sync (this will fail, because test@example.com is not a real account. See next step):
docker-compose exec isync /syncSince there's no such IMAP account as test@example.com, let's create some files in /mail to simulate a successful sync:
docker-compose exec isync mkdir -p /mail/INBOX /mail/INBOX/cur /mail/INBOX/new /mail/INBOX/tmp
docker-compose exec isync touch /mail/INBOX/new/123 /mail/INBOX/new/456
docker-compose exec isync touch /mail/INBOX/.mbsyncstate /mail/INBOX/.uidvalidityFinally, list the files:
docker-compose exec isync find /mailPerform a first-time backup of /mail using restic. This helps to ensure subsequent cron-based restic backups are speedy, since restic backups are incremental.
docker-compose exec isync /backup.shThe backup should succeed:
Files: 4 new, 0 changed, 0 unmodified
Dirs: 5 new, 0 changed, 0 unmodified
Data Blobs: 0 new
Tree Blobs: 5 new
Added to the repository: 2.758 KiB (1.341 KiB stored)
processed 4 files, 0 B in 0:00
snapshot c9ed53b0 savedNow, wait out for 00:00 of tomorrow.
At 00:00, the incremental sync and incremental backup would run very quickly. A notification of the cron status would be sent to https://example.com using curl.
List synced files:
docker-compose exec isync find /mailList backup files:
docker-compose exec isync find /backupIf /mail is ever lost, restic restore can easily restore the data.
First, list the backup snapshots:
docker-compose exec isync restic snapshotsYou should see a list of snapshots:
repository 5ba7868d opened (version 2, compression level auto)
ID Time Host Tags Paths
--------------------------------------------------------------
c9ed53b0 2023-04-15 15:48:48 346a68a05c86 cron /mail
81ec9c8f 2023-04-15 00:00:00 346a68a05c86 cron /mail
--------------------------------------------------------------
2 snapshotsRestore the latest snapshot 81ec9c8f to the /restore volume:
docker-compose exec isync restic restore 81ec9c8f --target /restoreList restored files in /restore:
docker-compose exec isync find /restoreIf all is well, clean out the /mail volume:
docker-compose exec isync sh -c 'find /mail -mindepth 1 -maxdepth 1 | xargs rm -rf'Restore the latest snapshot 81ec9c8f to the /mail volume:
docker-compose exec isync restic restore 81ec9c8f --target /mailList restored files in /mail:
docker-compose exec isync find /mailThe backup is fully restored.