Setup Full Server Remote Backup using rsync via SSH


Full Server Remote Backup using rsync via SSH



Step1:

Login to your server via ssh which you want to take backup. Login as root user.

Check the rsync operation in your server. This time it will ask for the password.

root@server [~] # rsync -avz -e ssh /test root@<BackupServerIP>:/backup/

You have to follow Step2 to make key based ssh login from a particular IP.


Step2:

In order to run the cronjob for creating backup, you need to configure rsync over ssh that doesn’t ask for a password.

Create an RSA encryption key for use with the SSH transport.

root@server [~] # ssh-keygen -t rsa -N ''

Use ssh-copy-id, to copy the public key to the remote host(Backup server).

root@server [~] # ssh-copy-id -i ~/.ssh/id_rsa.pub root@<BackupServerIP>

This time it will ask for the ssh password for the root user to copy the key.


Step3:

Test rsync over ssh without password

root@server [~] # ssh <BackupServerIP>

Now, you should be able to ssh to remote host without entering the password. If it is working fine perform a test rsync operation. It will not ask for password this time.

root@server [~] # rsync -avz -e ssh /test root@<BackupServerIP>:/backup/


Step4:

If Step3 passed the tests with rsync, you have to make a cronjob to run the backup periodically.

root@server [~] # crontab -e
0 1 * * * rsync -avz --exclude=/proc --exclude=/sys --exclude=/dev -e ssh / root@<BackupServerIP>:/backup



The above cronjob will take backup of the entire server excluding /proc, /sys and /dev direcories. The above cronjob will run on every day at 1AM.

Reference:
http://www.tutorialspoint.com/unix_commands/rsync.htm
http://www.thegeekstuff.com/2011/07/rsync-over-ssh-without-password/

This entry was posted by Unknown. Bookmark the permalink.

Leave a Reply