#!/bin/bash # ============================================================================= # JH Photomaton — Sauvegarde des configurations système # # Sauvegarde : RaspAP · Zoraxy · CUPS · JH Photomaton # # Usage : # sudo bash scripts/backup-configs.sh # sudo bash scripts/backup-configs.sh /mnt/usb/backups # dossier cible custom # # Les archives sont créées dans ~/photomaton-backups/ (ou le dossier fourni). # Chaque composant génère son propre .tar.gz daté. # ============================================================================= set -euo pipefail DEST="${1:-/home/pi/photomaton-backups}" DATE=$(date +%Y%m%d-%H%M%S) ERRORS=0 # Couleurs GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m' ok() { echo -e "${GREEN}✅ $*${NC}"; } warn() { echo -e "${YELLOW}⚠ $*${NC}"; } err() { echo -e "${RED}❌ $*${NC}"; ERRORS=$((ERRORS+1)); } mkdir -p "$DEST" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " JH Photomaton — Sauvegarde configurations" echo " Date : $DATE" echo " Dossier: $DEST" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" # ───────────────────────────────────────────────────────────────────────────── # 1. RaspAP # ───────────────────────────────────────────────────────────────────────────── echo "" echo "▶ Sauvegarde RaspAP..." RASPAP_ARCHIVE="$DEST/raspap-$DATE.tar.gz" # Fichiers de configuration RaspAP RASPAP_FILES=( "/etc/hostapd/hostapd.conf" # Config WiFi hotspot (SSID, password, channel) "/etc/dnsmasq.conf" # Config DHCP/DNS principale "/etc/dhcpcd.conf" # Config IP statique wlan0 "/etc/default/hostapd" # Active hostapd au démarrage "/etc/raspap" # Config interface web RaspAP "/etc/lighttpd/conf-available/50-raspap-router.conf" # Config lighttpd "/etc/dnsmasq.d" # Configs dnsmasq additionnelles (dont notre custom DNS) "/etc/network/interfaces" # Config réseau (si présent) ) # Collecte uniquement les fichiers/dossiers existants EXISTING_FILES=() for f in "${RASPAP_FILES[@]}"; do [ -e "$f" ] && EXISTING_FILES+=("$f") || true done if [ ${#EXISTING_FILES[@]} -gt 0 ]; then tar -czf "$RASPAP_ARCHIVE" "${EXISTING_FILES[@]}" 2>/dev/null && \ ok "RaspAP → $(basename $RASPAP_ARCHIVE) ($(du -sh $RASPAP_ARCHIVE | cut -f1))" || \ err "Échec sauvegarde RaspAP" else warn "RaspAP : aucun fichier de config trouvé (RaspAP installé ?)" fi # ───────────────────────────────────────────────────────────────────────────── # 2. Zoraxy # ───────────────────────────────────────────────────────────────────────────── echo "" echo "▶ Sauvegarde Zoraxy..." ZORAXY_DIR="/home/pi/zoraxy" ZORAXY_ARCHIVE="$DEST/zoraxy-$DATE.tar.gz" if [ -d "$ZORAXY_DIR" ]; then # Sauvegarde : conf/ (règles proxy, settings) mais PAS le binaire (gros) # Les certs Let's Encrypt sont séparément dans /etc/letsencrypt/ tar -czf "$ZORAXY_ARCHIVE" \ -C "$ZORAXY_DIR" \ --exclude="zoraxy" \ # binaire — re-téléchargeable --exclude="*.log" \ . 2>/dev/null && \ ok "Zoraxy → $(basename $ZORAXY_ARCHIVE) ($(du -sh $ZORAXY_ARCHIVE | cut -f1))" || \ err "Échec sauvegarde Zoraxy" else warn "Zoraxy : dossier $ZORAXY_DIR introuvable" fi # Sauvegarde des certificats Let's Encrypt séparément LETSENCRYPT_DIR="/etc/letsencrypt" LE_ARCHIVE="$DEST/letsencrypt-$DATE.tar.gz" if [ -d "$LETSENCRYPT_DIR" ]; then tar -czf "$LE_ARCHIVE" "$LETSENCRYPT_DIR" 2>/dev/null && \ ok "Let's Encrypt → $(basename $LE_ARCHIVE) ($(du -sh $LE_ARCHIVE | cut -f1))" || \ warn "Échec sauvegarde Let's Encrypt (fichiers système, peut nécessiter root)" else warn "Let's Encrypt : /etc/letsencrypt introuvable" fi # ───────────────────────────────────────────────────────────────────────────── # 3. CUPS (Imprimantes) # ───────────────────────────────────────────────────────────────────────────── echo "" echo "▶ Sauvegarde CUPS..." CUPS_ARCHIVE="$DEST/cups-$DATE.tar.gz" CUPS_FILES=( "/etc/cups/printers.conf" # Définitions des imprimantes (noms, URIs, options) "/etc/cups/cupsd.conf" # Config serveur CUPS (accès, ports) "/etc/cups/ppd" # Fichiers PPD (drivers par imprimante) "/etc/cups/classes.conf" # Groupes d'imprimantes (si présent) ) EXISTING_CUPS=() for f in "${CUPS_FILES[@]}"; do [ -e "$f" ] && EXISTING_CUPS+=("$f") || true done if [ ${#EXISTING_CUPS[@]} -gt 0 ]; then tar -czf "$CUPS_ARCHIVE" "${EXISTING_CUPS[@]}" 2>/dev/null && \ ok "CUPS → $(basename $CUPS_ARCHIVE) ($(du -sh $CUPS_ARCHIVE | cut -f1))" || \ err "Échec sauvegarde CUPS" # Exporter aussi la liste des imprimantes en texte lisible PRINTERS_TXT="$DEST/cups-printers-$DATE.txt" echo "# Imprimantes CUPS — $DATE" > "$PRINTERS_TXT" echo "" >> "$PRINTERS_TXT" lpstat -v 2>/dev/null >> "$PRINTERS_TXT" || true echo "" >> "$PRINTERS_TXT" lpstat -p 2>/dev/null >> "$PRINTERS_TXT" || true ok "Liste imprimantes → $(basename $PRINTERS_TXT)" else warn "CUPS : aucun fichier de config trouvé (CUPS installé ?)" fi # ───────────────────────────────────────────────────────────────────────────── # 4. JH Photomaton (config + DB) # ───────────────────────────────────────────────────────────────────────────── echo "" echo "▶ Sauvegarde JH Photomaton..." JH_DIR="/home/pi/jh-photomaton" JH_ARCHIVE="$DEST/jh-photomaton-$DATE.tar.gz" if [ -d "$JH_DIR" ]; then tar -czf "$JH_ARCHIVE" \ -C "$JH_DIR" \ --exclude=".venv" \ --exclude="__pycache__" \ --exclude="*.pyc" \ "config/settings.yaml" \ "data/" \ 2>/dev/null && \ ok "JH Photomaton config → $(basename $JH_ARCHIVE)" || \ warn "JH Photomaton : sauvegarde partielle" else warn "JH Photomaton : $JH_DIR introuvable" fi # Config photobooth-app PB_CFG="/home/pi/.config/photobooth-app" PB_ARCHIVE="$DEST/photobooth-app-config-$DATE.tar.gz" if [ -d "$PB_CFG" ]; then tar -czf "$PB_ARCHIVE" "$PB_CFG" 2>/dev/null && \ ok "photobooth-app config → $(basename $PB_ARCHIVE)" || \ warn "Échec sauvegarde config photobooth-app" fi # ───────────────────────────────────────────────────────────────────────────── # 5. Résumé # ───────────────────────────────────────────────────────────────────────────── echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " Archives créées dans : $DEST" ls -lh "$DEST/"*"$DATE"* 2>/dev/null | awk '{print " " $NF " (" $5 ")"}' echo "" if [ $ERRORS -eq 0 ]; then ok "Sauvegarde terminée sans erreur." else err "$ERRORS erreur(s) durant la sauvegarde." fi echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"