2023-06-19 13:13:26 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Define backup hash argument as BACKUP_HASH
|
|
|
|
BACKUP_HASH="$1"
|
|
|
|
|
|
|
|
# Define main directory containing subdirectories to potentially be deleted
|
2023-12-01 14:31:36 +01:00
|
|
|
MAIN_DIRECTORY="/Backups/$BACKUP_HASH/backup-docker-to-local"
|
2023-12-01 14:48:23 +01:00
|
|
|
if [ -d "$MAIN_DIRECTORY" ]; then
|
|
|
|
echo "Cleaning up directory: $MAIN_DIRECTORY"
|
|
|
|
else
|
|
|
|
echo "Error: $MAIN_DIRECTORY does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-06-19 13:13:26 +02:00
|
|
|
|
|
|
|
# Loop through all subdirectories in the main directory
|
|
|
|
for SUBDIR in "$MAIN_DIRECTORY"/*; do
|
|
|
|
|
|
|
|
# Only proceed if it is a directory
|
|
|
|
if [ -d "$SUBDIR" ]; then
|
2024-01-29 19:49:51 +01:00
|
|
|
echo "Validating directory: $SUBDIR"
|
|
|
|
|
|
|
|
# Call the Python script for validation
|
|
|
|
python ../directory-validator/directory-validator.py "$SUBDIR" --validate
|
|
|
|
VALIDATION_STATUS=$?
|
|
|
|
|
|
|
|
if [ $VALIDATION_STATUS -eq 0 ]; then
|
|
|
|
echo "Validation: ok"
|
|
|
|
else
|
|
|
|
echo "Validation: error"
|
|
|
|
# Display the subdirectory contents
|
|
|
|
echo "Contents of subdirectory: $SUBDIR"
|
|
|
|
ls "$SUBDIR"
|
2023-06-19 15:38:59 +02:00
|
|
|
|
2024-01-29 19:49:51 +01:00
|
|
|
# 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
|
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]
|
|
|
|
then
|
|
|
|
# Notify the user of the deletion, then delete the subdirectory
|
|
|
|
echo "Deleting subdirectory: $SUBDIR"
|
|
|
|
rm -vrf "$SUBDIR"
|
2023-06-19 13:13:26 +02:00
|
|
|
fi
|
2024-01-29 19:49:51 +01:00
|
|
|
fi
|
2023-06-19 13:13:26 +02:00
|
|
|
fi
|
2024-01-29 19:49:51 +01:00
|
|
|
done
|