Compare commits

..

7 Commits

4 changed files with 35 additions and 31 deletions

7
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,7 @@
github: kevinveenbirkenbach
patreon: kevinveenbirkenbach
buy_me_a_coffee: kevinveenbirkenbach
custom: https://s.veen.world/paypaldonate

View File

@@ -1,4 +1,6 @@
# Cleanup Failed Docker Backups
[![GitHub Sponsors](https://img.shields.io/badge/Sponsor-GitHub%20Sponsors-blue?logo=github)](https://github.com/sponsors/kevinveenbirkenbach) [![Patreon](https://img.shields.io/badge/Support-Patreon-orange?logo=patreon)](https://www.patreon.com/c/kevinveenbirkenbach) [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20me%20a%20Coffee-Funding-yellow?logo=buymeacoffee)](https://buymeacoffee.com/kevinveenbirkenbach) [![PayPal](https://img.shields.io/badge/Donate-PayPal-blue?logo=paypal)](https://s.veen.world/paypaldonate)
This repository hosts a Bash script designed for cleaning up directories within the Docker Volume Backup system. It is intended to be used in conjunction with the [Docker Volume Backup](https://github.com/kevinveenbirkenbach/docker-volume-backup) project.
@@ -15,7 +17,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:
```bash
bash cleanup.sh BACKUP_HASH TRIGGER_DIRECTORY
bash cleanup.sh BACKUP_HASH
```
Replace ```BACKUP_HASH``` and ```TRIGGER_DIRECTORY``` with your actual values.

7
cleanup-all.sh Normal file → Executable file
View File

@@ -1,13 +1,10 @@
#!/bin/bash
# Define trigger directory argument as TRIGGER_DIR
TRIGGER_DIR="$2"
# Get the absolute path of the directory where the current script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Define the path to the original cleanup script using the script directory path
CLEANUP_SCRIPT="$SCRIPT_DIR/cleanup_script.sh"
CLEANUP_SCRIPT="$SCRIPT_DIR/cleanup.sh"
# Path to the main directory
MAIN_DIRECTORY="/Backups"
@@ -29,7 +26,7 @@ for BACKUP_FOLDER_PATH in "$MAIN_DIRECTORY"/*; do
echo "Running cleanup script for folder: $BACKUP_FOLDER"
# Call the cleanup script
"$CLEANUP_SCRIPT" "$BACKUP_FOLDER" "$TRIGGER_DIR"
"$CLEANUP_SCRIPT" "$BACKUP_FOLDER"
else
echo "Directory $BACKUP_FOLDER_PATH/backup-docker-to-local not found."
fi

48
cleanup.sh Normal file → Executable file
View File

@@ -12,36 +12,34 @@ else
exit 1
fi
# Define trigger directory argument as TRIGGER_DIR
TRIGGER_DIR="$2"
# 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
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"
echo "Validating directory: $SUBDIR"
scripts_directory="$(dirname "$(dirname "$(realpath "$0")")")"
# Call the Python script for validation
python $scripts_directory/directory-validator/directory-validator.py "$SUBDIR" --validate
VALIDATION_STATUS=$?
# 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
else
echo "Validation: ok"
echo "$SUBDIR contains $FULL_TRIGGER_DIR_PATH."
if [ $VALIDATION_STATUS -eq 0 ]; then
echo "Validation: ok"
else
echo "Validation: error"
# 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
if [[ $REPLY =~ ^[Yy]$ ]]
then
# Notify the user of the deletion, then delete the subdirectory
echo "Deleting subdirectory: $SUBDIR"
rm -vrf "$SUBDIR"
fi
fi
fi
done
done