Fix deletion of wrong backup directory on the backup server with alpine system

This commit is contained in:
Wolfgang Huß 2023-11-28 15:45:41 +01:00
parent 72978889ef
commit ae41243324
2 changed files with 9 additions and 7 deletions

View File

@ -22,7 +22,8 @@ KUBECONFIG=${KUBECONFIG:-${SCRIPT_DIR}/../configurations/${CONFIGURATION}/kubeco
BACKUP_DATE=$(date "+%F_%H-%M-%S")
BACKUP_FOLDER=${BACKUP_FOLDER:-${SCRIPT_DIR}/../configurations/${CONFIGURATION}/backup/${BACKUP_DATE}}
# create backup fodler
printf "Backup folder name: %s\n" $BACKUP_DATE
# create backup folder
mkdir -p ${BACKUP_FOLDER}
# cluster maintenance mode on && Neo4j maintenance mode on

View File

@ -81,15 +81,16 @@ do
cd $path
printf "In\n '$path'\n remove:\n"
# TODO: replace 'ls' by 'find . -type d -maxdepth 1'? description: https://unix.stackexchange.com/questions/28939/how-to-delete-the-oldest-directory-in-a-given-directory
while [ `ls -1 | wc -l` -gt $keep ]; do
oldest=`ls -c1 | head -1`
echo " $oldest"
while [ `ls -1 | wc -l` -gt $keep ]; do
# TODO: because 'ls' is not always relyable maybe replace 'ls' by 'find . -type d -maxdepth 1'? description: https://unix.stackexchange.com/questions/28939/how-to-delete-the-oldest-directory-in-a-given-directory
# I tested this, but 'find' this is crutial, because of shell compatibilities
oldest=`ls -c1 | sort -n | head -1`
printf " %s\n" $oldest
rm -rf $oldest
done
printf "Keep the last %d backups:\n " $BACKUP_SAVED_BACKUPS_NUMBER
ls
printf "Keep the last %d backups:\n" $BACKUP_SAVED_BACKUPS_NUMBER
ls -c1 | sort -n | awk '{print " " $0}'
cd $SCRIPT_DIR
else