Submit Blog  RSS Feeds

Tuesday, January 8, 2013

Incremental backups with rsync

There are two types of computer users in the world: those who backup their data, and those who eventually will backup their data. Making regular backups consumes some time, but saves a lot of nerves and time(money) the primary data source crashes. Let's face it, backups are important.

Program source codes usually do not make problems, there are distributed version control systems with remote repositories which are ideal for not only sharing but also backing up the data.

Usually there are gigabytes of data that you will want to backup besides your source code. A good place for such backups is a remote storage or an external drive. If you'd like to automate the backup process as much as possible I suggest using rsync. It enables making incremental backups, which save your Internet bandwith / makes it faster to synchronize external drives. The following makes an incremental copy of some directories located in the home directory.


declare -a SOURCE_DIRS=("a" "b" "img" )

BACKUP_DIR=/mnt/backup/


for source_dir in ${SOURCE_DIRS[@]}
do
    echo "Current directory: $HOME/$source_dir"
    rsync -a "$HOME/$source_dir" $BACKUP_DIR
done
sync
echo "Backup complete"


This works exceptionally well. The -a option stands for:

  • -r, --recursive recurse into directories
  • -l, --links copy symlinks as symlinks
  • -p, --perms preserve permissions
  • -t, --times preserve modification times
  • -g, --group preserve group
  • -o, --owner preserve owner
  • --devices, preserve device files
  • --specials, preserve special files
More available at the rsync manual.

Cheers!
KR

2 comments:

free counters