From 9a163b3bf2be94e168e09edd6acc570c8d268d5f Mon Sep 17 00:00:00 2001 From: fpicone Date: Thu, 11 Dec 2025 16:42:27 +0100 Subject: [PATCH] Fix tablespaces & add Gotify Notification --- .secret.example | 4 ++++ backup.sh | 27 +++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.secret.example b/.secret.example index 196bbd3..96c7248 100644 --- a/.secret.example +++ b/.secret.example @@ -5,3 +5,7 @@ DB_HOST=localhost DB_NAME=nome_database DB_USER=utente_mysql DB_PASS=password_mysql + +# Gotify +GOTIFY_URL="https://alert.qwince.com/message" +GOTIFY_TOKEN="ABnq7pJSSPrFRjx" diff --git a/backup.sh b/backup.sh index f9612bb..e2734a6 100644 --- a/backup.sh +++ b/backup.sh @@ -39,6 +39,21 @@ if [ -z "$DB_HOST" ] || [ -z "$DB_NAME" ] || [ -z "$DB_USER" ] || [ -z "$DB_PASS exit 1 fi +# Funzione per inviare notifica a Gotify +send_gotify_notification() { + local title="$1" + local message="$2" + local priority="${3:-5}" + + if [ -n "$GOTIFY_URL" ] && [ -n "$GOTIFY_TOKEN" ]; then + curl -X POST "$GOTIFY_URL" \ + -H "Content-Type: application/json" \ + -d "{\"title\":\"$title\",\"message\":\"$message\",\"priority\":$priority}" \ + -H "X-Gotify-Key: $GOTIFY_TOKEN" \ + -s > /dev/null 2>&1 + fi +} + # Configurazione TIMESTAMP=$(date +"%Y%m%d_%H%M%S") BACKUP_DIR="$SCRIPT_DIR/backup_${DOMAIN}_$TIMESTAMP" @@ -52,10 +67,11 @@ mkdir -p "$BACKUP_DIR" # Esegui dump del database echo "Esecuzione dump del database $DB_NAME per il dominio $DOMAIN..." -mysqldump -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" > "$DB_DUMP_FILE" +mysqldump --no-tablespaces -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" > "$DB_DUMP_FILE" if [ $? -ne 0 ]; then echo "Errore durante il dump del database" + send_gotify_notification "❌ Backup Fallito" "Errore durante il dump del database $DB_NAME per $DOMAIN" 8 rm -rf "$BACKUP_DIR" exit 1 fi @@ -73,6 +89,7 @@ else if [ $? -ne 0 ]; then echo "Errore durante la copia della cartella del sito" + send_gotify_notification "❌ Backup Fallito" "Errore durante la copia della cartella $SITE_DIR" 8 rm -rf "$BACKUP_DIR" exit 1 fi @@ -87,6 +104,7 @@ zip -r "$ZIP_FILE" "backup_${DOMAIN}_$TIMESTAMP" if [ $? -ne 0 ]; then echo "Errore durante la creazione dell'archivio zip" + send_gotify_notification "❌ Backup Fallito" "Errore durante la creazione dell'archivio zip per $DOMAIN" 8 rm -rf "$BACKUP_DIR" exit 1 fi @@ -97,9 +115,14 @@ echo "Archivio zip creato: $ZIP_FILE" echo "Pulizia file temporanei..." rm -rf "$BACKUP_DIR" +BACKUP_SIZE=$(du -h "$ZIP_FILE" | cut -f1) + echo "" echo "==========================================" echo "Backup completato con successo!" echo "File: $ZIP_FILE" -echo "Dimensione: $(du -h "$ZIP_FILE" | cut -f1)" +echo "Dimensione: $BACKUP_SIZE" echo "==========================================" + +# Invia notifica di successo +send_gotify_notification "✅ Backup Completato" "Backup di $DOMAIN completato con successo\nFile: backup_${DOMAIN}_$TIMESTAMP.zip\nDimensione: $BACKUP_SIZE" 5