Everyone knows it is a good idea to backup your data. However, the good ol’ copy’n’paste routine is time consuming, inefficient, and prone to errors. By using rsync, you can achieve efficient synchronisation of files as only the change in data will be transferred.

For example, you might want to synchronise your home directory, /home/username/, to your external hard drive, /media/externalhdd/homebackup/. A oneliner is all that is needed:

rsync -ra --progress --stats --log-file=rsynclog /home/username/ /media/externalhdd/homebackup

The options used are:

  • -r recursive (includes subfolders)
  • -a archive (preserves, ownership, timestamps, etc.)
  • –progress (shows progress of files being synchronised)
  • –stats (print some statistics after synchronisation)
  • –log-file=rsynclog (save useful information in file rsynclog in current directory)

For other options, do

rsync --help

You can also use rsync for synchronisation to remote servers. If so, you may do

rsync -ra --progress --size-only /home/username/ server.example.com:/home/username/homebackup/

Note that such a connection to a remote server is insecure! You should be using SSH. Google it to find out how. One possible starting point is here.

Finally, you may want to use a script that runs at scheduled times to automate your backup process. An example script can be downloaded here (see below). Modify the script by removing the user input and use cron to run it at regular times, e.g., every night.

Download rsyncbackup.sh

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)