From f5f15dc88747cce0194833520c4af2f4d5aaa35d Mon Sep 17 00:00:00 2001 From: Naglfar Date: Wed, 6 Oct 2021 23:55:47 +0200 Subject: [PATCH] Keep a second backup set --- roles/shell/files/usr/local/bin/backup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/shell/files/usr/local/bin/backup b/roles/shell/files/usr/local/bin/backup index 2ecb463..0962569 100644 --- a/roles/shell/files/usr/local/bin/backup +++ b/roles/shell/files/usr/local/bin/backup @@ -5,7 +5,7 @@ DATE=$(date +%Y%m%d) BACKUPS=/var/backups DUMPS=7 -LEVEL0=$(find $BACKUPS -name "*full.tgz") +LEVEL0=$(find $BACKUPS -name "*full.tgz" | sort | tail -n1) INCR=$(find $BACKUPS -name "*incremental.tgz" | wc -l) if [ -e $LEVEL0 ] && [ $INCR -le $DUMPS ] @@ -14,6 +14,8 @@ then else TYPE=full rm -f $BACKUPS/*.snapshot + # Remove dumps and the previous backup if there is another one. + find $BACKUPS -name "*tgz" ! -newer $LEVEL0 -exec rm {} \; fi tar -cz \ @@ -45,8 +47,6 @@ chmod 640 $BACKUPS/{*.tgz,$TYPE.snapshot} if [ $TYPE = full ] then cp -p $BACKUPS/full.snapshot $BACKUPS/incremental.snapshot - # Remove dumps and the previous backup if there is another one. - [ -e $LEVEL0 ] && rm $LEVEL0 $BACKUPS/*incremental.tgz fi # Database backup