Compare commits

...

9 Commits

4 changed files with 66 additions and 26 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 # 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. 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: 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.

33
cleanup-all.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
# 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.sh"
# Path to the main directory
MAIN_DIRECTORY="/Backups"
# Check if the cleanup script exists
if [ ! -f "$CLEANUP_SCRIPT" ]; then
echo "Error: The script $CLEANUP_SCRIPT does not exist."
exit 1
fi
# Iterate through each subdirectory in the main directory
for BACKUP_FOLDER_PATH in "$MAIN_DIRECTORY"/*; do
# Extract the base name (folder name) from the path
BACKUP_FOLDER=$(basename "$BACKUP_FOLDER_PATH")
# Check if the 'backup-docker-to-local' directory exists
if [ -d "$BACKUP_FOLDER_PATH/backup-docker-to-local" ]; then
echo "Running cleanup script for folder: $BACKUP_FOLDER"
# Call the cleanup script
"$CLEANUP_SCRIPT" "$BACKUP_FOLDER"
else
echo "Directory $BACKUP_FOLDER_PATH/backup-docker-to-local not found."
fi
done

48
cleanup.sh Normal file → Executable file
View File

@@ -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 scripts_directory="$(dirname "$(dirname "$(realpath "$0")")")"
FULL_TRIGGER_DIR_PATH="$SUBDIR/$TRIGGER_DIR" # Call the Python script for validation
if [ ! -d "$FULL_TRIGGER_DIR_PATH" ]; then python $scripts_directory/directory-validator/directory-validator.py "$SUBDIR" --validate
echo "Validation: error" VALIDATION_STATUS=$?
echo "Missing directory: $FULL_TRIGGER_DIR_PATH"
# Display the subdirectory contents
echo "Contents of subdirectory: $SUBDIR"
ls "$SUBDIR"
# Ask for user confirmation before deletion if [ $VALIDATION_STATUS -eq 0 ]; then
read -p "Are you sure you want to delete this subdirectory? (y/n) " -n 1 -r echo "Validation: ok"
echo # move to a new line else
if [[ $REPLY =~ ^[Yy]$ ]] echo "Validation: error"
then # Display the subdirectory contents
# Notify the user of the deletion, then delete the subdirectory echo "Contents of subdirectory: $SUBDIR"
echo "Deleting subdirectory: $SUBDIR" ls "$SUBDIR"
rm -vrf "$SUBDIR"
fi # Ask for user confirmation before deletion
else read -p "Are you sure you want to delete this subdirectory? (y/n) " -n 1 -r
echo "Validation: ok" echo # move to a new line
echo "$SUBDIR contains $FULL_TRIGGER_DIR_PATH." 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