mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup-cleanup.git
synced 2025-09-10 12:17:13 +02:00
Compare commits
9 Commits
7b00a6584b
...
main
Author | SHA1 | Date | |
---|---|---|---|
15e70b7a58 | |||
35cdf1218d | |||
8cac183c17 | |||
78ea7ba2ff | |||
f0c235ac67 | |||
62d69bac03 | |||
ee685ecb0a | |||
6794061edd | |||
76c28fdc39 |
7
.github/FUNDING.yml
vendored
Normal file
7
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
github: kevinveenbirkenbach
|
||||
|
||||
patreon: kevinveenbirkenbach
|
||||
|
||||
buy_me_a_coffee: kevinveenbirkenbach
|
||||
|
||||
custom: https://s.veen.world/paypaldonate
|
@@ -1,4 +1,6 @@
|
||||
# Cleanup Failed Docker Backups
|
||||
[](https://github.com/sponsors/kevinveenbirkenbach) [](https://www.patreon.com/c/kevinveenbirkenbach) [](https://buymeacoffee.com/kevinveenbirkenbach) [](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.
|
||||
|
33
cleanup-all.sh
Executable file
33
cleanup-all.sh
Executable 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
|
46
cleanup.sh
Normal file → Executable file
46
cleanup.sh
Normal file → Executable 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
|
Reference in New Issue
Block a user