#!/bin/bash [ -z "$2" ] && echo "usage: $0 [ ...]" && exit 1 OPTIONS=" --archive --update --delete --numeric-ids --verbose --one-file-system --progress --rsh=ssh " # Destination will have a data prefix, and will use the most recent # (time stamp) backup directory as a hard link base. HERE=$(readlink -f .) DST=$(readlink -f "$2") SRC="$1" DST=$(readlink -f $2) shift shift TAG=$(date +%Y%m%d-%H%M%S) # Get last tag and make a new one. cd $DST rm -f last LAST_TAG=$(ls -t |head -n1) mkdir $TAG ln -s $TAG last fail () { echo rsync returned error echo removing $DST/$TAG rm -rf $DST/$TAG exit 1 } debug () { echo "$@" "$@" || fail } # Transfer dirs cd $HERE for dir in "$@"; do [ -z "$LAST_TAG" ] || LINK_DEST_OPTIONS="--link-dest=$DST/$LAST_TAG/$dir" debug mkdir -p "$DST/$TAG/$dir" debug rsync $OPTIONS $LINK_DEST_OPTIONS "$SRC/$dir/" "$DST/$TAG/$dir/" # FIXME: If this fails or gets interrupted in in any way, the # directory needs to be removed. Otherwise it will trigger a full # download next time. done