From 1b513e59e2b7418cb8dcf43f2d8ab21733b72369 Mon Sep 17 00:00:00 2001 From: ZoopaMario Date: Sun, 1 Sep 2024 18:47:37 +0200 Subject: [PATCH] backup forgejo and portainer data add backup scripts for forgejo and portainer make full-backup.sh execute them add git specific config files to .gitignore --- .gitignore | 2 ++ forgejo/forgejo-backup.sh | 45 +++++++++++++++++++++++++++++++++++ full-backup.sh | 2 +- portainer/portainer-backup.sh | 45 +++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100755 forgejo/forgejo-backup.sh create mode 100755 portainer/portainer-backup.sh diff --git a/.gitignore b/.gitignore index 808053f..b45ec99 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +.gitignore +.gitconfig *.env *.log diff --git a/forgejo/forgejo-backup.sh b/forgejo/forgejo-backup.sh new file mode 100755 index 0000000..8447fa2 --- /dev/null +++ b/forgejo/forgejo-backup.sh @@ -0,0 +1,45 @@ +#!/bin/bash +SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") + +source $SCRIPT_ABS_LOCATION/forgejo-backup.env +source $SCRIPT_ABS_LOCATION/../logger.sh + +# Container Names +APP_CONTAINER="forgejo" +BACKUP_CONTAINER="duplicati" + +SOURCE_DIR="/mnt/data/forgejo" +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/forgejo-backup.log" + +# 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." diff --git a/full-backup.sh b/full-backup.sh index 27792ce..f47168d 100755 --- a/full-backup.sh +++ b/full-backup.sh @@ -3,7 +3,7 @@ SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") # Define an array of application names -declare -a apps=("cryptpad" "immich" "duplicati" "nextcloud" "vaultwarden") +declare -a apps=("cryptpad" "immich" "duplicati" "nextcloud" "vaultwarden" "forgejo" "portainer") # Function to execute the backup script for each application backup_app() { diff --git a/portainer/portainer-backup.sh b/portainer/portainer-backup.sh new file mode 100755 index 0000000..0441641 --- /dev/null +++ b/portainer/portainer-backup.sh @@ -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."