Time Machine like backups

If you backup your data to a remote server or a local disk with a script (I strongly recommend rsync to do so, otherwise this script will most probably not work), you should also keep old versions of that data to be able to rollback to an earlier version. But if you have a LOT of data, your HD will run full. So better just keep the deltas.

In my case its half a terabyte of email data from a mail server. Many files change every day. Get deleted, added, moved.
To keep old versions (you could call them snapshots) of the backups, I use hardlinks, that will just create a new link to an existing file in the filesystem. It is not a symbolic link, meaning the actual file will only get deleted, when the last hardlink will be deleted from the filesystem. In my case, this will happen 10 days after the original file was deleted.


BASEDIR="/var/bkp/" # base directory
BDIR=mybackup # directory to backup
cp -al $BASEDIR/$BDIR/ $BASEDIR/$BDIR$(date +%Y%m%d)
if [ -d $BASEDIR/$BDIR$(date +%Y%m%d --date="-$DAYS day") ]; then
 echo "deleting old backup $BDIR$(date +%Y%m%d --date="-$DAYS day")..."
 rm -rf $BASEDIR/$BDIR$(date +%Y%m%d --date="-$DAYS day")
 echo -n "No old backups at "
 date +%Y%m%d --date="-$DAYS day"
Time Machine like backups

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s