Backup Ubuntu using rdiff-backup
Sponsored Link
Install rdiff-backup in ubuntu
If you want to install rdiff-backup in ubuntu use the following command
sudo apt-get install rdiff-backup
Because rdiff-backup is using SSH, which asks for a password upon logging in, it will require human interaction during the actual back-up process. And because we are trying to setup an automated process, this is not what we want. Fortunately, this problem can be easily skipped by using SSH public keys. So, we'll need to create a pair of keys on the home computer, one of which will be saved on the work computer. Basically, these keys will tell the work machine that the home machine is allowed to login through SSH.first you need to make sure both machines installed with openssh.
Install openssh using the following command
sudo apt-get install openssh
Now you need to Generate a DSA key pair on the USA computer
ssh-keygen -t dsa
Hit enter when you are asked for the target directory and for the passphrase.
Send the public key to the UK computer:
(The UK computer has to have used the ssh client, otherwise, the .ssh directory won't exist)
cd $HOME
scp .ssh/id_dsa.pub [email protected]:~/.ssh
Log in to UK PC and add the key to the list of authorized keys:
cd .ssh
cat id_dsa.pub >> authorized_keys2
rm -rf id_dsa.pub
Test if everything is ok: Log out and log back in, this time, you shouldn't be asked for a password.
Back-up process
we want to do here is back-up the scripts/ directory on the UK PC to the USA PC. To do this, type the following command on the USA machine
rdiff-backup -v4 --print-statistics [email protected]:://home/UK-user/scripts/ scripts/
Automate Backup process with crontab
On the USA machine, type the following command to open the crontab editor
crontab -e
It will open vi.Once it started, Now, add the following line
15 1 * * * /usr/bin/rdiff-backup [email protected]:://home/UK-user/scripts/ scripts/
save and exit the file
As of now, every night at 1:15, the scripts directory from the UK PC will be saved to /home/USA-user/scripts directory and will be updated if any scripts are added to the work directory.
Two comments/questions:
Firstly you switch confusingly between home – work pcs, and USA – UK pcs – and neither of these descriptions is very useful – can you change the text pair to home – backup pc?
Secondly my two pcs are rarely connected and never powered up at 1.15am. I’d like to use a script to execute this backup periodically when I get round to it. Can you include brief instructions for this.
Thanks
Visctrix, it sounds like you’d be better off with anacron:
http://en.wikipedia.org/wiki/Anacron
That will make sure your home computer is backed up regularly, even if it’s not always turned on at 1:15am.
That was a great blog. Most blogs are not even worth reading.
Are you planning to blog more on this topic. I would like to learn more.
Is this cron going to take incremental backup?
Actually you can simply the SSH key-sharing process considerably with the ssh-copy-id command which is part of ssh in Debian and Ubuntu. No need to manually copy the file to the remote host and append it to the authorized_keys file! Just:
apt-get install ssh
ssh-keygen -t rsa #say yes to defaults. when it #asks for password, this is not necessary. it is #only a password to view the local copy of the #key – its safe to say no
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remotehost
And that is it!