diff --git a/Makefile b/Makefile index 813a3b6..340be3c 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ install: ## Installe Borgmatic et configure le système test-config: ## Valide la configuration Borgmatic @echo "$(BLUE)Validation de la configuration...$(NC)" - @validate-borgmatic-config || borgmatic --dry-run -v 0 + @borgmatic config validate test-notifications: ## Teste les notifications ntfy @echo "$(BLUE)Test des notifications ntfy...$(NC)" diff --git a/QUICKSTART.md b/QUICKSTART.md index 431b203..50520ac 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -2,18 +2,28 @@ Installation et configuration en 5 minutes. +**Version requise : Borgmatic ≥ 2.0.0** + ## Installation rapide ```bash -# 1. Cloner le dépôt (si pas déjà fait) +# 1. Installer Borgmatic 2.0+ (si pas déjà fait) +sudo apt install pipx +sudo pipx install borgmatic +sudo ln -sf /root/.local/bin/borgmatic /usr/local/bin/borgmatic + +# 2. Vérifier la version +borgmatic --version # Doit être ≥ 2.0.0 + +# 3. Cloner le dépôt (si pas déjà fait) git clone cd agence66-borgmatic -# 2. Configurer les variables d'environnement +# 4. Configurer les variables d'environnement cp .env.example .env nano .env # Éditer avec vos valeurs (voir ci-dessous) -# 3. Installer +# 5. Installer sudo ./install.sh ``` diff --git a/README.md b/README.md index fb145ea..1800f0f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Configuration Borgmatic pour le backup automatique du serveur Agence66. Ce dépôt contient la configuration complète pour effectuer des backups automatiques quotidiens à 3h du matin via Borgmatic et BorgBackup. +**Version Borgmatic requise : ≥ 2.0.0** (pour l'interpolation des variables d'environnement) + ### Caractéristiques - **Backup quotidien automatique** à 3h du matin via systemd timer @@ -40,6 +42,7 @@ Ce dépôt contient la configuration complète pour effectuer des backups automa - Système Linux (Debian/Ubuntu/Arch/Fedora) - Accès root - Git installé +- **Borgmatic ≥ 2.0.0** (pour l'interpolation des variables d'environnement) ### Installation rapide @@ -64,10 +67,18 @@ sudo ./install.sh Si vous préférez installer manuellement : ```bash -# Installer Borgmatic -sudo apt install borgbackup borgmatic # Debian/Ubuntu +# Installer Borgmatic ≥ 2.0.0 via pipx (recommandé) +sudo apt install pipx +sudo pipx install borgmatic + +# Créer les liens symboliques +sudo ln -sf /root/.local/bin/borgmatic /usr/local/bin/borgmatic +sudo ln -sf /root/.local/bin/generate-borgmatic-config /usr/local/bin/generate-borgmatic-config + +# Installer BorgBackup +sudo apt install borgbackup # Debian/Ubuntu # ou -sudo pacman -S borgmatic borg # Arch Linux +sudo pacman -S borg # Arch Linux # Copier les fichiers sudo mkdir -p /etc/borgmatic/hooks diff --git a/config.yaml b/config.yaml index f23639e..bd0de82 100644 --- a/config.yaml +++ b/config.yaml @@ -1,84 +1,84 @@ -# Configuration Borgmatic pour backup serveur Agence66 -# Compatible avec Borgmatic 1.7.7 +# Configuration Borgmatic 2.0 pour backup serveur Agence66 +# Compatible avec les backups Borg existants +# +# IMPORTANT: Nécessite Borgmatic ≥ 2.0.0 pour l'interpolation des variables d'environnement -location: - # Chemins sources à sauvegarder - source_directories: - - /var/www - - /srv/minecraftserver - - /srv/reddiscordbot - - /srv/waltercoiffure - - /etc - - /opt/nextcloud - - /opt/traefik - - /opt/n8n - - /opt/portainer - - /opt/uptime-kuma - - /opt/vaultwarden - - /opt/mailcow-dockerized - - /opt/netdata - - /opt/gitea - - /home +# Repository Borg - utilise la variable d'environnement +repositories: + - path: "{BORG_REPO}" + label: serveur - # Repository Borg depuis variable d'environnement - repositories: - - "{BORG_REPO}" +# Chemins sources à sauvegarder +source_directories: + - /var/www + - /srv/minecraftserver + - /srv/reddiscordbot + - /srv/waltercoiffure + - /etc + - /opt/nextcloud + - /opt/traefik + - /opt/n8n + - /opt/portainer + - /opt/uptime-kuma + - /opt/vaultwarden + - /opt/mailcow-dockerized + - /opt/netdata + - /opt/gitea + - /home - # Patterns d'exclusion - exclude_patterns: - - "*.log" - - "*/cache/*" - - "*/tmp/*" - - "**/__pycache__" - - "*/node_modules/*" +# Patterns d'exclusion +exclude_patterns: + - "*.log" + - "*/cache/*" + - "*/tmp/*" + - "**/__pycache__" + - "*/node_modules/*" - # Un seul système de fichiers - one_file_system: false +# Un seul système de fichiers +one_file_system: false -storage: - # Format du nom d'archive (compatible avec votre ancien script) - archive_name_format: "backup-{now:%Y%m%d-%H%M}" +# Format du nom d'archive (compatible avec votre ancien script) +archive_name_format: "backup-{now:%Y%m%d-%H%M}" - # Compression - compression: zstd +# Compression +compression: zstd - # Options SSH - ssh_command: ssh -o StrictHostKeyChecking=accept-new +# Options SSH +ssh_command: ssh -o StrictHostKeyChecking=accept-new -retention: - # Politique de rétention - keep_daily: 7 - keep_weekly: 4 - keep_monthly: 6 +# Politique de rétention +keep_daily: 7 +keep_weekly: 4 +keep_monthly: 6 - # Préfixe des archives - prefix: "backup-" +# Préfixe des archives +prefix: "backup-" -consistency: - # Vérifications d'intégrité - checks: - - name: repository - frequency: 2 weeks - - name: archives - frequency: 1 month +# Vérifications d'intégrité +checks: + - name: repository + frequency: 2 weeks + - name: archives + frequency: 1 month - # Fréquence des vérifications - check_last: 3 +# Nombre d'archives à vérifier +check_last: 3 -hooks: - # Hooks pour notifications ntfy - before_backup: - - echo "Backup démarré" +# Commandes/hooks pour notifications +before_actions: + - echo "Backup démarré" - after_backup: - - /etc/borgmatic/hooks/ntfy-success.sh "{archive_name}" "{stats}" +after_backup: + - echo "Exécution hook de succès" + - /etc/borgmatic/hooks/ntfy-success.sh "{archive_name}" "{stats}" - on_error: - - /etc/borgmatic/hooks/ntfy-error.sh "{error}" +on_error: + - echo "Exécution hook d'erreur" + - /etc/borgmatic/hooks/ntfy-error.sh "{error}" - # Commandes PostgreSQL/MySQL si nécessaire - # postgresql_databases: - # - name: all +# Commandes PostgreSQL/MySQL si nécessaire +# postgresql_databases: +# - name: all - # mysql_databases: - # - name: all +# mysql_databases: +# - name: all diff --git a/install.sh b/install.sh index 172a9e4..9f9ea6e 100755 --- a/install.sh +++ b/install.sh @@ -35,24 +35,82 @@ fi # 1. Installation de Borgmatic et Borg echo -e "${YELLOW}📦 Installation de Borgmatic et Borg...${NC}" -case $OS in - ubuntu|debian) - apt-get update - apt-get install -y borgbackup borgmatic curl - ;; - arch|manjaro) - pacman -Syu --noconfirm borgmatic borg curl - ;; - fedora|rhel|centos) - dnf install -y borgbackup borgmatic curl - ;; - *) - echo -e "${RED}❌ Distribution non supportée: $OS${NC}" - exit 1 - ;; -esac +# Vérifier si Borgmatic est déjà installé +if command -v borgmatic &> /dev/null; then + BORGMATIC_VERSION=$(borgmatic --version 2>&1 | grep -oP '\d+\.\d+\.\d+' | head -1) + MAJOR_VERSION=$(echo $BORGMATIC_VERSION | cut -d. -f1) -echo -e "${GREEN}✅ Borgmatic et Borg installés${NC}" + if [ "$MAJOR_VERSION" -lt 2 ]; then + echo -e "${YELLOW}⚠️ Borgmatic $BORGMATIC_VERSION détecté (version < 2.0)${NC}" + echo -e "${YELLOW} Cette configuration nécessite Borgmatic ≥ 2.0.0${NC}" + echo -e "${YELLOW} Installation via pipx recommandée...${NC}" + + # Installer pipx si pas déjà fait + case $OS in + ubuntu|debian) + apt-get update + apt-get install -y pipx + ;; + arch|manjaro) + pacman -Syu --noconfirm python-pipx + ;; + fedora|rhel|centos) + dnf install -y pipx + ;; + esac + + # Installer Borgmatic via pipx + pipx install borgmatic --force + + # Créer les liens symboliques + ln -sf /root/.local/bin/borgmatic /usr/local/bin/borgmatic + ln -sf /root/.local/bin/generate-borgmatic-config /usr/local/bin/generate-borgmatic-config + + echo -e "${GREEN}✅ Borgmatic 2.0+ installé via pipx${NC}" + else + echo -e "${GREEN}✅ Borgmatic $BORGMATIC_VERSION déjà installé${NC}" + fi +else + echo -e "${YELLOW}Installation de Borgmatic via pipx...${NC}" + + # Installer pipx + case $OS in + ubuntu|debian) + apt-get update + apt-get install -y pipx + ;; + arch|manjaro) + pacman -Syu --noconfirm python-pipx + ;; + fedora|rhel|centos) + dnf install -y pipx + ;; + esac + + # Installer Borgmatic + pipx install borgmatic + + # Créer les liens symboliques + ln -sf /root/.local/bin/borgmatic /usr/local/bin/borgmatic + ln -sf /root/.local/bin/generate-borgmatic-config /usr/local/bin/generate-borgmatic-config +fi + +# Installer Borg si pas déjà fait +if ! command -v borg &> /dev/null; then + case $OS in + ubuntu|debian) + apt-get install -y borgbackup curl + ;; + arch|manjaro) + pacman -Syu --noconfirm borg curl + ;; + fedora|rhel|centos) + dnf install -y borgbackup curl + ;; + esac +fi + +echo -e "${GREEN}✅ Installation terminée${NC}" # 2. Créer les répertoires nécessaires echo -e "${YELLOW}📁 Création des répertoires...${NC}" @@ -114,7 +172,7 @@ else fi # Test de la configuration (sans exécuter de backup) -if validate-borgmatic-config > /dev/null 2>&1; then +if borgmatic config validate > /dev/null 2>&1; then echo -e "${GREEN}✅ Configuration valide${NC}" else echo -e "${YELLOW}⚠️ Validation de la configuration...${NC}" diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index 65093d5..7ebee2d 100755 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -52,7 +52,7 @@ echo -e "${YELLOW}🔍 Vérification de la configuration...${NC}" if [ -f /etc/borgmatic/config.yaml ]; then echo -e "${GREEN}✅ Fichier de configuration trouvé${NC}" - if validate-borgmatic-config > /dev/null 2>&1; then + if borgmatic config validate > /dev/null 2>&1; then echo -e "${GREEN}✅ Configuration valide${NC}" else echo -e "${YELLOW}⚠️ Utilisez 'borgmatic --dry-run' pour tester${NC}"