mirror of
https://github.com/acedanger/shell.git
synced 2026-03-24 20:11:49 -07:00
feat: Add configurable shared backup directory and enhance backup script with improved storage checks
This commit is contained in:
@@ -148,7 +148,13 @@ while [[ $# -gt 0 ]]; do
|
||||
done
|
||||
|
||||
# B2 CLI tool path
|
||||
B2_CLI="$(dirname "$0")/b2-linux"
|
||||
if [ -f "$(dirname "$0")/b2-linux" ]; then
|
||||
B2_CLI="$(dirname "$0")/b2-linux"
|
||||
elif command -v b2 &> /dev/null; then
|
||||
B2_CLI=$(command -v b2)
|
||||
else
|
||||
B2_CLI="$(dirname "$0")/b2-linux"
|
||||
fi
|
||||
|
||||
# Notification function
|
||||
send_notification() {
|
||||
@@ -225,11 +231,14 @@ LOG_FILE="${LOG_DIR}/immich-backup.log"
|
||||
log_message() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
# Create backup directory if it doesn't exist
|
||||
BACKUP_DIR="$(dirname "$0")/../immich_backups"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
# Function to log without timestamp (for progress/status)
|
||||
log_status() {
|
||||
echo "$1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
# Shared backup directory (can be overridden in .env)
|
||||
SHARED_BACKUP_DIR="${SHARED_BACKUP_DIR:-/mnt/share/media/backups/immich}"
|
||||
|
||||
# Generate timestamp for the backup filename
|
||||
|
||||
# Create backup directory if it doesn't exist
|
||||
BACKUP_DIR="$(dirname "$0")/../immich_backups"
|
||||
@@ -307,15 +316,16 @@ if [ "$DRY_RUN" = true ]; then
|
||||
# Check shared storage directory
|
||||
echo ""
|
||||
echo "Shared Storage Check:"
|
||||
if [ -d "/mnt/share/media/backups" ]; then
|
||||
echo " ✓ Shared storage accessible: /mnt/share/media/backups"
|
||||
if [ -w "/mnt/share/media/backups" ]; then
|
||||
echo " ✓ Shared storage writable - would copy backups before B2 upload"
|
||||
SHARED_PARENT=$(dirname "$SHARED_BACKUP_DIR")
|
||||
if [ -d "$SHARED_PARENT" ]; then
|
||||
echo " ✓ Shared storage accessible: $SHARED_PARENT"
|
||||
if [ -w "$SHARED_PARENT" ]; then
|
||||
echo " ✓ Shared storage writable - would copy backups to $SHARED_BACKUP_DIR"
|
||||
else
|
||||
echo " ⚠ Shared storage not writable - backups would remain in ${BACKUP_DIR}"
|
||||
fi
|
||||
else
|
||||
echo " ⚠ Shared storage not accessible: /mnt/share/media/backups"
|
||||
echo " ⚠ Shared storage not accessible: $SHARED_PARENT"
|
||||
echo " Backups would remain in ${BACKUP_DIR}"
|
||||
fi
|
||||
|
||||
@@ -380,7 +390,7 @@ fi
|
||||
|
||||
log_message "Taking database backup using pg_dumpall as recommended by Immich documentation..."
|
||||
# Use pg_dumpall with recommended flags: --clean and --if-exists
|
||||
if ! docker exec -t immich_postgres pg_dumpall \
|
||||
if ! docker exec immich_postgres pg_dumpall \
|
||||
--clean \
|
||||
--if-exists \
|
||||
--username="${DB_USERNAME}" \
|
||||
@@ -454,22 +464,22 @@ if [ "${IMMICH_SERVER_RUNNING:-true}" = true ]; then
|
||||
log_message "Note: No need to unpause immich_server container."
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== COPYING BACKUPS TO SHARED STORAGE ==="
|
||||
|
||||
# Update metrics for shared storage phase
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_update_status "running" "Copying backups to shared storage"
|
||||
fi
|
||||
|
||||
SHARED_BACKUP_DIR="/mnt/share/media/backups/immich"
|
||||
|
||||
# Initialize COPY_SUCCESS before use
|
||||
COPY_SUCCESS=false
|
||||
|
||||
# Check if the parent directory of the shared backup dir exists (basic mount check)
|
||||
SHARED_PARENT=$(dirname "$SHARED_BACKUP_DIR")
|
||||
if [ ! -d "$SHARED_PARENT" ]; then
|
||||
log_message "Warning: Shared storage parent directory not found: $SHARED_PARENT"
|
||||
log_message "Backup files remain only in: $BACKUP_DIR"
|
||||
COPY_SUCCESS=false
|
||||
# Create shared backup directory if it doesn't exist
|
||||
if ! mkdir -p "$SHARED_BACKUP_DIR"; then
|
||||
elif ! mkdir -p "$SHARED_BACKUP_DIR"; then
|
||||
log_message "Warning: Failed to create shared backup directory: $SHARED_BACKUP_DIR"
|
||||
log_message "Backup files remain only in: $BACKUP_DIR"
|
||||
COPY_SUCCESS=false
|
||||
@@ -533,12 +543,12 @@ if [ "$NO_UPLOAD" = true ]; then
|
||||
B2_UPLOAD_SUCCESS="skipped"
|
||||
else
|
||||
echo "=== UPLOADING TO BACKBLAZE B2 ==="
|
||||
|
||||
|
||||
# Update metrics for B2 upload phase
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_update_status "running" "Uploading backups to Backblaze B2"
|
||||
fi
|
||||
|
||||
|
||||
B2_UPLOAD_SUCCESS=true
|
||||
|
||||
# Upload database backup from local location
|
||||
|
||||
Reference in New Issue
Block a user