Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
Update hook installation to use wildcard pattern instead of hardcoded file names, ensuring all current and future hooks are copied. Changes: - Replace individual cp commands with cp hooks/*.sh pattern - Automatically includes ntfy and uptime-kuma hooks - More maintainable for future hook additions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
211 lines
6.5 KiB
Bash
Executable File
211 lines
6.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Script d'installation de Borgmatic pour Agence66
|
|
# Usage: sudo ./install.sh
|
|
#
|
|
|
|
set -e
|
|
|
|
# Couleurs pour l'affichage
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${GREEN}==================================================${NC}"
|
|
echo -e "${GREEN}Installation de Borgmatic${NC}"
|
|
echo -e "${GREEN}==================================================${NC}"
|
|
echo ""
|
|
|
|
# Vérifier que le script est exécuté en root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo -e "${RED}❌ Ce script doit être exécuté en root (sudo)${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Détecter la distribution
|
|
if [ -f /etc/os-release ]; then
|
|
. /etc/os-release
|
|
OS=$ID
|
|
else
|
|
echo -e "${RED}❌ Impossible de détecter la distribution${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# 1. Installation de Borgmatic et Borg
|
|
echo -e "${YELLOW}📦 Installation de Borgmatic et Borg...${NC}"
|
|
|
|
# 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)
|
|
|
|
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}"
|
|
mkdir -p /etc/borgmatic
|
|
mkdir -p /etc/borgmatic/hooks
|
|
mkdir -p /var/log/borgmatic
|
|
|
|
echo -e "${GREEN}✅ Répertoires créés${NC}"
|
|
|
|
# 3. Copier les fichiers de configuration
|
|
echo -e "${YELLOW}📋 Copie des fichiers de configuration...${NC}"
|
|
|
|
# Config principale
|
|
cp config.yaml /etc/borgmatic/config.yaml
|
|
chmod 600 /etc/borgmatic/config.yaml
|
|
|
|
# Scripts de hooks - copier tous les fichiers .sh
|
|
cp hooks/*.sh /etc/borgmatic/hooks/
|
|
chmod +x /etc/borgmatic/hooks/*.sh
|
|
|
|
echo -e "${GREEN}✅ Fichiers de configuration copiés${NC}"
|
|
|
|
# 4. Configuration des variables d'environnement
|
|
echo -e "${YELLOW}🔐 Configuration des variables d'environnement...${NC}"
|
|
|
|
if [ -f .env ]; then
|
|
cp .env /etc/borgmatic/.env
|
|
chmod 600 /etc/borgmatic/.env
|
|
echo -e "${GREEN}✅ Fichier .env copié${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ Fichier .env non trouvé${NC}"
|
|
echo -e "${YELLOW} Copie du template .env.example...${NC}"
|
|
cp .env.example /etc/borgmatic/.env
|
|
chmod 600 /etc/borgmatic/.env
|
|
echo -e "${RED}⚠️ IMPORTANT: Éditez /etc/borgmatic/.env avec vos vraies valeurs !${NC}"
|
|
fi
|
|
|
|
# 5. Installation des services systemd
|
|
echo -e "${YELLOW}⚙️ Installation des services systemd...${NC}"
|
|
|
|
cp systemd/borgmatic.service /etc/systemd/system/
|
|
cp systemd/borgmatic.timer /etc/systemd/system/
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable borgmatic.timer
|
|
|
|
echo -e "${GREEN}✅ Services systemd installés et activés${NC}"
|
|
|
|
# 6. Vérification de la configuration
|
|
echo -e "${YELLOW}🔍 Validation de la configuration...${NC}"
|
|
|
|
if borgmatic --version > /dev/null 2>&1; then
|
|
echo -e "${GREEN}✅ Borgmatic est installé correctement${NC}"
|
|
borgmatic --version
|
|
else
|
|
echo -e "${RED}❌ Erreur: Borgmatic n'est pas installé correctement${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Test de la configuration (sans exécuter de backup)
|
|
if borgmatic config validate > /dev/null 2>&1; then
|
|
echo -e "${GREEN}✅ Configuration valide${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ Validation de la configuration...${NC}"
|
|
echo -e "${YELLOW} Testez avec: borgmatic --dry-run${NC}"
|
|
fi
|
|
|
|
# 7. Affichage des prochaines étapes
|
|
echo ""
|
|
echo -e "${GREEN}==================================================${NC}"
|
|
echo -e "${GREEN}✅ Installation terminée !${NC}"
|
|
echo -e "${GREEN}==================================================${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}📝 Prochaines étapes:${NC}"
|
|
echo ""
|
|
echo -e "1. Éditez les configurations:"
|
|
echo -e " - ${YELLOW}/etc/borgmatic/.env${NC} (variables d'environnement)"
|
|
echo -e " - ${YELLOW}/etc/borgmatic/config.yaml${NC} (configuration Borg)"
|
|
echo ""
|
|
echo -e "2. Initialisez votre repository Borg (si nouveau):"
|
|
echo -e " ${YELLOW}borg init --encryption=repokey-blake2 /path/to/repo${NC}"
|
|
echo ""
|
|
echo -e "3. Testez votre configuration:"
|
|
echo -e " ${YELLOW}borgmatic --dry-run --verbosity 2${NC}"
|
|
echo ""
|
|
echo -e "4. Exécutez un premier backup manuel:"
|
|
echo -e " ${YELLOW}borgmatic --verbosity 1${NC}"
|
|
echo ""
|
|
echo -e "5. Vérifiez le timer systemd:"
|
|
echo -e " ${YELLOW}systemctl status borgmatic.timer${NC}"
|
|
echo -e " ${YELLOW}systemctl list-timers | grep borgmatic${NC}"
|
|
echo ""
|
|
echo -e "6. Démarrez le timer:"
|
|
echo -e " ${YELLOW}systemctl start borgmatic.timer${NC}"
|
|
echo ""
|
|
echo -e "${GREEN}Le backup s'exécutera automatiquement tous les jours à 3h du matin${NC}"
|
|
echo ""
|