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 up
isync
service is now running:
/mbsyncrc
config file is created/backup.sh
is created/notify.sh
is created- A crontab is created that runs
/sync
,/backup.sh
, andnotify.sh
daily at00:00
crond
is started
View /mbsyncrc
config:
docker-compose exec isync cat /mbsyncrc
Run a first-time sync (this will fail, because test@example.com
is not a real account. See next step):
docker-compose exec isync /sync
Since 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/.uidvalidity
Finally, list the files:
docker-compose exec isync find /mail
Perform 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.sh
The 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 saved
Now, 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 /mail
List backup files:
docker-compose exec isync find /backup
If /mail
is ever lost, restic restore
can easily restore the data.
First, list the backup snapshots:
docker-compose exec isync restic snapshots
You 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 snapshots
Restore the latest snapshot 81ec9c8f
to the /restore
volume:
docker-compose exec isync restic restore 81ec9c8f --target /restore
List restored files in /restore
:
docker-compose exec isync find /restore
If 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 /mail
List restored files in /mail
:
docker-compose exec isync find /mail
The backup is fully restored.