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