Added subtree exclusion
authorRalph Ronnquist <rrq@rrq.au>
Wed, 22 Jan 2025 01:20:18 +0000 (12:20 +1100)
committerRalph Ronnquist <rrq@rrq.au>
Wed, 22 Jan 2025 01:20:18 +0000 (12:20 +1100)
timeliner

index 5ca3d4687745a4dd76860c9a924191f6574f2bcd..4bf2e52bc1eb47ca711e43c6d4ed3537b23f99cf 100755 (executable)
--- 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"