Saturday, December 19, 2009

Backing up your computer files with rsync

If you're paranoid about losing ages and ages of work you need to find a way of backing up your computer files!  In Windows I would use a program called Save-n-Sync to make sure that a synchronized copy of all my work files could be saved on a backup source.  In Linux this can be done with one command in the terminal using a shell program called rsync

rsync -r -u --log-file=[path for your new log file] --stats [path for your source directory] [path for your target directory]

I'll explain the arguments:

  • -r tells it to recurse through the subdirectories of your specified source directory, meaning that it will synchronize files found directly in the source directory, but also files found within subdirectories inside your source directory.
  • -u tells it that if a file is in both the source and target directory, it should only update the target directory file if it is an older version than the one in the source.
  • --log-file=[path for your new log file] is the command you should use if you want the results of your file sync to be saved in a log file named however you like.  For example:  --log-file='/home/user/Desktop/Backup Log.txt'
  • --stats tells it to output some useful file sync statistics for you such as how many files were scanned through, transferred, size of the transfer, etc.
  • [path for your source directory] should be replaced with your source directory such as '/media/USB Stick'
  • [path for your target directory] should be replaced with your target directory such as '/media/Backup Drive'
You can add or take away whatever of these options you like and many many more.  Type in rsync --help in the terminal to learn more.  Now, if you don't feel like typing this command in every time you want to back your stuff up then you can create the equivalent of a shortcut, in Ubuntuspeak a 'Launcher', on the desktop. Do the following and all you'll have to do is double click on your launcher icon to back your files up:
Creating launchers is simple!                 

  • Right-click (or if you're a lefty, left-click) on your desktop and select Create Launcher
  • The selection next to Type: should be left as Application
  • Beside Name: you can put whatever you like to indicate that it's a Launcher for your backup command
  • Now next to Command: put in your full rsync command with all the arguments discussed (or not) above
  • Feel free to click on the icon box at the top left to select a more interesting icon for your backup launcher (i.e. select an icon, and press OK)
  • Press OK when you're done and now you have a Launcher that you can double click whenever you need to back your stuff up!

Happy file-synchronizing!  This program does a blazing fast job :)

No comments:

Post a Comment