WIP Refactor code base
Add a library file containing common logic to be sourced by individual backup scripts
This commit is contained in:
parent
6f394a867a
commit
db7d5a154a
76
common-backup.sh
Executable file
76
common-backup.sh
Executable file
|
@ -0,0 +1,76 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
stop_container() {
|
||||||
|
local c="$1"
|
||||||
|
log "Stopping $c..."
|
||||||
|
docker stop "$c" || { log "Error stopping $c"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
start_container() {
|
||||||
|
local c="$1"
|
||||||
|
log "Starting $c..."
|
||||||
|
docker start "$c" || { log "Error starting $c"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
enable_maintenance_mode() {
|
||||||
|
local c="$1"
|
||||||
|
local cmd="$2"
|
||||||
|
log "Enabling maintenance mode for $c..."
|
||||||
|
docker exec -u www-data "$c" $cmd || { log "Error enabling maintenance mode"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
disable_maintenance_mode() {
|
||||||
|
local c="$1"
|
||||||
|
local cmd="$2"
|
||||||
|
log "Disabling maintenance mode for $c..."
|
||||||
|
docker exec -u www-data "$c" $cmd || { log "Error disabling maintenance mode"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
dump_postgres_db() {
|
||||||
|
local c="$1"
|
||||||
|
local user="$2"
|
||||||
|
local path="$3"
|
||||||
|
log "Dumping PostgreSQL db..."
|
||||||
|
docker exec -t "$c" pg_dumpall --clean --if-exists --username="$user" --file="$path" || { log "Error dumping PostgreSQL"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
dump_mariadb_db() {
|
||||||
|
local c="$1"
|
||||||
|
local user="$2"
|
||||||
|
local pass="$3"
|
||||||
|
local db="$4"
|
||||||
|
local path="$5"
|
||||||
|
log "Dumping MariaDB/MySQL db..."
|
||||||
|
docker exec "$c" mariadb-dump --single-transaction -h localhost -u "$user" -p"$pass" "$db" > "$path" || { log "Error dumping MariaDB/MySQL"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
dump_sqlite_db() {
|
||||||
|
local src="$1"
|
||||||
|
local dst="$2"
|
||||||
|
log "Dumping SQLite db..."
|
||||||
|
sqlite3 "$src" ".backup $dst" || { log "Error dumping SQLite"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
run_duplicati_backup() {
|
||||||
|
local c="$1"
|
||||||
|
local dest="$2"
|
||||||
|
local name="$3"
|
||||||
|
local versions="$4"
|
||||||
|
local sftp_user="$5"
|
||||||
|
local sftp_pass="$6"
|
||||||
|
local passphrase="$7"
|
||||||
|
local fingerprint="$8"
|
||||||
|
shift 8
|
||||||
|
local sources=("$@")
|
||||||
|
log "Running duplicati backup for $name..."
|
||||||
|
docker exec "$c" duplicati-cli backup "$dest" "${sources[@]}" \
|
||||||
|
--backup-name="$name" \
|
||||||
|
--keep-versions="$versions" \
|
||||||
|
--auth-username="$sftp_user" \
|
||||||
|
--auth-password="$sftp_pass" \
|
||||||
|
--passphrase="$passphrase" \
|
||||||
|
--ssh-fingerprint="$fingerprint" \
|
||||||
|
--prefix="$name" || { log "Error in duplicati backup for $name"; exit 1; }
|
||||||
|
log "$name backup complete."
|
||||||
|
}
|
||||||
|
|
|
@ -1,48 +1,34 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
|
SCRIPT_ABS_LOCATION="$(realpath "$(dirname "$0")")"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$SCRIPT_ABS_LOCATION/cryptpad-backup.env"
|
source "$SCRIPT_ABS_LOCATION/cryptpad-backup.env"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
||||||
|
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
|
||||||
# Container Names
|
|
||||||
CONTAINER="cryptpad"
|
|
||||||
BACKUP_CONTAINER="duplicati"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
LOG_FILE="$SCRIPT_ABS_LOCATION/cryptpad-backup.log"
|
LOG_FILE="$SCRIPT_ABS_LOCATION/cryptpad-backup.log"
|
||||||
|
|
||||||
SOURCE_DIR="/mnt/data/cryptpad"
|
log "Cleaning up inactive files..."
|
||||||
|
docker exec cryptpad /usr/local/bin/node scripts/evict-inactive.js --workdir=/cryptpad || { log "Error cleaning up inactive files"; exit 1; }
|
||||||
|
|
||||||
# Cleanup inactive and archive files
|
log "Cleaning up archived files..."
|
||||||
log "Cleaning up inactive accounts and files to save space..."
|
docker exec cryptpad /usr/local/bin/node scripts/evict-archived.js --workdir=/cryptpad || { log "Error cleaning up archived files"; exit 1; }
|
||||||
docker exec cryptpad \
|
|
||||||
/usr/local/bin/node scripts/evict-inactive.js \
|
|
||||||
--workdir=/cryptpad || { log "Error: Failed to clean up inactive files"; exit 1; }
|
|
||||||
|
|
||||||
log "Cleaning up archived beyond retention period files to save space..."
|
run_duplicati_backup \
|
||||||
docker exec cryptpad \
|
"$BACKUP_CONTAINER" \
|
||||||
/usr/local/bin/node scripts/evict-archived.js \
|
"$BACKUP_DESTINATION" \
|
||||||
--workdir=/cryptpad || { log "Error: Failed to clean up inactive files"; exit 1; }
|
"cryptpad" \
|
||||||
|
7 \
|
||||||
|
"$SFTP_USERNAME" \
|
||||||
|
"$SFTP_PASSWORD" \
|
||||||
|
"$BACKUP_ENCR_PASSPHRASE" \
|
||||||
|
"$SFTP_FINGERPRINT" \
|
||||||
|
"$SOURCE_DIR/data" \
|
||||||
|
"$SOURCE_DIR/datastore" \
|
||||||
|
"$SOURCE_DIR/block" \
|
||||||
|
"$SOURCE_DIR/blob" \
|
||||||
|
"$SOURCE_DIR/config/config.js" \
|
||||||
|
"$SOURCE_DIR/customize" \
|
||||||
|
"$SOURCE_DIR/customize.dist"
|
||||||
|
|
||||||
# Backup all files to target destination
|
|
||||||
log "Backing up cryptpad files and database..."
|
|
||||||
docker exec "$BACKUP_CONTAINER" \
|
|
||||||
duplicati-cli backup "ssh://$BACKUP_DESTINATION" \
|
|
||||||
"$SOURCE_DIR/data" \
|
|
||||||
"$SOURCE_DIR/datastore" \
|
|
||||||
"$SOURCE_DIR/block" \
|
|
||||||
"$SOURCE_DIR/blob" \
|
|
||||||
"$SOURCE_DIR/config/config.js" \
|
|
||||||
"$SOURCE_DIR/customize" \
|
|
||||||
"$SOURCE_DIR/customize.dist" \
|
|
||||||
--backup-name="$CONTAINER backup" \
|
|
||||||
--keep-versions=7 \
|
|
||||||
--auth-username="$SFTP_USERNAME" \
|
|
||||||
--auth-password="$SFTP_PASSWORD" \
|
|
||||||
--passphrase="$BACKUP_ENCR_PASSPHRASE" \
|
|
||||||
--ssh-fingerprint="$SFTP_FINGERPRINT" \
|
|
||||||
--prefix="cryptpad" || { log "Error: Failed to backup cryptpad files and database."; exit 1; }
|
|
||||||
log "cryptpad backup completed successfully."
|
|
||||||
|
|
|
@ -1,41 +1,26 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
|
SCRIPT_ABS_LOCATION="$(realpath "$(dirname "$0")")"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$SCRIPT_ABS_LOCATION/forgejo-backup.env"
|
source "$SCRIPT_ABS_LOCATION/forgejo-backup.env"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
||||||
|
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
|
||||||
# Container Names
|
|
||||||
APP_CONTAINER="forgejo"
|
|
||||||
BACKUP_CONTAINER="duplicati"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
LOG_FILE="$SCRIPT_ABS_LOCATION/forgejo-backup.log"
|
LOG_FILE="$SCRIPT_ABS_LOCATION/forgejo-backup.log"
|
||||||
|
|
||||||
SOURCE_DIR="/mnt/data/forgejo"
|
stop_container "$APP_CONTAINER"
|
||||||
|
|
||||||
# Stop forgejo container
|
run_duplicati_backup \
|
||||||
log "Stopping forgejo container..."
|
"$BACKUP_CONTAINER" \
|
||||||
docker stop $APP_CONTAINER || { log "Error: Failed to stop forgejo."; exit 1; }
|
"$BACKUP_DESTINATION" \
|
||||||
|
"forgejo" \
|
||||||
|
7 \
|
||||||
|
"$SFTP_USERNAME" \
|
||||||
|
"$SFTP_PASSWORD" \
|
||||||
|
"$BACKUP_ENCR_PASSPHRASE" \
|
||||||
|
"$SFTP_FINGERPRINT" \
|
||||||
|
"$SOURCE_DIR"
|
||||||
|
|
||||||
# Backup all files to target destination
|
start_container "$APP_CONTAINER"
|
||||||
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."
|
|
||||||
|
|
|
@ -3,48 +3,37 @@ SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$SCRIPT_ABS_LOCATION/immich-backup.env"
|
source "$SCRIPT_ABS_LOCATION/immich-backup.env"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
||||||
|
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
|
||||||
# Container Names
|
|
||||||
DB_CONTAINER="immich_postgres"
|
|
||||||
BACKUP_CONTAINER="duplicati"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
LOG_FILE="$SCRIPT_ABS_LOCATION/immich-backup.log"
|
LOG_FILE="$SCRIPT_ABS_LOCATION/immich-backup.log"
|
||||||
|
|
||||||
# Database Settings
|
DB_CONTAINER="immich_postgres"
|
||||||
|
BACKUP_CONTAINER="duplicati"
|
||||||
DB_USER="postgres"
|
DB_USER="postgres"
|
||||||
|
|
||||||
SOURCE_DIR="/mnt/data/immich"
|
SOURCE_DIR="/mnt/data/immich"
|
||||||
|
|
||||||
# Dump Database
|
|
||||||
log "Dumping immich postgresql database..."
|
|
||||||
DB_TMP_BAK_NAME="postgres_$(date +"%Y%m%d").bak"
|
DB_TMP_BAK_NAME="postgres_$(date +"%Y%m%d").bak"
|
||||||
docker exec -t "$DB_CONTAINER" pg_dumpall \
|
|
||||||
--clean \
|
|
||||||
--if-exists \
|
|
||||||
--username="$DB_USER" \
|
|
||||||
--file="/var/lib/postgresql/data/$DB_TMP_BAK_NAME" || { log "Error: Failed to dump the immich database."; exit 1; }
|
|
||||||
|
|
||||||
# Backup all files to target destination
|
dump_postgres_db "$DB_CONTAINER" "$DB_USER" "/var/lib/postgresql/data/$DB_TMP_BAK_NAME"
|
||||||
log "Backing up immich files and database..."
|
|
||||||
docker exec "$BACKUP_CONTAINER" duplicati-cli backup "ssh://$BACKUP_DESTINATION" \
|
run_duplicati_backup \
|
||||||
|
"$BACKUP_CONTAINER" \
|
||||||
|
"$BACKUP_DESTINATION" \
|
||||||
|
"immich" \
|
||||||
|
7 \
|
||||||
|
"$SFTP_USERNAME" \
|
||||||
|
"$SFTP_PASSWORD" \
|
||||||
|
"$BACKUP_ENCR_PASSPHRASE" \
|
||||||
|
"$SFTP_FINGERPRINT" \
|
||||||
"$SOURCE_DIR/data/library" \
|
"$SOURCE_DIR/data/library" \
|
||||||
"$SOURCE_DIR/data/upload" \
|
"$SOURCE_DIR/data/upload" \
|
||||||
"$SOURCE_DIR/data/profile" \
|
"$SOURCE_DIR/data/profile" \
|
||||||
"$SOURCE_DIR/postgres/$DB_TMP_BAK_NAME" \
|
"$SOURCE_DIR/postgres/$DB_TMP_BAK_NAME"
|
||||||
--backup-name="immich backup" \
|
|
||||||
--keep-versions=7 \
|
|
||||||
--auth-username="$SFTP_USERNAME" \
|
|
||||||
--auth-password="$SFTP_PASSWORD" \
|
|
||||||
--passphrase="$BACKUP_ENCR_PASSPHRASE" \
|
|
||||||
--ssh-fingerprint="$SFTP_FINGERPRINT" \
|
|
||||||
--prefix="immich" || { log "Error: Failed to backup immich files and database."; exit 1; }
|
|
||||||
|
|
||||||
# Delete temporary backup files
|
log "Deleting immich temp DB backup..."
|
||||||
log "Deleting temporary backup files..."
|
docker exec "$DB_CONTAINER" rm "/var/lib/postgresql/data/$DB_TMP_BAK_NAME" || {
|
||||||
docker exec "$DB_CONTAINER" rm "/var/lib/postgresql/data/$DB_TMP_BAK_NAME" || { log "Error: Failed to delete temporary backup files."; exit 1; }
|
log "Error: Failed to delete temp DB backup."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
log "immich backup completed successfully."
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Function to log messages
|
|
||||||
log() {
|
log() {
|
||||||
local message="$1"
|
local message="$1"
|
||||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" | tee -a "$LOG_FILE"
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" | tee -a "$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,60 +3,42 @@ SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$SCRIPT_ABS_LOCATION/nextcloud-backup.env"
|
source "$SCRIPT_ABS_LOCATION/nextcloud-backup.env"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
||||||
|
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
|
||||||
# Container Names
|
|
||||||
APP_CONTAINER="nextcloud-app"
|
|
||||||
DB_CONTAINER="nextcloud-db"
|
|
||||||
BACKUP_CONTAINER="duplicati"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
LOG_FILE="$SCRIPT_ABS_LOCATION/nextcloud-backup.log"
|
LOG_FILE="$SCRIPT_ABS_LOCATION/nextcloud-backup.log"
|
||||||
|
|
||||||
# Database Settings
|
APP_CONTAINER="nextcloud-app"
|
||||||
|
DB_CONTAINER="nextcloud-db"
|
||||||
|
BACKUP_CONTAINER="duplicati"
|
||||||
DB_USER="nextcloud"
|
DB_USER="nextcloud"
|
||||||
|
|
||||||
SOURCE_DIR="/mnt/data/nextcloud"
|
SOURCE_DIR="/mnt/data/nextcloud"
|
||||||
|
|
||||||
# Put Nextcloud in Maintenance Mode
|
|
||||||
log "Putting Nextcloud in maintenance mode..."
|
|
||||||
docker exec -u www-data "$APP_CONTAINER" php occ maintenance:mode --on || { log "Error: Failed to put Nextcloud in maintenance mode."; exit 1; }
|
|
||||||
|
|
||||||
# Dump Database
|
|
||||||
log "Dumping Nextcloud database..."
|
|
||||||
DB_TMP_BAK_NAME="nextcloud-db_$(date +"%Y%m%d").bak"
|
DB_TMP_BAK_NAME="nextcloud-db_$(date +"%Y%m%d").bak"
|
||||||
docker exec "$DB_CONTAINER" /usr/bin/mariadb-dump \
|
|
||||||
--single-transaction \
|
|
||||||
-h localhost \
|
|
||||||
-u "$DB_USER" \
|
|
||||||
-p"$DB_PASSWORD" \
|
|
||||||
nextcloud > "$SOURCE_DIR/$DB_TMP_BAK_NAME" || { log "Error: Failed to dump the Nextcloud database."; exit 1; }
|
|
||||||
|
|
||||||
# Backup all files to target destination
|
enable_maintenance_mode "$APP_CONTAINER" "php occ maintenance:mode --on"
|
||||||
log "Backing up Nextcloud files and database..."
|
|
||||||
docker exec "$BACKUP_CONTAINER" \
|
|
||||||
duplicati-cli backup \
|
|
||||||
"ssh://$BACKUP_DESTINATION" \
|
|
||||||
"$SOURCE_DIR/html/data" \
|
|
||||||
"$SOURCE_DIR/html/config" \
|
|
||||||
"$SOURCE_DIR/html/themes" \
|
|
||||||
"$SOURCE_DIR/$DB_TMP_BAK_NAME" \
|
|
||||||
--backup-name="nextcloud backup" \
|
|
||||||
--keep-versions=7 \
|
|
||||||
--auth-username="$SFTP_USERNAME" \
|
|
||||||
--auth-password="$SFTP_PASSWORD" \
|
|
||||||
--passphrase="$BACKUP_ENCR_PASSPHRASE" \
|
|
||||||
--ssh-fingerprint="$SFTP_FINGERPRINT" \
|
|
||||||
--prefix="nextcloud" || { log "Error: Failed to backup Nextcloud files and database."; exit 1; }
|
|
||||||
|
|
||||||
# Turn off Maintenance Mode
|
dump_mariadb_db "$DB_CONTAINER" "$DB_USER" "$DB_PASSWORD" "nextcloud" "$SOURCE_DIR/$DB_TMP_BAK_NAME"
|
||||||
log "Turning off Nextcloud maintenance mode..."
|
|
||||||
docker exec -u www-data "$APP_CONTAINER" php occ maintenance:mode --off || { log "Error: Failed to turn off Nextcloud maintenance mode."; exit 1; }
|
|
||||||
|
|
||||||
# Delete temporary backup files
|
run_duplicati_backup \
|
||||||
log "Deleting temporary backup files..."
|
"$BACKUP_CONTAINER" \
|
||||||
rm "$SOURCE_DIR/$DB_TMP_BAK_NAME" || { log "Error: Failed to delete temporary databse file"; exit 1; }
|
"$BACKUP_DESTINATION" \
|
||||||
|
"nextcloud" \
|
||||||
|
7 \
|
||||||
|
"$SFTP_USERNAME" \
|
||||||
|
"$SFTP_PASSWORD" \
|
||||||
|
"$BACKUP_ENCR_PASSPHRASE" \
|
||||||
|
"$SFTP_FINGERPRINT" \
|
||||||
|
"$SOURCE_DIR/html/data" \
|
||||||
|
"$SOURCE_DIR/html/config" \
|
||||||
|
"$SOURCE_DIR/html/themes" \
|
||||||
|
"$SOURCE_DIR/$DB_TMP_BAK_NAME"
|
||||||
|
|
||||||
|
disable_maintenance_mode "$APP_CONTAINER" "php occ maintenance:mode --off"
|
||||||
|
|
||||||
|
log "Deleting Nextcloud temp DB backup..."
|
||||||
|
rm "$SOURCE_DIR/$DB_TMP_BAK_NAME" || {
|
||||||
|
log "Error: Failed to delete temp DB backup."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
log "Nextcloud backup completed successfully."
|
|
||||||
|
|
|
@ -3,39 +3,28 @@ SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$SCRIPT_ABS_LOCATION/portainer-backup.env"
|
source "$SCRIPT_ABS_LOCATION/portainer-backup.env"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
||||||
|
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
|
||||||
# Container Names
|
|
||||||
APP_CONTAINER="portainer"
|
|
||||||
BACKUP_CONTAINER="duplicati"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
LOG_FILE="$SCRIPT_ABS_LOCATION/portainer-backup.log"
|
LOG_FILE="$SCRIPT_ABS_LOCATION/portainer-backup.log"
|
||||||
|
|
||||||
|
APP_CONTAINER="portainer"
|
||||||
|
BACKUP_CONTAINER="duplicati"
|
||||||
SOURCE_DIR="/volumes/portainer"
|
SOURCE_DIR="/volumes/portainer"
|
||||||
|
|
||||||
# Stop portainer container
|
stop_container "$APP_CONTAINER"
|
||||||
log "Stopping portainer container..."
|
|
||||||
docker stop $APP_CONTAINER || { log "Error: Failed to stop portainer."; exit 1; }
|
|
||||||
|
|
||||||
# Backup all files to target destination
|
run_duplicati_backup \
|
||||||
log "Backing up portainer files (including the SQLite database)..."
|
"$BACKUP_CONTAINER" \
|
||||||
docker exec "$BACKUP_CONTAINER" \
|
"$BACKUP_DESTINATION" \
|
||||||
duplicati-cli backup \
|
"portainer" \
|
||||||
"ssh://$BACKUP_DESTINATION" \
|
7 \
|
||||||
"$SOURCE_DIR" \
|
"$SFTP_USERNAME" \
|
||||||
--backup-name="portainer backup" \
|
"$SFTP_PASSWORD" \
|
||||||
--keep-versions=7 \
|
"$BACKUP_ENCR_PASSPHRASE" \
|
||||||
--auth-username="$SFTP_USERNAME" \
|
"$SFTP_FINGERPRINT" \
|
||||||
--auth-password="$SFTP_PASSWORD" \
|
"$SOURCE_DIR"
|
||||||
--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
|
start_container "$APP_CONTAINER"
|
||||||
log "Starting portainer container..."
|
|
||||||
docker start "$APP_CONTAINER" || { log "Error: Failed to start portainer container."; exit 1; }
|
|
||||||
|
|
||||||
log "portainer backup completed successfully."
|
|
||||||
|
|
|
@ -3,38 +3,32 @@ SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$SCRIPT_ABS_LOCATION/vaultwarden-backup.env"
|
source "$SCRIPT_ABS_LOCATION/vaultwarden-backup.env"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
source "$SCRIPT_ABS_LOCATION/../logger.sh"
|
||||||
|
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
|
||||||
# Container Names
|
|
||||||
BACKUP_CONTAINER="duplicati"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
LOG_FILE="$SCRIPT_ABS_LOCATION/vaultwarden-backup.log"
|
LOG_FILE="$SCRIPT_ABS_LOCATION/vaultwarden-backup.log"
|
||||||
|
|
||||||
|
BACKUP_CONTAINER="duplicati"
|
||||||
SOURCE_DIR="/mnt/data/vaultwarden"
|
SOURCE_DIR="/mnt/data/vaultwarden"
|
||||||
|
DB_TMP_BAK_NAME="vaultwarden-db_$(date +"%Y%m%d").sqlite3"
|
||||||
|
|
||||||
# Dump Database
|
dump_sqlite_db "$SOURCE_DIR/db.sqlite3" "$SOURCE_DIR/$DB_TMP_BAK_NAME"
|
||||||
log "Dumping vaultwarden database..."
|
|
||||||
DB_TMP_BAK_NAME=vaultwarden-db_$(date +"%Y%m%d").sqlite3
|
|
||||||
sqlite3 "$SOURCE_DIR/db.sqlite3" ".backup $SOURCE_DIR/$DB_TMP_BAK_NAME" || { log "Error: Failed to dump the Nextcloud database."; exit 1; }
|
|
||||||
|
|
||||||
# Backup all files to target destination
|
run_duplicati_backup \
|
||||||
log "Backing up vaultwarden files and database..."
|
"$BACKUP_CONTAINER" \
|
||||||
docker exec "$BACKUP_CONTAINER" duplicati-cli backup \
|
"$BACKUP_DESTINATION" \
|
||||||
"ssh://$BACKUP_DESTINATION" \
|
"vaultwarden" \
|
||||||
"$SOURCE_DIR" \
|
7 \
|
||||||
--backup-name="vaultwarden backup" \
|
"$SFTP_USERNAME" \
|
||||||
--keep-versions=7 \
|
"$SFTP_PASSWORD" \
|
||||||
--auth-username="$SFTP_USERNAME" \
|
"$BACKUP_ENCR_PASSPHRASE" \
|
||||||
--auth-password="$SFTP_PASSWORD" \
|
"$SFTP_FINGERPRINT" \
|
||||||
--passphrase="$BACKUP_ENCR_PASSPHRASE" \
|
"$SOURCE_DIR"
|
||||||
--ssh-fingerprint="$SFTP_FINGERPRINT" \
|
|
||||||
--prefix="vaultwarden" || { log "Error: Failed to backup vaultwarden files and database."; exit 1; }
|
|
||||||
|
|
||||||
# Delete temporary backup files
|
log "Deleting vaultwarden temp DB backup..."
|
||||||
log "Deleting temporary backup files..."
|
rm "$SOURCE_DIR/$DB_TMP_BAK_NAME" || {
|
||||||
rm "$SOURCE_DIR/$DB_TMP_BAK_NAME" || { log "Error: Failed to delete temporary backup files."; exit 1; }
|
log "Error: Failed to delete temp DB backup."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
log "vaultwarden backup completed successfully."
|
|
||||||
|
|
Loading…
Reference in a new issue