From 24db53b4562e4a9d050e5244dc4de15f9a12dd42 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Wed, 22 Jan 2025 12:20:18 +1100 Subject: [PATCH] Added subtree exclusion --- timeliner | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/timeliner b/timeliner index 5ca3d46..4bf2e52 100755 --- a/timeliner +++ b/timeliner @@ -29,21 +29,34 @@ log() { date +"%Y-%m-%d %H:%M:%S - $*" } -log "$0 begin" +log "$0 begin $*" + +# Make args: $1 [ --exclude=$2 ] when split on : +rsyncpaths() { + local P P0 + P0="${1%%:*}" + echo -n "$P0" + rest=false + for P in $(echo "$1" | tr : ' ') ; do + $rest && echo -n " --exclude=$P" + rest=true + done +} BACKUP=$1 shift -ERR=false +ERR= for D in "$@" ; do - rsync -aR --delete-after /.$(realpath "$D") $BACKUP/current/. + X="/.$(rsyncpaths "$D")" + #echo "rsync -aRx --delete-after $X $BACKUP/current/." >> /tmp/timeliner.debug + rsync -aRx --delete-after $X $BACKUP/current/. E=$? - [ $E != 0 ] && [ $E != 24 ] && ERR="$ERR $D:$E" + [ $E != 0 ] && ERR="$ERR $D:$E" done -[ -n "$ERR" ] && log "$0 rsync:$ERR - end" && exit 1 +[ -n "$ERR" ] && log "$0 rsync:$ERR" HOST="${BACKUP%%:*}" BASE="${BACKUP#*:}" - if [ "$HOST" = "$BACKUP" ] ; then cmd() { $* ; } else @@ -54,14 +67,14 @@ TS=$(date +%s) TODAY="$(date -d @$TS +%Y-%m-%d)" # If snapshot of $TODAY exists then exit -cmd test -d "$BASE/$TODAY" && log "$0 $TODAY exists - end" && exit 0 +cmd test -d "$BASE/$TODAY" && log "$0 $TODAY exists" && exit 0 # If there is a snap of yesterday and time < SNAPTIME then exit cmd test -d "$BASE/$(date -d "@$((TS - 86400))" "+%Y-%m-%d")" && \ test "$TS" -lt "$(date -d "$SNAPTIME" +%s)" && \ - log "$0 still too early ($SNAPTIME) - end" exit 0 + log "$0 still too early" && exit 0 -log "make snapshot $TODAY" +log ".. snapshot $TODAY" cmd mkdir -p "$BASE/$TODAY" cmd cp -axl "$BASE/current/." "$BASE/$TODAY/." log "$0 end" -- 2.39.5