Easy Automated Snapshot-Style Backups with Linux and Rsync

By jbayer - Last updated: Saturday, October 22, 2011 - Save & Share - 2 Comments

The inspiration for this is the original post at:  mikerubel.org

The basic idea is to create a snapshot of a directory structure using rsync.  Multiple snapshots can be created without taking up extra space by using file links for files which haven’t changed.

I was dissatisfied with the scripts there.  The ideas were good, but I wanted more flexibility in them.  After examining all the contributions, I settled on the script written by  Elio Pizzottelli, elio@tovel.it

I took his script and extended it with more options and abilities.  The attached script is the result.

  make_snapshot.sh (14.0 KiB, 456 hits)

Basic documention follows:

make_snapshot.sh  source_dir [-dev device ] [-mount mount_point ] [ (-d | --dest) dest_dir ]
 [ --sourcedir source_dir ] [--nomount ] [ -y | --yes ] [ -q | --quiet ]
 [ ( -N | --name ) backup_name ] [-f exclude_file] [ ( -l | --number ) backup_level ]
 [ ( -f | --excludefile ) exclude_file ] [ -h | --help ] [ -x | --onefilesystem ]

Explanation:

 device:      a partition device
 mount_point: a valid mount point
 source_dir:   the directory to backup

 dest_dir:     a optional destination dir, default it is unset
                 (starting from the mount_point)
 backup_name:  a name for the backup, default BAKUP
 backup_level: the number of backups to preseve, default 5, min 2
 exclude_file: a file for rsync --exclude-from, default it is unset

Example:

  /usr/local/bin/make_snapshot.sh  -dev /dev/hdd15 -mount /root/backup /home/
  /usr/local/bin/make_snapshot.sh  -dev /dev/hdd15 -mount /root/backup /home/ -d home
  /usr/local/bin/make_snapshot.sh  -dev /dev/hdd15 -mount /root/backup /home/ -d home -N daily
  /usr/local/bin/make_snapshot.sh  -dev /dev/hdd15 -mount /root/backup /home/ -d home -N daily -m 10;
  /usr/local/bin/make_snapshot.sh  -dev /dev/hdd15 -mount /root/backup /home/ -d home -N daily -m 10 \\
 -f /root/make_snapshot_exclude

Example Crontab-lines:

0 8-18/2 * * *  /usr/local/bin/make_snapshot.sh  /dev/hdd15 /root/backup /home/ -d home -N hourly -m 10;
0 12 * * *  /usr/local/bin/make_snapshot.sh  /dev/hdd15 /root/backup /home/ -d home -N daily -m 10;
0 14 * * *  /usr/local/bin/make_snapshot.sh  0 /dev/hdd15 /root/backup /www/ -d /web/www -N daily -m 5;
0 0 * * *  /usr/local/bin/make_snapshot.sh   --srcdir /home --dest /mnt/backup/home --name Daily --number 5 --nomount -y -q
Posted in Administration • • Top Of Page
778 views

2 Responses to “Easy Automated Snapshot-Style Backups with Linux and Rsync”

Comment from Phil Hollenback
Time October 28, 2011 at 4:13 pm

Did you think about using rsnapshot (http://rsnapshot.org/)? I’ve used it in these sorts of situations and it works very well.

Comment from jbayer
Time October 28, 2011 at 4:40 pm

No, wasn’t aware of it. After reading it, the only thing I can say is that all of these programs were inspired by Mike Rubel.

It does seem to be more powerful than mine. But also more complicated to configure.

JBB

Write a comment

asd