My company runs a web server without any real backup. Lately we’ve seen some strange file system stuff going on (we use reiserfs) and decided it’s high time to fix some kind of backup solution.
rsync came to the rescue!
This is a straight forward “guide” (or something) on how to set it up. We have a machine which initiates the backups every day at 05:00. This computer is the backup. Let’s call it thishost.
We want this to be secure thus we’ll use ssh. So, first we need to create a key pair so rsync doesn’t need to prompt for a password each time we run it.
Accept the default path (~/.ssh/id…) and specify and empty passphrase.
(Same procedure as with -t rsa)
Try connecting to remotehost and see if it lets you in:
If it worked, log out and continue on thishost. If not, you did something wrong. Log out and try again from the beginning.
Now you can setup a cron job running something like this:
This will backup the /some/dir on remotehost to the /backups/host/some–dir on thishost at 05:00 (5 AM) every day.
In my case, I needed to backup quite a few things on remotehost
, so I wrapped all backup runs in a script which is triggered by cron.
The modersynk
function takes the following arguments:
I setup cron like this:
Simple as that! Works great and the level of complexity is, in my point of view, very low.