mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup-cleanup.git
synced 2025-09-10 20:27: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
|
# 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.
|
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
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
|
18
cleanup.sh
Normal file → Executable file
18
cleanup.sh
Normal file → Executable file
@@ -12,20 +12,21 @@ 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
|
||||||
|
VALIDATION_STATUS=$?
|
||||||
|
|
||||||
|
if [ $VALIDATION_STATUS -eq 0 ]; then
|
||||||
|
echo "Validation: ok"
|
||||||
|
else
|
||||||
echo "Validation: error"
|
echo "Validation: error"
|
||||||
echo "Missing directory: $FULL_TRIGGER_DIR_PATH"
|
|
||||||
# Display the subdirectory contents
|
# Display the subdirectory contents
|
||||||
echo "Contents of subdirectory: $SUBDIR"
|
echo "Contents of subdirectory: $SUBDIR"
|
||||||
ls "$SUBDIR"
|
ls "$SUBDIR"
|
||||||
@@ -39,9 +40,6 @@ for SUBDIR in "$MAIN_DIRECTORY"/*; do
|
|||||||
echo "Deleting subdirectory: $SUBDIR"
|
echo "Deleting subdirectory: $SUBDIR"
|
||||||
rm -vrf "$SUBDIR"
|
rm -vrf "$SUBDIR"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "Validation: ok"
|
|
||||||
echo "$SUBDIR contains $FULL_TRIGGER_DIR_PATH."
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
Reference in New Issue
Block a user