Table of Contents
Rsync
After you have setup ssh to work without passwords you can configure your server to perform incremental backups by getting cron to schedule rsync tasks.
Basic Rsync Usage
Before scheduling rsync
to run under cron
its best first to work out how you want to run it. A full description of how to use rsync
is not appropriate here (see various tutorials instead), but lets back up our pictures folder (~/pics/
) to the ReadyNAS.
$ rsync -av ~/pics readynas:~/.
Thats it, very simple. I purposefully do not use the -z
switch for compression as my pictures which are mainly JPEG are already in a compressed format so using compression gains nothing and actually increases the run-time slightly as the individual files require compressing and then decompressing at either end. If this is the first time its been run then it will take a while to transfer all your data, but after that incremental back-ups will be very quick.
Scheduling Rsync
Now that you have a working rsync
command you need to schedule it to run with cron
. There are a number of different cron
implementations, personally I use fcron because it works well running tasks that should have run when a system has been turned off.
Creating a script
You need to create a script which contains two commands, one to ensure your key, which is stored by keychain is loaded, because when you run a script its essentially a new login, and the second to actually run the above rsync
command. Create the file in ~/bin
…
$ mkdir ~/bin $ echo '#!/bin/bash' > ~/bin/rsync.pics $ echo 'source ~/.keychain/$HOSTNAME-sh' >> ~/bin/rsync.pics $ echo '/usr/bin/rsync -av ~/pics/* readynas:~/pics/.' >> ~/bin/rsync.pics $ chmod 0755 ~/bin/rsync.pics