From 2f95fc967596e81aba7b84021f16f215a6db27e9 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Fri, 7 Jun 2024 22:43:14 +1000 Subject: [PATCH] initial fixup --- Makefile | 9 ++++-- tester.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ timeliner-cron | 13 +++++++-- 3 files changed, 92 insertions(+), 4 deletions(-) create mode 100755 tester.sh mode change 100644 => 100755 timeliner-cron diff --git a/Makefile b/Makefile index 0d06bc8..9550ee6 100644 --- 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 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 diff --git a/timeliner-cron b/timeliner-cron old mode 100644 new mode 100755 index 27d7161..b481871 --- a/timeliner-cron +++ b/timeliner-cron @@ -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" @@ -13,5 +13,14 @@ { 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 -- 2.39.5