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/id-rsa.pub 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* firstname.lastname@example.org:/mnt/backupdir/
-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
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* email@example.com:/mnt/backupdir/
It works for me.
Another option for rsync is -P means progress copy is displayed in our screen.
source : ubuntuforum