Posted on 05 Jun 2018 Data Hoarding 101 I have digital backups of data, especially of my photos, going back almost a decade (I鈥檓 not that old) but it鈥檚 only recently that I got into creating time-snapshots of my backups, after I mistakenly deleted a bunch of (non-crucial) personal files with a stray rsync --delete on a directory I had not backed-up. My home server used be compatible with macOS鈥檚 Time Machine and when I kept most things on my Mac that was useful, but I changed my data hoarding habits and that solution started to not be the optimal one. Time Based Snapshots Using rsync rsync has got to be one of my favourite and most used utilities. I use it constantly to transfer files between machine on my local network (and remote ones) but I鈥檝e discovered it鈥檚 very useful as a backup tool. The following is a short script that uses rsync to create snapshots of the my data directory to another directory (they are mount points on two different drives): #!/bin/sh TIMESTAMP=`date "+%Y-%m-%dT%H-%M-%S"` USER=user SOURCEDIR=/var/data/backups TARGETDIR=/var/redundancy # Create new backup using rsync and output to log rsync -avPh --delete --link-dest=$TARGETDIR/current $SOURCEDIR/$USER/ $TARGETDIR/$USER-$TIMESTAMP > /var/log/rsync/$TIMESTAMP.log 2>&1 # check exit status to see if backup failed if [ "$?" = 0 ]; then # Remove link to current backup rm -f $TARGETDIR/current # Create link to the newest backup ln -s $TARGETDIR/$USER-$TIMESTAMP $TARGETDIR/current else # Rename directory if failed mv $TARGETDIR/$USER-$TIMESTAMP $TARGETDIR/failed-$USER-$TIMESTAMP fi Essentially this script creates incremental copies of backups for a given user on the system by comparing any changes to that user鈥檚 data directory ($SOURCEDIR) with the current backup ($TARGETDIR) and making a new snapshot of any changes with the date. Now all that remains is to save this script somewhere and create a cron job to run it on an automatic interval: # daily at 5am 0 5 * * * bash /usr/local/bin/rsync-time-m...
First seen: 2026-02-02 01:31
Last seen: 2026-02-02 02:32