Dear list,

For years I'd used a couple of rsync scripts for backup,
usually just full snapshots.

I knew there is an option using hardlinks that behaves like
the Mac Time Machine app, giving cheap incremental backups.

https://blog.interlinked.org/tutorials/rsync_time_machine.html

And now I fool around with it myself. 

Since I have map UUIDs to mount points in /etc/fstab,
I can put the full paths in the backup script 
and simply run it without parameters to get a 
date-and-time-stamped directory containing a full backup.

Probably you all have something much better, but for the 
sake of discussion, and will post my humble offering. 

The clever part of the code is using a symlink
.../backups/current/ to provide rsync with the --link-dest
argument, the tree of files available for hardlinking during
next backup pass. 

Also, the one-file-system argument to rsync lets me backup
the root directory without pulling in other mounts. 

The current script doesn't support copying over a network,
but can be easily achieved by consulting online resources
(left as an exercise to the reader.)

Obviously, you will need to configure it. Note that the directories
excluded from backup are created in the last step.

probably someone has done it better...


# rsync-time

#!/bin/sh
DATE=`date "+%Y.%m.%d-%H:%M:%S"`
BACKUP_ROOT=/mnt/matte/backups
SOURCE_DIR=/
BACKUP_DIR="$BACKUP_ROOT/back-$DATE"
HARDLINK_ROOT=$BACKUP_ROOT/current
HOME_=home/jill
LOG=/var/log/backup.log
EXCLUDE_HOME="\
        --exclude $HOME_/.mozilla/firefox/n5c5mmhh.default/cache2  \
        --exclude $HOME_/.cache/mozilla/firefox/n5c5mmhh.default/cache2 \
        --exclude $HOME_/.opera/cache4 \
        --exclude $HOME_/Desktop \
        --exclude $HOME_/Downloads \
        --exclude $HOME_/.cpan \
        --exclude $HOME_/.cpanm \
        --exclude $HOME_/.cpanplus \
        --exclude $HOME_/perl5 "
EXCLUDE_SYS="\
        --exclude /dev \
        --exclude /proc \
        --exclude /sys  \
        --exclude /tmp \
        --exclude /var/cache/apt/archives \
        --exclude /var/run  "
CMD="rsync -avxP $EXCLUDE_HOME $EXCLUDE_SYS --link-dest=$HARDLINK_ROOT 
$SOURCE_DIR $BACKUP_DIR"
echo $CMD
$CMD
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "$DATE - Starting hardlink backup to $BACKUP_ROOT" >> $LOG
echo $CMD >> $LOG
echo "Completed" >> $LOG
rm -f $HARDLINK_ROOT
ln -s $BACKUP_DIR $HARDLINK_ROOT
cd $BACKUP_DIR
for dir in dev proc sys  tmp var/run var/cache/apt/archives ; do mkdir $dir; 
done
cd -

# end

-- 
Joel Roth
  

_______________________________________________
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng

Reply via email to