I posted recently about setting up a microserver and included a rsync script for backing up my files to the server. At the time, I was running it manually, but since have sorted out the excludes list and have now automated it.
My original scheme was to set up a cron job and mount an NFS share before rsync’ing the directories across. In the end, I went with SSH and public key authentication as debugging all of the various permissions issues with the NFS share did not seem worth the effort.
First, on my local desktop, I created the keypair called, inventively, rsync:
1 2 3 |
|
This keypair was created without a passphrase so that the script could
be successfully called from cron
. To slightly increase the security
around a key without a passphrase, I used the from option in
authorized_keys1, to restrict access to the IP address of the client
machine(s), like so:
1
|
|
It was then just a matter of adding a line to my crontab
:
1 2 |
|
To further simplify matters, I created an alias in $HOME/.ssh/config for the SSH command:
1 2 3 4 5 |
|
And I was done. Everynight at 10pm, all of my data will be backed up to the server. The rsync command in the script:
1 2 3 4 5 6 |
|
Notes
- All of the options are detailed in man sshd(8).
Creative Commons image from skreuzer.