initial fixup v1.0
authorRalph Ronnquist <rrq@rrq.au>
Fri, 7 Jun 2024 12:43:14 +0000 (22:43 +1000)
committerRalph Ronnquist <rrq@rrq.au>
Fri, 7 Jun 2024 12:43:14 +0000 (22:43 +1000)
Makefile
tester.sh [new file with mode: 0755]
timeliner-cron [changed mode: 0644->0755]

index 0d06bc8af99296b3be306384315939d6905337b2..9550ee6843baef227b83080f0c7952cf4a8ff924 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,12 @@
 MANPAGES = $(basename $(wildcard *.8.adoc))
-$(warning MANPAGES = $(MANPAGES))
 
-all: $(MANPAGES)
+all: $(MANPAGES:=.gz)
 
 %.8: %.8.adoc
        asciidoctor -bmanpage $<
+
+%.8.gz: %.8
+       gzip $<
+
+clean:
+       rm -f $(MANPAGES) $(MANPAGES:=.gz)
diff --git a/tester.sh b/tester.sh
new file mode 100755 (executable)
index 0000000..8ed06fe
--- /dev/null
+++ b/tester.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+#
+
+TARGET=${1-localhost:/tmp/target1}
+HOST="${TARGET%%:*}"
+BASE="${TARGET#*:}"
+if [ "$HOST" = "$TARGET" ] ; then
+   cmd() { $* ; }
+else
+    cmd() { ssh $HOST "$*" ; }
+fi
+
+rm -rf test1 || exit 1
+cmd rm -rf $BASE || exit 1
+
+HERE="$(pwd)"
+mkdir -p test1/A test1/B
+for I in $(seq 1 5) ; do
+    echo something $I > test1/A/afile$I
+    echo more $I > test1/B/bfile$I
+done
+
+cmd mkdir -p $BASE/current
+
+R1="$(./timeliner-local.sh $TARGET test1/A test1/B)"
+
+echo hubba > test1/A/afile1
+echo hubba > test1/A/afile1a
+
+R2="$(./timeliner-local.sh $TARGET test1/A test1/B)"
+
+# target1 now contains one yyyy-mm-dd and 'current'
+DATE=$(date +%Y-%m-%d)
+if [ "$DATE" != "$(cmd ls $BASE | sed "/^current\$/d")" ] ; then
+    echo "** ERROR **"
+    cmd ls $BASE
+fi
+
+content() {
+    cmd find $BASE -type f | xargs ls -i | \
+       sed "s| target1/| |;s|$(pwd)/test1/| |" | \
+       sort -rk3,3 | column -t
+}
+
+cmd mv $BASE/$DATE $BASE/$(date -d "-1 day" +%Y-%m-%d)
+
+R3="$(./timeliner-local.sh $TARGET test1/A test1/B)"
+
+R4="$(content)"
+
+inodes() {
+    cmd find $BASE -name $1 | xargs stat -c %i | \
+       awk '{inodes[$1]+=1}END{for(k in inodes){printf " %s:%s",k,inodes[k]}}'
+}
+
+# Check occurances and inode counts of files
+check() {
+    local N="$(inodes $1)"
+    case "$1" in
+       bfile[1-5]|afile[2-5]*) [ "${N#*:}" = 3 ] && return 0 ;;
+       afile1a) [ "${N#*:}" = 2 ] && return 0 ;;
+       afile1)
+           [ "${N##*:1}" != "$1" ] && [ "${N#*:2}" != "$1" ] && return 0 ;;
+    esac
+    echo "** ERROR $1$N"
+}
+
+for I in $(seq 1 5) ; do
+    check afile$I
+    check bfile$I
+done
+check afile1a
+
+#rm -r test1 target1
old mode 100644 (file)
new mode 100755 (executable)
index 27d7161..b481871
@@ -5,7 +5,7 @@
 
 #LOGFILE=/var/log/timeliner.log
 #LOCAL=/backup
-#BASE=/backup
+#BASE=/backup/$(hostname)
 #REMOTE=remote.example.com # needs paswwordless ssh access to root
 #DIRS="/root /etc /home /opt /usr"
 
 
 {
     flock -n 1 || exit 0
-    timeliner $LOCAL $DIRS && timeliner-backup $REMOTE:$BASE $LOCAL
+    if [ -z "$LOCAL" ] ; then
+       # Remote-only backup scheme
+       timeliner $REMOTE:$BASE $DIRS
+    elif [ -z "$REMOTE" ] ; then
+       # Local-only backup scheme
+       timeliner $LOCAL $DIRS
+    else
+       # Local backup window with remote store
+       timeliner $LOCAL $DIRS && timeliner-backup $REMOTE:$BASE $LOCAL
+    fi
 } >> $LOGFILE  2>&1