Install and setup rsnapshot to make automated backups
From OpenFSG
Contents |
rsnapshot
rsnapshot is a filesystem snapshot utility for making backups of local and remote systems.
Using rsync and hard links, it is possible to keep multiple, full backups instantly available. The disk space required is just a little more than the space of one full backup, plus incrementals.
Depending on your configuration, it is quite possible to set up in just a few minutes. Files can be restored by the users who own them, without the root user getting involved.
Info
I have installed rsnapshot on the FSG with firmware 3.3.9 but it should work on other firmware versions as well. Compiling the latest version from source also produced a working setup.
Backing up to external usb HDD's works perfectly, but one needs to use a ext3 or similar formatted drive that supports hard links. So no FAT32 or NTFS drives.
Installing rsnapshot
Before starting log in as root and install the official ipkg bootstrap first!
The following should also be installed as root.
- Install Perl "ipkg install perl"
- Install Rsync "ipkg install rsync"
- Install rsnapshot "ipkg install rsnapshot"
Optionally one can install the gnu coreutils. This if you want to use gnu cp (busybox cp does not support cp -al yet) If you want to compile the latest rsnapshot from source yourself install the optware-devel package (make, libraries, etc) as well.
- Install coreutils "ipkg install coreutils"
- Install make "ipkg install optware-devel"
- Copy the defaults file to make a working personal configuration file while keeping your original as a backup: "cp /opt/etc/rsnapshot.conf.default /opt/etc/rsnapshot.conf"
Setting up rsnapshot
Edit the /opt/etc/rsnapshot.conf file and use the following settings as a working example:
snapshot_root (--> path to your .snapshot directory (backup goal path)) cmd_cp /opt/bin/cp cmd_rm /opt/bin/rm cmd_rsync /opt/bin/rsync cmd_du /opt/bin/du cmd_rsnapshot_diff /opt/bin/rsnapshot-diff interval hourly 6 interval daily 7 interval weekly 7 interval monthly 3 verbose 2 loglevel 3 logfile /var/log/rsnapshot lockfile /var/run/rsnapshot.pid link_dest 1 (--> if you do not want to use gnu cp, but the hardlinking provided by rsync backup (--> path of the directory you want to backup (backup source path)) Make sure your /etc/rsnapshot.conf file has all elements separated by tabs. Make sure you put a trailing slash on the end of all directory references.
- Test your configuration file with: "/opt/bin/rsnapshot configtest".
rsnapshot can be used by any user, but for system-wide backups you will probably want to run it as root. Since backups usually get neglected if human intervention is required, the preferred way is to run it from cron.
When you are first setting up your backups, you will probably also want to run it from the command line once or twice to get a feel for what it's doing: "rsnapshot hourly" or "rsnapshot daily", etc..
Creating automated backups with cron
Define the intervals hourly, daily, weekly and monthly in /etc/rsnapshot.conf. Underneath the default values are displayed, adjust it to your personal backup needs.
Edit /etc/init.d/croninit and look for:
echo "$PERIOD" >> /etc/crontab fi
Under this add the following new lines:
echo "0 */4 * * * root /opt/bin/rsnapshot hourly" >> /etc/crontab echo "50 23 * * * root /opt/bin/rsnapshot daily" >> /etc/crontab echo "40 23 1,8,15,22 * * root /opt/bin/rsnapshot weekly" >> /etc/crontab echo "30 23 1 * * root /opt/bin/rsnapshot monthly" >> /etc/crontab
This example will do the following:
- 6 hourly backups a day (once every 4 hours, at 0,4,8,12,16,20)
- 1 daily backup every day, at 11:50PM
- 4 weekly backups a month, at 11:40PM, on the 1st, 8th, 15th, and 22nd
- 1 monthly backup every month, at 11:30PM on the 1st day of the month
Issues
- The coreutils du creates a segmentation fault when using "rsnapshot du" to check the disk space used by rsnapshot. Work around this by using the busybox du.
- Coreutils cp did work in my config, but failed when going from daily to monthly. Don't know why and use the rsync provided hardlinking as workaround.
Credits
Credits to the guys from NSLU2, rsync and rsnapshot for their excellent work and info!
