Selasa, 02 Juli 2013

Zimbra 8 - automatic backup & restore via script

Some longer time I announced here my plan to make my mail server failsafe. I went for a rather simple approach, because I use Zimbra 8 Open Source Edition.
Every night a make a backup of the mailboxes on server 1 and import them to server 2.
I wrote two bash scripts. One runs, invoked by a daily cronjob in context of the root user, on the primary mail server and creates a backup of all mailboxes. Which mailboxes should be backed up is defined in a text file (this file is parsed with:while read). The command for backing up and restoring mailboxes is 'zmmailbox'.
Example: zmmailbox -z -m getRestURL "//?fmt=zip" > /home/zmbackup/"
At the end of the script the zipped files are rsynced to the secondary mail server. The rsync runs in the context of another user, which is only allowed to run rsync on the backup mail server and authenticates with a passwordless ssh key.
Then, on the second host, another bash script starts which restores the backups. It starts one hour later than the backup script on the primary host, to make sure that backup and rsync on the primary server have finished.
Example: zmmailbox -z -m postRestURL "//?fmt=zip&resolve=reset"/home/zmrestore/
At the beginning of the first and at the end of the second bash script the zip files are deleted, no to flood my disk with backups.

Tidak ada komentar:

Posting Komentar

Silahkan beri komentar ?