From c2527c5408573abbd3cf98ef09dee48d95b601a6 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 19 Jun 2023 15:38:59 +0200 Subject: [PATCH] Update cleanup.sh --- cleanup.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cleanup.sh b/cleanup.sh index bf05099..d21f0ab 100644 --- a/cleanup.sh +++ b/cleanup.sh @@ -4,7 +4,8 @@ BACKUP_HASH="$1" # Define main directory containing subdirectories to potentially be deleted -MAIN_DIRECTORY="Backups/$BACKUP_HASH/docker-volume-backup/" +MAIN_DIRECTORY="/Backups/$BACKUP_HASH/docker-volume-backup" +echo "Checking backup directory: $MAIN_DIRECTORY" # Define trigger directory argument as TRIGGER_DIR TRIGGER_DIR="$2" @@ -14,16 +15,12 @@ for SUBDIR in "$MAIN_DIRECTORY"/*; do # Only proceed if it is a directory if [ -d "$SUBDIR" ]; then - - # Only proceed if the subdirectory name matches a date-time-stamp format (YYYY-MM-DDTHH:MM:SS) - if [[ $(basename "$SUBDIR") =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$ ]]; then - # Only proceed if the specified trigger directory does not exist within the subdirectory if [ ! -d "$SUBDIR/$TRIGGER_DIR" ]; then # Display the subdirectory contents echo "Contents of subdirectory: $SUBDIR" ls "$SUBDIR" - + # Ask for user confirmation before deletion read -p "Are you sure you want to delete this subdirectory? (y/n) " -n 1 -r echo # move to a new line @@ -31,9 +28,10 @@ for SUBDIR in "$MAIN_DIRECTORY"/*; do then # Notify the user of the deletion, then delete the subdirectory echo "Deleting subdirectory: $SUBDIR" - rm -rf "$SUBDIR" + rm -vrf "$SUBDIR" fi + else + echo "$SUBDIR contains $TRIGGER_DIR." fi - fi fi done