Skip to content

Instantly share code, notes, and snippets.

@popmonkey
Created April 1, 2018 17:04
Show Gist options
  • Save popmonkey/571f76ca2cb08c12380b28123eb47dcc to your computer and use it in GitHub Desktop.
Save popmonkey/571f76ca2cb08c12380b28123eb47dcc to your computer and use it in GitHub Desktop.
time machine like backups using rsync
#!/bin/bash
#
# will create new directories each time it is executed with hard links to unchanged files
# exclude file can be used to skip certain files/directories as specified by rsync
# see the FILTER section of https://linux.die.net/man/1/rsync
SRC=$1
DST=$2
if [ ! \( -d "$DST" -a -d "$SRC" \) ]; then
echo "must specify valid destination and source"
exit 1
fi
EXCLUDE=${0%/*}/exclude_empty
if [ ! -z $3 ]; then
EXCLUDE="$3"
fi
date=$(date "+%Y-%m-%dT%H:%M:%S")
rsync --itemize-changes --modify-window=3601 -aP --link-dest=$DST/current --exclude-from=$EXCLUDE $SRC/* $DST/back-$date
rm -f $DST/current
ln -s $DST/back-$date $DST/current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment