From 1ccc5480e18e0485c4e2203687de56cc101135b6 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 16 Feb 2021 11:40:45 -0500 Subject: [PATCH 1/2] remove oldest backup --- salt/common/tools/sbin/so-config-backup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/common/tools/sbin/so-config-backup b/salt/common/tools/sbin/so-config-backup index f68417c6a..0216c0f52 100755 --- a/salt/common/tools/sbin/so-config-backup +++ b/salt/common/tools/sbin/so-config-backup @@ -40,7 +40,7 @@ fi # Find oldest backup file and remove it NUMBACKUPS=$(find /nsm/backup/ -type f -name "so-config-backup*" | wc -l) -OLDESTBACKUP=$(find /nsm/backup/ -type f -name "so-config-backup*" | ls -1t | tail -1) +OLDESTBACKUP=$(find /nsm/backup/ -type f -name "so-config-backup*" -type f -printf '%T+ %p\n' | sort | head -n 1 | awk -F" " '{print $2}') if [ "$NUMBACKUPS" -gt "$MAXBACKUPS" ]; then - rm -f /nsm/backup/$OLDESTBACKUP + rm -f $OLDESTBACKUP fi From 7099ed4bf5fd7085e87e240cdbebdb3fe3e4b93f Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 16 Feb 2021 11:55:49 -0500 Subject: [PATCH 2/2] delete many backup files --- salt/common/tools/sbin/so-config-backup | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/salt/common/tools/sbin/so-config-backup b/salt/common/tools/sbin/so-config-backup index 0216c0f52..c8e504b4a 100755 --- a/salt/common/tools/sbin/so-config-backup +++ b/salt/common/tools/sbin/so-config-backup @@ -38,9 +38,10 @@ if [ ! -f $BACKUPFILE ]; then fi -# Find oldest backup file and remove it +# Find oldest backup files and remove them NUMBACKUPS=$(find /nsm/backup/ -type f -name "so-config-backup*" | wc -l) -OLDESTBACKUP=$(find /nsm/backup/ -type f -name "so-config-backup*" -type f -printf '%T+ %p\n' | sort | head -n 1 | awk -F" " '{print $2}') -if [ "$NUMBACKUPS" -gt "$MAXBACKUPS" ]; then +while [ "$NUMBACKUPS" -gt "$MAXBACKUPS" ]; do + OLDESTBACKUP=$(find /nsm/backup/ -type f -name "so-config-backup*" -type f -printf '%T+ %p\n' | sort | head -n 1 | awk -F" " '{print $2}') rm -f $OLDESTBACKUP -fi + NUMBACKUPS=$(find /nsm/backup/ -type f -name "so-config-backup*" | wc -l) +done \ No newline at end of file