ssh+rsync+cron is a good combination for backup.
Let us take a simple scenario like this
a.should be done everyday at 10.30am
b.should be automatic without manual intervention.
Let us do it step by step
Stage 1: Establishing passwordless ssh connection
Login as user
Generate key pairs
myid@server$ ssh-keygen -t rsa
Now .ssh directory will have a file named id_rsa.pub. This is the public key of user myid. Copy this file to backup system using scp.
myid@server$ scp .ssh/id_rsa.pub bup@backup:~/.ssh/server.pub
Now log onto backup system
myid@server$ ssh bup@backup
bup@backup$ cd .ssh
bup@backup$ cat server.pub >>authorized_keys2
ensure that files in .ssh has read/write for owner and no permission for others and group.
Now log out of backup. You will be back at server.
Now try to login again on backup. You will not be prompted for password.
Stage 2: Creating appropriate rsync command
First let us try the rsync at command prompt in the server.
myid@server$ rsync -e ‘ssh -l bup’ -avzp /home/data/ backup:/home/backup/data
Let me explain the command in detail.
-e option allows rsync to use ssh. Rsync can use its own protocol or rsh or ssh. Here we choose ssh and give the options to ssh like -l login name inside a single quote.
-a this option lets rsync to work in archive mode, so files are copied recursively much like tar.
-v verbose gives details about files transferred
-z use compression
-p preserve permission.
While using rsync the distinction between with and without a / at the end is important when specifying source. If last / is omitted it will create a directory and then copy.
Stage 3:Converting rsync into cron job.
Store the above command in a file say mybackup.sh
myid@server$ cat mybackup.sh
rsync -e ‘ssh -l bup’ -avzp /home/data/ backup:/home/backup/data >>/home/myid/errorlog 2>&1
Here I am directing all messages to myid/errorlog file.
Grant executable permission
myid@server$ chmod u+x mybackup.sh
Now add it to cron
myid@server$ crontab -e
30 10 * * * /home/myid/mybackup.sh >>/home/myid/errorlog 2>>/home/myid/errorlog
In the above line 30 stands for minute and 10 stands for hour. Normally cronjob errors are directed to mail, but we can redirect as done above also.
If everything proper you should have a fully automated backup which is very fast also.
a.You can schedule backup more than once say every hour.
b.Improve the shell script for multiple backup depending on date and time
c.Start the backup system through wake on lan, take backup and then shutdown.