backup-automation/nextcloud/nextcloud-backup.sh

45 lines
1.2 KiB
Bash
Raw Normal View History

2024-08-04 23:10:36 +02:00
#!/bin/bash
SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")")
# shellcheck disable=SC1090
source "$SCRIPT_ABS_LOCATION/nextcloud-backup.env"; \
source "$SCRIPT_ABS_LOCATION/../logger.sh"; \
source "$SCRIPT_ABS_LOCATION/../common-backup.sh"
# shellcheck disable=SC2034
LOG_FILE="$SCRIPT_ABS_LOCATION/nextcloud-backup.log"
2024-08-04 23:10:36 +02:00
APP_CONTAINER="nextcloud-app"
DB_CONTAINER="nextcloud-db"
BACKUP_CONTAINER="duplicati"
DB_USER="nextcloud"
SOURCE_DIR="/mnt/data/nextcloud"
DB_TMP_BAK_NAME="nextcloud-db_$(date +"%Y%m%d").bak"
enable_maintenance_mode "$APP_CONTAINER" "php occ maintenance:mode --on"
2024-08-04 23:10:36 +02:00
dump_mariadb_db "$DB_CONTAINER" "$DB_USER" "$DB_PASSWORD" "nextcloud" "$SOURCE_DIR/$DB_TMP_BAK_NAME"
2024-08-04 23:10:36 +02:00
run_duplicati_backup \
"$BACKUP_CONTAINER" \
"$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"
2024-08-04 23:10:36 +02:00
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
}
2024-08-04 23:10:36 +02:00