In this article I will be talking you through how to use rSnapshot and rSync to backup your server with an email alert when the backup has been completed and what has been backed up.
1. You must first have rSync and rSnapshot installed:
yum -y install rsync rsnapshot
2. Once installed you will then need to create the correct configuration files for your server. Here is an example of what I use (save as backup_config.conf):
interval daily 7
interval weekly 4
interval monthly 3
rsync_long_args --delete --numeric-ids --delete-excluded --stats
backup email@example.com:/ mp-vps01
rsync_long_args --stats --delete --numeric-ids --delete-excluded
retain daily 14
NOTE: It is important to use tabs between each argument otherwise you will receive errors.
3. Now we need to create an exclude file, this will exclude any directories that you don’t want to backup. This needs to be placed in the location specified on you conf file above(save as backup_config.exclude):
NOTE: when adding a sub directory e.g. + /var/www you must first include + /var and then your sub directory, you can then exclude the existing directories as I have in my example. (you dont need to use tab in this file)
4. Create the directory for backups and logs to be stored:
mkdir -p /data/backups/snapshots/server/
mkdir -p /var/log/rsnapshot/
5. Test the backup by running:
/usr/bin/rsnapshot -c /etc/rsnapshot/mp-vps01.conf
If successful move on if not troubleshoot, ask below if you get stuck.
6. Schedule the backup with crontab:
0 0 * * * /usr/bin/rsnapshot -c /etc/rsnapshot/mp-vps01.conf daily
If you would like email alerts use the following:
0 0 * * * /usr/bin/rsnapshot -c /etc/rsnapshot/mp-vps01.conf daily | mail -s "My Backup Job" firstname.lastname@example.org
NOTE: If the backup fails the email will be empty, I still haven’t figured out how to resolve this to email the errors, If you know please let me know in the comments!