mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup-cleanup.git
synced 2024-11-21 21:31:02 +01:00
Implemented validate function to substitute trigger directory
This commit is contained in:
parent
7b00a6584b
commit
ee685ecb0a
@ -15,7 +15,7 @@ For more detailed information about the script's workings, refer to the comments
|
|||||||
To use this script, clone this repository to your local system and run the script with the necessary arguments. The command should be structured as follows:
|
To use this script, clone this repository to your local system and run the script with the necessary arguments. The command should be structured as follows:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash cleanup.sh BACKUP_HASH TRIGGER_DIRECTORY
|
bash cleanup.sh BACKUP_HASH
|
||||||
```
|
```
|
||||||
|
|
||||||
Replace ```BACKUP_HASH``` and ```TRIGGER_DIRECTORY``` with your actual values.
|
Replace ```BACKUP_HASH``` and ```TRIGGER_DIRECTORY``` with your actual values.
|
||||||
|
48
cleanup.sh
48
cleanup.sh
@ -12,36 +12,34 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define trigger directory argument as TRIGGER_DIR
|
|
||||||
TRIGGER_DIR="$2"
|
|
||||||
|
|
||||||
# Loop through all subdirectories in the main directory
|
# Loop through all subdirectories in the main directory
|
||||||
for SUBDIR in "$MAIN_DIRECTORY"/*; do
|
for SUBDIR in "$MAIN_DIRECTORY"/*; do
|
||||||
|
|
||||||
# Only proceed if it is a directory
|
# Only proceed if it is a directory
|
||||||
if [ -d "$SUBDIR" ]; then
|
if [ -d "$SUBDIR" ]; then
|
||||||
echo "Validating directory: $SUBDIR"
|
echo "Validating directory: $SUBDIR"
|
||||||
# Only proceed if the specified trigger directory does not exist within the subdirectory
|
|
||||||
FULL_TRIGGER_DIR_PATH="$SUBDIR/$TRIGGER_DIR"
|
|
||||||
if [ ! -d "$FULL_TRIGGER_DIR_PATH" ]; then
|
|
||||||
echo "Validation: error"
|
|
||||||
echo "Missing directory: $FULL_TRIGGER_DIR_PATH"
|
|
||||||
# Display the subdirectory contents
|
|
||||||
echo "Contents of subdirectory: $SUBDIR"
|
|
||||||
ls "$SUBDIR"
|
|
||||||
|
|
||||||
# Ask for user confirmation before deletion
|
# Call the Python script for validation
|
||||||
read -p "Are you sure you want to delete this subdirectory? (y/n) " -n 1 -r
|
python ../directory-validator/directory-validator.py "$SUBDIR" --validate
|
||||||
echo # move to a new line
|
VALIDATION_STATUS=$?
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
|
||||||
then
|
if [ $VALIDATION_STATUS -eq 0 ]; then
|
||||||
# Notify the user of the deletion, then delete the subdirectory
|
echo "Validation: ok"
|
||||||
echo "Deleting subdirectory: $SUBDIR"
|
else
|
||||||
rm -vrf "$SUBDIR"
|
echo "Validation: error"
|
||||||
fi
|
# Display the subdirectory contents
|
||||||
else
|
echo "Contents of subdirectory: $SUBDIR"
|
||||||
echo "Validation: ok"
|
ls "$SUBDIR"
|
||||||
echo "$SUBDIR contains $FULL_TRIGGER_DIR_PATH."
|
|
||||||
|
# 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"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
Loading…
Reference in New Issue
Block a user