backup-automation/duplicati/duplicati-backup.sh
ZoopaMario 52fee22f04
All checks were successful
Check Commit Messages / check-commit-message (pull_request) Successful in 13s
Lint Bash Scripts / lint-bash (pull_request) Successful in 23s
Lint Bash Scripts / lint-bash (push) Successful in 1m0s
Refactor code base focusing on extendability
- Add a library file containing common logic to be sourced by individual backup scripts
- Integrate logger file as it so far only contained a single method
- Make sure all relevant variables are defined within the related .env file
- Remove the option to pass command line  arguments to the script
2024-12-30 06:50:33 +01:00

47 lines
1 KiB
Bash
Executable file

#!/bin/bash
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
# shellcheck disable=SC1090
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
# shellcheck disable=SC1090
source "$SCRIPT_ABS_LOCATION/duplicati-backup.env"
# shellcheck disable=SC2034
LOG_FILE="$SCRIPT_ABS_LOCATION/duplicati-backup.log"
TMP_FILEPATH="$SCRIPT_ABS_LOCATION"
if [ -z "$TMP_FILEPATH" ]; then
log "Error: TMP_FILEPATH is not set."
exit 1
fi
stop_container duplicati
tar_and_encrypt "$SOURCE_DIR" "$TMP_FILEPATH/$TMP_FILENAME" "$BACKUP_ENCR_PASSPHRASE"
remove_old_backups \
"$SSH_USERNAME" \
"$SSH_DESTINATION" \
"$SSH_KEY" \
"$SSH_PORT" \
"$BACKUP_FOLDER" \
"$MAX_BACKUPS"
scp_transfer \
"$TMP_FILEPATH/$TMP_FILENAME" \
"$SSH_USERNAME" \
"$SSH_DESTINATION" \
"$SSH_KEY" \
"$SSH_PORT" \
"${BACKUP_FOLDER}${TMP_FILENAME}"
log "Cleaning up temporary archive..."
rm "$TMP_FILEPATH/$TMP_FILENAME" || {
log "Error: Failed to remove the temporary file."
exit 1
}
start_container duplicati
log "duplicati backup completed."