Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximishchenko/30f9e8eef4b1a40d7590 to your computer and use it in GitHub Desktop.
Save maximishchenko/30f9e8eef4b1a40d7590 to your computer and use it in GitHub Desktop.
Linux_backup_and_restore_dovecot_maildir
#!/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"
report_recipient=it@alians-kmv.ru
# vmail user
dovecot_user=vmail
# vmail group
dovecot_group=vmail
# email to backup
backup_email=fullbackup@gorodavto.com
# 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