backup-automation/immich/immich-backup.sh
ZoopaMario 0005432b69
Some checks failed
Check Commit Messages / check-commit-message (pull_request) Successful in 15s
Lint Bash Scripts / lint-bash (pull_request) Failing after 24s
Refactor code to make linter runs succeed
This commit refactors the codebase in order to make the shellcheck
workflow pass.

It also makes shellcheck ignore common info messages, specifically:
- https://www.shellcheck.net/wiki/SC1091 -- Not following: ./../logger.sh: op...
- https://www.shellcheck.net/wiki/SC2015 -- Note that A && B || C is not if-t...
2024-12-29 15:18:41 +01:00

45 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
source "$SCRIPT_ABS_LOCATION/immich-backup.env"
source "$SCRIPT_ABS_LOCATION/../logger.sh"
# Container Names
DB_CONTAINER="immich_postgres"
BACKUP_CONTAINER="duplicati"
# Database Settings
DB_USER="postgres"
SOURCE_DIR="/mnt/data/immich"
# Dump Database
log "Dumping immich postgresql database..."
DB_TMP_BAK_NAME="postgres_$(date +"%Y%m%d").bak"
docker exec -t "$DB_CONTAINER" pg_dumpall \
--clean \
--if-exists \
--username="$DB_USER" \
--file="/var/lib/postgresql/data/$DB_TMP_BAK_NAME" || { log "Error: Failed to dump the immich database."; exit 1; }
# Backup all files to target destination
log "Backing up immich files and database..."
docker exec "$BACKUP_CONTAINER" duplicati-cli backup "ssh://$BACKUP_DESTINATION" \
"$SOURCE_DIR/data/library" \
"$SOURCE_DIR/data/upload" \
"$SOURCE_DIR/data/profile" \
"$SOURCE_DIR/postgres/$DB_TMP_BAK_NAME" \
--backup-name="immich backup" \
--keep-versions=7 \
--auth-username="$SFTP_USERNAME" \
--auth-password="$SFTP_PASSWORD" \
--passphrase="$BACKUP_ENCR_PASSPHRASE" \
--ssh-fingerprint="$SFTP_FINGERPRINT" \
--prefix="immich" || { log "Error: Failed to backup immich files and database."; exit 1; }
# Delete temporary backup files
log "Deleting temporary backup files..."
docker exec "$DB_CONTAINER" rm "/var/lib/postgresql/data/$DB_TMP_BAK_NAME" || { log "Error: Failed to delete temporary backup files."; exit 1; }
log "immich backup completed successfully."