Post

Setup rSnapshot backups on CentOS

1390262400
1666884241
6

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:
1
yum -y install rsync rsnapshot
  1. 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):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
config_version  1.2
snapshot_root   /data/backups/snapshots/server/
cmd_cp  /bin/cp
cmd_rm  /bin/rm
cmd_rsync       /usr/bin/rsync
cmd_ssh /usr/bin/ssh
cmd_logger      /usr/bin/logger
#cmd_du /usr/bin/du
interval        daily   7
interval        weekly  4
interval        monthly 3
verbose 3
loglevel        4
logfile /var/log/rsnapshot/backups.log
exclude_file    /etc/rsnapshot/backup_config.exclude
rsync_long_args --delete        --numeric-ids   --delete-excluded       --stats
lockfile        /var/run/rsnapshot.pid
backup  root@spitfiredev.com:/  mp-vps01
rsync_long_args --stats --delete        --numeric-ids   --delete-excluded
retain  daily   14

It is important to use tabs between each argument otherwise you will receive errors.

  1. 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):
1
2
3
4
5
+ /var
+ /var/www
- /var/*
+ /home
- /*

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 don’t need to use tab in this file)

  1. Create the directory for backups and logs to be stored:
1
2
mkdir -p /data/backups/snapshots/server/
mkdir -p /var/log/rsnapshot/
  1. Test the backup by running:
1
/usr/bin/rsnapshot -c /etc/rsnapshot/mp-vps01.conf

If successful move on if not troubleshoot, ask below if you get stuck.

  1. Schedule the backup with crontab:
1
2
crontab -e
0 0 * * * /usr/bin/rsnapshot -c /etc/rsnapshot/mp-vps01.conf daily

If you would like email alerts use the following:

1
0 0 * * * /usr/bin/rsnapshot -c /etc/rsnapshot/mp-vps01.conf daily | mail -s "My Backup Job" your@email.co.uk

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!

This post is licensed under CC BY 4.0 by the author.