backup-automation/forgejo/forgejo-backup.sh
ZoopaMario 6f394a867a
All checks were successful
Check Commit Messages / check-commit-message (pull_request) Successful in 52s
Lint Bash Scripts / lint-bash (pull_request) Successful in 30s
Lint Bash Scripts / lint-bash (push) Successful in 26s
Refactor code to make linter runs succeed
This commit refactors the codebase in order to make the shellcheck
workflow pass.
2024-12-29 19:32:26 +01:00

42 lines
1.2 KiB
Bash
Executable file

#!/bin/bash
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
# shellcheck disable=SC1090
source "$SCRIPT_ABS_LOCATION/forgejo-backup.env"
# shellcheck disable=SC1090
source "$SCRIPT_ABS_LOCATION/../logger.sh"
# Container Names
APP_CONTAINER="forgejo"
BACKUP_CONTAINER="duplicati"
# shellcheck disable=SC2034
LOG_FILE="$SCRIPT_ABS_LOCATION/forgejo-backup.log"
SOURCE_DIR="/mnt/data/forgejo"
# Stop forgejo container
log "Stopping forgejo container..."
docker stop $APP_CONTAINER || { log "Error: Failed to stop forgejo."; exit 1; }
# Backup all files to target destination
log "Backing up forgejo files (including the SQLite database)..."
docker exec $BACKUP_CONTAINER \
duplicati-cli backup \
"ssh://$BACKUP_DESTINATION" \
"$SOURCE_DIR" \
--backup-name="forgejo backup" \
--keep-versions=7 \
--auth-username="$SFTP_USERNAME" \
--auth-password="$SFTP_PASSWORD" \
--passphrase="$BACKUP_ENCR_PASSPHRASE" \
--ssh-fingerprint="$SFTP_FINGERPRINT" \
--prefix="forgejo" || { log "Error: Failed to backup forgejo files and database."; exit 1; }
# Turn off Maintenance Mode
log "Starting forgejo container..."
docker start "$APP_CONTAINER" || { log "Error: Failed to start forgejo container."; exit 1; }
log "Forgejo backup completed successfully."