diff --git a/salt/common/tools/sbin/so-config-backup b/salt/common/tools/sbin/so-config-backup index f68417c6a..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*" | ls -1t | tail -1) -if [ "$NUMBACKUPS" -gt "$MAXBACKUPS" ]; then - rm -f /nsm/backup/$OLDESTBACKUP -fi +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 + NUMBACKUPS=$(find /nsm/backup/ -type f -name "so-config-backup*" | wc -l) +done \ No newline at end of file