Backups using Rsync website to home server

I have remotely hosted websites and my home network. Following some recent almost disasters I figured that it was time to create some automatedbackup processes.

So I started with one remote site and my SMEServer at home and used Troy’s guide mostly.

One change was that I have alternative port settings for SSH connections, so I had to modify this line:

$ rsync -avz -e ssh remoteuser@remotehost:/remote/dir /this/dir/

to

$ rsync -avz -e ‘ssh -p 3333’ remoteuser@remotehost:/remote/dir /this/dir/

the single quotes around the ssh command separates its parameters from the rsync parameters so you can add other ssh options if needed.

Making the keys etc worked fine, but a similar setting is required when transferring via scp.

scp /home/thisuser/cron/thishost-rsync-key.pub remoteuser@remotehost:/home/remoteuser/

changes to

scp -P 3333 /home/thisuser/cron/thishost-rsync-key.pub remoteuser@remotehost:/home/remoteuser/

note that ssh uses -p (lowercase) while scp uses -P (uppercase) to change/set the port #.

I also liked Troy’s verbose ‘whoami’ line

$ echo I am now $USER at $HOSTNAME

but I also used

$ pwd

to check what directory I was actually using before continuing.

Two things tripped me up when testing just prior to the cron job configuration.

So to debug I started by stripping the authorised keys back to just the certificate and it was fine. I then added in the command string to that file and tested again only to get a password prompt.

The issue was that I had the validate-rsync script on the local host and not the remote server so I copied that file to an appropriate location on the remote host and tried again and that worked.

The second issue was with the ‘from=’ host setting in which I tried the hostname rather than ip address and rsync did not like that at and again prompted for the password. Changing it to the ip address worked. Not sure why this is as all the documentation I have read indicates that the text option should work. I’ve left it as the ip address for now.

Having done that and proved that it all worked added a new template into /etc/e-smith/templates-custom/etc/crontab called 70remotebackups and added these lines:

$OUT = “”;
# note to self as to what this is doing
$OUT .=
“05 2 * * * root” . ” /home/e-smith/files/ibays/backups/files/scripts/myremotebackup.shn”;

This is setup so that I can add another site script into the same crontab component file.Then I ran the process to include my new custom template into the crontab file.

/sbin/e-smith/expand-template /etc/crontab

No need to restart anything as cron will pick up the changes automatically.

Throughout all the testing I have already got the first initial copy of my entire website and a few changes so thats all working nicely.

The next step at some point is to prepare further copies of the same stuff in order that I can recover intermediate changes when required. But that is another day.

One reply

Leave a Reply

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