Wednesday, February 16, 2011

---------Logging from hostserver to remoteserver without giving passwords--------

First you should create a user in both servers, in my case the username is backup_user.I created them in both machine.

Then in hostserver, I created SSH private and Public key pairs using ssh-keygen (as given below) so that backup can be automated without inputing passwords. I did this as backup_user

#ssh-keygen -t rsa -b 1024When you execute above command it will ask for several things, leave all them as default.Then at one place it will ask for passphrase. At that point, without enter any password press enter key. (In other words, leave them blank)

Then you may see two files, id_rsa and id_rsa.pub in /home/backup_user/.ssh/

Now you should copy the pub key to the remote server. To do this, execute following command :

ssh-copy-id -i /home/backup_user/id_rsa.pub backup_user@remoteserver

Now you should be able to login from hostserver to remoteserver without giving any password.

--------Making backups from hostserver to remoteserver------------------------------

**We need to create a script to make the nessary backups to backup_user's home directory with the date label. eg: Following script will create a folder with date label and server name (eg. 20101223-hostserver). Then it makes an archive of required folder in the newly created folder. (eg. in our case we get backup of mysql dir)

Then we should add a backup_user level cron to the above scipt and run that with some time after the above script (USER level cron job) crontab -e

and add folling things

30 19 * * * /home/backup_user/copy_script

According to this, all the files that we specified first backedup to hostserver it self at 18.30.Then it will be transfered to remoteserver at 19.30. It is recommended to give sufficient time between copying files to server it self and copying to remoteserver.