better deletion logic
This commit is contained in:
@@ -42,7 +42,7 @@ while read line; do
|
|||||||
# Set Source directory, and make exception for %mysql
|
# Set Source directory, and make exception for %mysql
|
||||||
SOURCE="${RDIR}"
|
SOURCE="${RDIR}"
|
||||||
if [ "${RDIR}" == "mysql" ]; then SOURCE=/mysqlbackup/latest/${RUSER}; fi
|
if [ "${RDIR}" == "mysql" ]; then SOURCE=/mysqlbackup/latest/${RUSER}; fi
|
||||||
|
|
||||||
# Create backup destination if necessary
|
# Create backup destination if necessary
|
||||||
if [ ! -e "${DEST}" ]; then mkdir -p "${DEST}"; fi
|
if [ ! -e "${DEST}" ]; then mkdir -p "${DEST}"; fi
|
||||||
|
|
||||||
@@ -58,8 +58,9 @@ while read line; do
|
|||||||
rm ${DEST}.tar
|
rm ${DEST}.tar
|
||||||
|
|
||||||
# Delete all old directories except the $MAXBAK most recent
|
# Delete all old directories except the $MAXBAK most recent
|
||||||
MAXBAK=$[$MAXBAK + 1]
|
if [ $(ls -tp "${BACKUPDIR}"/"${RHOST}"/ | grep '/$' | wc -l) -gt $MAXBAK ]; then
|
||||||
ls -tpd "${BACKUPDIR}"/"${RHOST}"/* | grep '/$' | tail -n +$MAXBAK | xargs -d '\n' rm -rv --
|
ls -tpd "${BACKUPDIR}"/"${RHOST}"/* | grep '/$' | tail -n +$[$MAXBAK + 1] | xargs -d '\n' rm -rv --
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
done < "$HOSTS"
|
done < "$HOSTS"
|
||||||
|
|||||||
Reference in New Issue
Block a user