Backup automatico script del 2026-08-21 11:59
This commit is contained in:
1 parent
beb790ed7e
commit
11823447a2
2 files changed
+30
-17
No files matched your search
@@ -1,36 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ==============================================================================
|
||||
# 💾 AUTO GIT BACKUP - DINAMICO
|
||||
# AUTO GIT BACKUP - DINAMICO
|
||||
# Sincronizza automaticamente tutti gli script .sh e .py dal Pi2 e dal Pi1
|
||||
# verso il repository Gitea locale, poi esegue il push.
|
||||
# ==============================================================================
|
||||
|
||||
set -u
|
||||
|
||||
# --- CONFIGURAZIONE ---
|
||||
REPO_DIR="/home/daniely/loogle-repo"
|
||||
LOG_FILE="/var/log/git-backup.log"
|
||||
DATE=$(date +"%Y-%m-%d %H:%M")
|
||||
export GIT_SSH_COMMAND="ssh -o BatchMode=yes -o ConnectTimeout=10"
|
||||
|
||||
# IP del Pi1 (Master) da cui prelevare i file remoti
|
||||
PI1_IP="192.168.128.80"
|
||||
PI1_USER="daniely"
|
||||
|
||||
# Redirige tutto l'output (stdout e stderr) nel log
|
||||
exec >> $LOG_FILE 2>&1
|
||||
exec >> "$LOG_FILE" 2>&1
|
||||
|
||||
echo "=== Inizio Backup Git: $DATE ==="
|
||||
|
||||
fail() {
|
||||
echo "❌ $1"
|
||||
echo "=== Fine Backup Git (ERRORE) ==="
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 1. PREPARAZIONE REPOSITORY
|
||||
# --------------------------
|
||||
if [ -d "$REPO_DIR" ]; then
|
||||
cd "$REPO_DIR" || { echo "❌ Errore: Impossibile entrare in $REPO_DIR"; exit 1; }
|
||||
cd "$REPO_DIR" || fail "Impossibile entrare in $REPO_DIR"
|
||||
else
|
||||
echo "❌ Errore: La cartella $REPO_DIR non esiste."; exit 1;
|
||||
fail "La cartella $REPO_DIR non esiste."
|
||||
fi
|
||||
|
||||
# Aggiorna il repository locale (pull) per evitare conflitti
|
||||
echo "🔄 Eseguo Git Pull..."
|
||||
git pull origin main
|
||||
if ! git pull --ff-only origin main; then
|
||||
echo "⚠️ Git pull fallito (proseguo con commit locale se possibile)."
|
||||
fi
|
||||
|
||||
# Assicuriamoci che le cartelle di destinazione esistano
|
||||
mkdir -p ./scripts/pi2-backup
|
||||
@@ -43,7 +54,6 @@ mkdir -p ./configs
|
||||
echo "📂 Raccolta dinamica file locali (Pi-2)..."
|
||||
|
||||
# A. Script nella Home (solo .sh) -> scripts/pi2-backup
|
||||
# --include='*.sh' prende gli script, --exclude='*' ignora tutto il resto
|
||||
rsync -av --include='*.sh' --exclude='*' /home/daniely/ "$REPO_DIR/scripts/pi2-backup/"
|
||||
|
||||
# B. Script del Bot (tutti .py e .sh) -> services/telegram-bot
|
||||
@@ -61,16 +71,16 @@ fi
|
||||
echo "📡 Raccolta dinamica file remoti (Pi-1)..."
|
||||
|
||||
# A. Script nella Home remota (.sh e .py) -> scripts/pi1-master
|
||||
# Nota: Richiede che le chiavi SSH siano configurate per non chiedere password
|
||||
rsync -av -e "ssh -q" --include='*.sh' --include='*.py' --exclude='*' $PI1_USER@$PI1_IP:/home/daniely/ "$REPO_DIR/scripts/pi1-master/"
|
||||
rsync -av -e "ssh -q" --include='*.sh' --include='*.py' --exclude='*' \
|
||||
"$PI1_USER@$PI1_IP:/home/daniely/" "$REPO_DIR/scripts/pi1-master/" \
|
||||
|| echo "⚠️ rsync Pi1 fallito (ignorato)"
|
||||
|
||||
# B. Recupero file specifici fuori dalla home (Legacy da vecchio script)
|
||||
# Se dhcp-alert.sh esiste ancora in /usr/local/bin, lo prendiamo
|
||||
scp -q $PI1_USER@$PI1_IP:/usr/local/bin/dhcp-alert.sh ./scripts/pi1-master/ 2>/dev/null || echo "⚠️ dhcp-alert.sh non trovato su Pi1 (ignorato)"
|
||||
scp -q "$PI1_USER@$PI1_IP:/usr/local/bin/dhcp-alert.sh" ./scripts/pi1-master/ 2>/dev/null \
|
||||
|| echo "⚠️ dhcp-alert.sh non trovato su Pi1 (ignorato)"
|
||||
|
||||
# C. Configurazione Keepalived Remota
|
||||
scp -q $PI1_USER@$PI1_IP:/etc/keepalived/keepalived.conf ./configs/keepalived_pi1.conf 2>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
if scp -q "$PI1_USER@$PI1_IP:/etc/keepalived/keepalived.conf" ./configs/keepalived_pi1.conf 2>/dev/null; then
|
||||
echo "✅ Configurazione Keepalived Pi1 scaricata."
|
||||
else
|
||||
echo "⚠️ Impossibile scaricare Keepalived conf da Pi1."
|
||||
@@ -78,15 +88,17 @@ fi
|
||||
|
||||
# 4. GIT PUSH
|
||||
# -----------
|
||||
# Verifica se ci sono cambiamenti reali
|
||||
if [[ `git status --porcelain` ]]; then
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo "📝 Rilevati cambiamenti. Eseguo Commit e Push..."
|
||||
|
||||
git add .
|
||||
git commit -m "Backup automatico script del $DATE"
|
||||
git push -u origin main
|
||||
git commit -m "Backup automatico script del $DATE" || fail "Commit fallito"
|
||||
|
||||
echo "✅ Push completato con successo."
|
||||
if git push origin main; then
|
||||
echo "✅ Push completato con successo."
|
||||
else
|
||||
fail "Push su Gitea fallito (SSH/auth/Gitea down?)."
|
||||
fi
|
||||
else
|
||||
echo "ℹ️ Nessun cambiamento rilevato. Repository già aggiornato."
|
||||
fi
|
||||
|
||||
@@ -19,6 +19,7 @@ EXCLUDED_FILES = {
|
||||
"irrigation_cron.log",
|
||||
"road_weather.log",
|
||||
"snow_radar.log",
|
||||
"nowcast_120m_alert.log", # sostituito da meteo-alert (ADR-019, disabilitato 2026-07-25)
|
||||
}
|
||||
SEASONAL_EXCLUDED_FILES = {
|
||||
"freeze_alert.log",
|
||||
|
||||
Reference in new issue
Block a user