Backup Linux Server with rsnapshot

rsnapshot is a backup software based on rsync. It can make an incremental backup. rsnapshot makes an automatic incremental backup using rsync and cronjob. It use linux hardlinks to save disk space. When you make the first backup, all files are copied to the backup location, every subsequent backup makes a copy of the previous backup using Linux hard links, then copy over new and changed files, delete files that are removed from the source folder. This way even if you have multiple copies of the files, there is only one file stored in your disk. rsnapshot is available for installation from apt repositories in Ubuntu and Debian Linux.

https://rsnapshot.org/ (GitHub)

To install rsnapshot on Ubuntu/Debian, run

apt install rsnapshot -y

Configure rsnapshot

rsnapshot configuration file available in /etc/rsnapshot.conf, you need to edit this file to configure rsnapshot.

vi /etc/rsnapshot.conf

To change the location of backup folder, change

snapshot_root   /var/cache/rsnapshot/

I change this to /backup/

snapshot_root   /backup/

Below you will find

retain  alpha   6
retain  beta    7
retain  gamma   4

These is different backup rotations, to easily understand, I renamed it as daily/weekly/monthly

retain  daily   6
retain  weekly    3
retain  monthly   3

This will store 6 daily backups, 3 weekly backups, and 3 monthly backups.

Uncomment following lines

cmd_ssh        /usr/bin/ssh
cmd_du         /usr/bin/du

The lines starting with “backup” define the backup. These lines each parameter must be separated with TAB (space won’t work).

You can verify the configuration with the command

rsnapshot configtest

Test Backup

To see the commands used by rsnapshot to take backup, run

rsnapshot -t daily

Here is rsnapshot -t daily result for the backup command

backup	/root/		localhost/

To exclude a folder from backup, you can use +rsync_long_args=–exclude=/full/path/to/folder

Example

backup  [email protected]:/home/serverok.in/  serverok.in/  +rsync_long_args=--exclude=/home/serverok.in/html/wp-content/cache

If you ned to exclude multiple files, you can use exclude-from to specify a file with all paths to exclude.

backup	[email protected]:/home/	137.184.80.235/		+rsync_long_args=--exclude-from="/usr/serverok/exclude-server5"

NOTE: use TAB to separate each items in backup line. For arguments, use space to separate.

Running Daily Backup

To run daily automated backup, you need to set a cronjob

0 0 * * * /usr/bin/rsnapshot daily
0 6 * * 0 /usr/bin/rsnapshot weekly

This will run backup every day at 00:00 hours server time.

See Backup

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *