Last active
July 6, 2016 14:35
-
-
Save maximishchenko/30f9e8eef4b1a40d7590 to your computer and use it in GitHub Desktop.
Linux_backup_and_restore_dovecot_maildir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#for run backup function from this script need run: | |
# source </path/to/this_script_name>.sh; backup>/dev/null 2>&1 | |
#for run restore function from this script need run: | |
# source </path/to/this_script_name>.sh; restore>/dev/null 2>&1 | |
curdate=`date +%Y-%m-%d_%H-%M-%S` | |
host=MAIL.GORODAVTO.COM | |
backup_report_text="Backup emails complete successfully" | |
backup_report_theme="Backup emails on '$host' at $curdate" | |
restore_report_text="Restore emails complete successfully" | |
restore_report_theme="Restore emails on '$host' at $curdate" | |
[email protected] | |
# vmail user | |
dovecot_user=vmail | |
# vmail group | |
dovecot_group=vmail | |
# email to backup | |
[email protected] | |
# domain to backup | |
backup_domain=gorodavto.com | |
# backup archive extension | |
backup_archive_ext=tar.gz | |
# maildir to backup | |
backup_maildir=/home/$dovecot_user/$backup_domain/$backup_email | |
# backups destination path | |
backup_destination_path=/home/backups/maildir/$backup_email | |
# backup function | |
backup(){ | |
mkdir $backup_destination_path | |
rsync -rpz $backup_maildir/* $backup_destination_path/ | |
chown $dovecot_user:$dovecot_group -R $backup_destination_path | |
tar -czvf $backup_email.$backup_archive_ext $backup_destination_path | |
rm -rf $backup_maildir/cur/* | |
echo $backup_report_text | mail -s "$backup_report_theme" $report_recipient | |
} | |
# restore function | |
restore(){ | |
rsync -rpz $backup_destination_path/* $backup_maildir | |
chown $dovecot_user:$dovecot_group -R $backup_maildir | |
echo $restore_report_text | mail -s "$restore_report_theme" $report_recipient | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment