Backup Ubuntu using rdiff-backup

Sponsored Link
rdiff-backup backs up one directory to another, possibly over a network. The target directory ends up a copy of the source directory, but extra reverse diffs are stored in a special subdirectory of that target directory, so you can still recover files lost some time ago. The idea is to combine the best features of a mirror and an incremental backup. rdiff-backup also preserves subdirectories, hard links, dev files, permissions, uid/gid ownership, modification times, extended attributes, acls, and resource forks. Also, rdiff-backup can operate in a bandwidth efficient manner over a pipe, like rsync. Thus you can use rdiff-backup and ssh to securely back a hard drive up to a remote location, and only the differences will be transmitted. Finally, rdiff-backup is easy to use and settings have sensical defaults.

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:

ssh [email protected]

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.

Sponsored Link

You may also like...

6 Responses

  1. visctrix says:

    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

  2. Jacobian says:

    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.

  3. Jack Robert says:

    That was a great blog. Most blogs are not even worth reading.

  4. Samson G. says:

    Are you planning to blog more on this topic. I would like to learn more.

  5. san says:

    Is this cron going to take incremental backup?

  6. Aethera says:

    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!

Leave a Reply

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