backup-automation/immich/immich-backup.sh

44 lines
1.1 KiB
Bash
Raw Normal View History

2024-08-04 23:10:36 +02:00
#!/bin/bash
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
# shellcheck disable=SC1090
source "$SCRIPT_ABS_LOCATION/immich-backup.env"; \
# shellcheck disable=SC1090
source "$SCRIPT_ABS_LOCATION/../logger.sh"; \
2024-08-04 23:10:36 +02:00
# shellcheck disable=SC1090
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
2024-08-04 23:10:36 +02:00
# shellcheck disable=SC2034
LOG_FILE="$SCRIPT_ABS_LOCATION/immich-backup.log"
DB_CONTAINER="immich_postgres"
BACKUP_CONTAINER="duplicati"
2024-08-04 23:10:36 +02:00
DB_USER="postgres"
SOURCE_DIR="/mnt/data/immich"
DB_TMP_BAK_NAME="postgres_$(date +"%Y%m%d").bak"
dump_postgres_db "$DB_CONTAINER" "$DB_USER" "/var/lib/postgresql/data/$DB_TMP_BAK_NAME"
run_duplicati_backup \
"$BACKUP_CONTAINER" \
"$BACKUP_DESTINATION" \
"immich" \
7 \
"$SFTP_USERNAME" \
"$SFTP_PASSWORD" \
"$BACKUP_ENCR_PASSPHRASE" \
"$SFTP_FINGERPRINT" \
"$SOURCE_DIR/data/library" \
"$SOURCE_DIR/data/upload" \
"$SOURCE_DIR/data/profile" \
"$SOURCE_DIR/postgres/$DB_TMP_BAK_NAME"
log "Deleting immich temp DB backup..."
docker exec "$DB_CONTAINER" rm "/var/lib/postgresql/data/$DB_TMP_BAK_NAME" || {
log "Error: Failed to delete temp DB backup."
exit 1
}