backup data with rsync and ssh

I have computer1 as a data source and computer2 as a backup machine, computer1 and computer2 is also an example username on both machine. I want to create a backup function using rsycn and ssh without using password so it can run in cronjob automatically on the date I command to.

First let’s work in the computer1.
Create a public ssh key
#ssh-keygen -t rsa
Press enter if it asking for the place to put id-rsa
And Press enter twice to pass the passphrase. It means it will no ask for password.

Add the /home/computer1/.ssh/ to computer2 .ssh/authorized-keys
Simply do this
enter the password of the computer2

Let’s check computer2. It should be a file called authorized-keys on .ssh folder.
Back to computer1, now time for backup.
#rsync -avzp –exclude-from=myexclude -e ssh /mnt/mydir/file*
-avzp means archive, verbose, compressed, show progress
–exclude-from=myexclude is the file that I create to pass some directory or types of file that I don’t want to backup.
The myexclude file is :

Test the rsync command in the terminal first before we put it in the cron job.

To put it a cron, let’s do this
#crontab -e
0 5 /1 * * /home/computer1/rsync-command
Type :wq to save and exit.

The rsync-command is
rsync -avzp –exclude-from=myexclude -e ssh /mnt/mydir/file*

It works for me.

Another option for rsync is -P means progress copy is displayed in our screen.
source : ubuntuforum

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.