Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At the moment i do a simple Mail-Backup: On the server there is a Maildir, and i use rsync to sync the Maildir from server to backup.

So i delete on the Server every file which is older than i.e. one month. So i have only the latest mails on the server and the rest in the Backup only. So i do not use much space on the server, and if somebody hacks me, he will get only a month of mails instead of the whole archive.

the commands i use are:

rsync -avz Maildir/ backupserver:backup/Mails/
cd Maildir
touch -d 2011-07-30 dummy
find -type f \! -newer dummy -delete

That is working pretty good, but when i move a mail, which is already in the backup, i will have two copies of the mail in the backup. One copy from the old backup job, one from the new one. Or i may even decide to delete the mail and it will not be deleted in the backup.

I could use rsync with --delete, but then i need to have the full archive on the server, because otherwise it will delete the old mails in the backup, too.

So now my question is: How can i sync the Mails in a way, that preserves moves and deletions?

share|improve this question
Only with manual work. The Message-ID in each mail should be unique. This gives you the possibility to keep track of every mail. But for my subjective opinion your type of "backup" is strange. – mailq Aug 30 '11 at 18:11
I don't think you can, because you want to preserve the mails that are deleted by the system on day 30 but delete the mails that are deleted manually on day 29. – tomjedrz Aug 30 '11 at 19:18
what is a good idea for having only the latest mails on the server and the rest in a backup? An alternative would be to move mails older than 30 days to backup. i.e. via rsync parameter for only including old mails and then deleting or by using some imap tool. But then i do not have the most recent mails in the backup. Of course i can find double-mails by message-id, which i will need to do with the current backupset some time. But then i need to re-decide for every mail which folder is the "correct" one. – allo Aug 30 '11 at 20:00
up vote 0 down vote accepted

Okay, i think i have found a solution:

Using Syncmaildir, i keep my E-Mails from the local maildir in sync with the remote maildir. When i want to delete old mails from the server, but not from the backup, i first sync a last time, which syncs added/deleted/moved mails, then i remove the mail-db from the local and the remote .smd/ folder and delete the old mails.

Steps in Detail:

  • sync mails with smd-pull
  • when removing old mails from the server:
    • sync a last time with smd-pull
    • delete the old mails with the find-cmdline.
    • delete .smd/profilename__Mail.db.txt* files locally/remotely
    • sync again, so the db gets rebuild for the remaining files, so moves/deletions can be detected.
  • sync mails as always
share|improve this answer
maybe not even rebuilding the db, but just using mddiff to check which mails generate a "DELETE" command after the delete step, and removing the corrosponding lines from the .smd/profilename.db.txt file. – allo Dec 9 '11 at 9:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.