diff --git a/roles/shell/files/usr/local/bin/backup b/roles/shell/files/usr/local/bin/backup index 2ecb4632..09625694 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