Updated to version 2.0.1

- Modified to save all files to a folder tree for backup rather than creating a single monolithic archive.  This will allow restic to properly manage snapshots.
- Changed exception lookup to case-insensitive
This commit is contained in:
ackitsme committed 2026-10-18 12:26:59 -07:00
1 parent e79d26435b
commit 0e07c9ec97
1 file changed
+17 -10
+17 -10
View File
@@ -3,8 +3,8 @@
### Docker Stack Backup Script ### Docker Stack Backup Script
### Created by Charlie Silverman - ackitsme3@gmail.com ### Created by Charlie Silverman - ackitsme3@gmail.com
############################################################################### ###############################################################################
### Version: 1.1.3 ### Version: 2.0.1
### Updated: 2026-08-05 ### Updated: 2026-10-18
### Purpose: Backs up all docker stacks in a given directory to Restic bucket ### Purpose: Backs up all docker stacks in a given directory to Restic bucket
############################################################################### ###############################################################################
### Requirements: ### Requirements:
@@ -25,6 +25,10 @@
# 1.1.1 - Added snapshot size to log # 1.1.1 - Added snapshot size to log
# 1.1.2 - Added aggregate backup size to end of log # 1.1.2 - Added aggregate backup size to end of log
# 1.1.3 - Added GiB to total backup size information # 1.1.3 - Added GiB to total backup size information
# 2.0.0 - Modified to save all files to a folder tree for backup rather than
# creating a single monolithic archive. This will allow restic to
# properly manage snapshots
# 2.0.1 - Changed exception lookup to case-insensitive
set -Eeuo pipefail set -Eeuo pipefail
@@ -68,12 +72,16 @@ log() {
should_skip() { should_skip() {
local project="$1" local project="$1"
shopt -s nocasematch
for pattern in "${SKIP_PROJECTS[@]}"; do for pattern in "${SKIP_PROJECTS[@]}"; do
if [[ "$project" == $pattern ]]; then if [[ "$project" == $pattern ]]; then
return 0 return 0
fi fi
done done
shopt -u nocasematch
return 1 return 1
} }
@@ -148,7 +156,7 @@ for compose_file in "${COMPOSE_FILES[@]}"; do
log "Compose file: ${compose_file}" log "Compose file: ${compose_file}"
log "==================================================" log "=================================================="
STAGING_DIR="/tmp/docker-backup-${project_name}-${TIMESTAMP}" STAGING_DIR="/home/Backups/docker-backup-${project_name}"
mkdir -p \ mkdir -p \
"${STAGING_DIR}/images" \ "${STAGING_DIR}/images" \
@@ -198,11 +206,11 @@ for compose_file in "${COMPOSE_FILES[@]}"; do
################################################### ###################################################
log "Backing up compose files..." log "Backing up compose files..."
mkdir -p "${STAGING_DIR}/compose"
tar -czf \ cp -a \
"${STAGING_DIR}/${project_name}-compose.tar.gz" \ "${compose_dir}" \
-C "$(dirname "$compose_dir")" \ "${STAGING_DIR}/compose/"
"$(basename "$compose_dir")"
################################################### ###################################################
# Backup Images # Backup Images
@@ -221,8 +229,7 @@ for compose_file in "${COMPOSE_FILES[@]}"; do
log "Saving image: $image" log "Saving image: $image"
docker save "$image" \ docker save "$image" \
| gzip \ > "${STAGING_DIR}/images/${safe_name}.tar"
> "${STAGING_DIR}/images/${safe_name}.tar.gz"
fi fi
done < "${STAGING_DIR}/metadata/images.list" done < "${STAGING_DIR}/metadata/images.list"
@@ -243,7 +250,7 @@ for compose_file in "${COMPOSE_FILES[@]}"; do
-v "${volume}:/source:ro" \ -v "${volume}:/source:ro" \
-v "${STAGING_DIR}/volumes:/backup" \ -v "${STAGING_DIR}/volumes:/backup" \
alpine \ alpine \
tar -czf "/backup/${volume}.tar.gz" -C /source . sh -c "cd /source && tar cf - . | tar xf - -C /backup"
done < "${STAGING_DIR}/metadata/volumes.list" done < "${STAGING_DIR}/metadata/volumes.list"