From 8a2dc47f89dd06b0f45e26accd8f8d0d2715a681 Mon Sep 17 00:00:00 2001 From: St33v Date: Thu, 27 Feb 2020 22:35:49 +1100 Subject: summarise diffs to MAXLINE --- borgAuto.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'borgAuto.sh') diff --git a/borgAuto.sh b/borgAuto.sh index 74a3485..07c83c3 100755 --- a/borgAuto.sh +++ b/borgAuto.sh @@ -4,11 +4,34 @@ # the envvar $REPONAME is something you should just hardcode export BORG_REPO="/mnt/bak/borg" # (now set in ~/.bashrc) +MAXFILES=20 #Max number of file changes to log + +# Route the normal process logging to journalctl +2>&1 + # DIFF function # List changes between this archive and the previous one function Differ { newArchive=$(borg list :: -P $1 --last 2 --format {name}{NL}) - borg diff ::$newArchive + diffTmpFile=`mktemp /tmp/borgAutoXXXXX` # in /tmp dir + borg diff ::$newArchive > $diffTmpFile + addFiles=$(grep '^added' ${diffTmpFile} | wc -l) + remFiles=$(grep '^removed' ${diffTmpFile} | wc -l) + totFiles=$(wc -l ${diffTmpFile} | awk '{print $1}') + changeFiles=$(awk -v tot=$totFiles -v a=$addFiles -v r=$remFiles 'BEGIN {print tot - a - r}') + if [ ${totFiles} -eq 0 ]; then + echo "No changes, additions or deletions since last backup" + elif [ ${totFiles} -gt ${MAXFILES} ]; then + #echo $(head ${diffTmpFile}) + head ${diffTmpFile} + + midFiles=$(awk -v tot=$totFiles -v max=$MAXFILES 'BEGIN {print tot - max}') + echo " ... ${midFiles} more changes (Changed $changeFiles, Added ${addFiles}, Removed ${remFiles})" + tail ${diffTmpFile} + else + cat ${diffTmpFile} + fi + rm ${diffTmpFile} } # Backup all of /home except a few excluded directories and files @@ -36,9 +59,6 @@ echo $'\nCreating Image archive' borg create -v --stats --compression none \ ::'olho-{now:%Y%m%dT%H%M}' /mnt/olho -# Route the normal process logging to journalctl -2>&1 - Differ olho backup_exit=$? -- cgit v1.3