Create and intergrate portainer backup procedure

- Add to full-backup.sh script execution
This commit is contained in:
ZoopaMario 2024-09-02 00:21:06 +02:00
parent 5cdb7cf942
commit 2d034b4d6d
2 changed files with 46 additions and 1 deletions

View file

@ -3,7 +3,7 @@
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
# Define an array of application names
declare -a apps=("cryptpad" "immich" "duplicati" "nextcloud" "vaultwarden" "forgejo")
declare -a apps=("cryptpad" "immich" "duplicati" "nextcloud" "vaultwarden" "forgejo" "portainer")
# Function to execute the backup script for each application
backup_app() {

45
portainer/portainer-backup.sh Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
source $SCRIPT_ABS_LOCATION/portainer-backup.env
source $SCRIPT_ABS_LOCATION/../logger.sh
# Container Names
APP_CONTAINER="portainer"
BACKUP_CONTAINER="duplicati"
SOURCE_DIR="/volumes/portainer"
BACKUP_DESTINATION="$BACKUP_DESTINATION"
BACKUP_ENCR_PASSPHRASE="$BACKUP_ENCR_PASSPHRASE"
# Cloud Storage Authentication
SFTP_USERNAME="$SFTP_USERNAME"
SFTP_PASSWORD="$SFTP_PASSWORD"
SFTP_FINGERPRINT="$SFTP_FINGERPRINT"
# Log file
LOG_FILE="$SCRIPT_ABS_LOCATION/portainer-backup.log"
# 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)..."
docker exec $BACKUP_CONTAINER \
duplicati-cli backup \
ssh://$BACKUP_DESTINATION \
$SOURCE_DIR \
--backup-name="portainer backup" \
--keep-versions=7 \
--auth-username=$SFTP_USERNAME \
--auth-password=$SFTP_PASSWORD \
--passphrase=$BACKUP_ENCR_PASSPHRASE \
--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..."
docker start $APP_CONTAINER || { log "Error: Failed to start portainer container."; exit 1; }
log "portainer backup completed successfully."