initial commit
This commit is contained in:
354
README.md
Normal file
354
README.md
Normal file
@@ -0,0 +1,354 @@
|
||||
# Borgmatic Backup - Agence66
|
||||
|
||||
Configuration Borgmatic pour le backup automatique du serveur Agence66.
|
||||
|
||||
## Vue d'ensemble
|
||||
|
||||
Ce dépôt contient la configuration complète pour effectuer des backups automatiques quotidiens à 3h du matin via Borgmatic et BorgBackup.
|
||||
|
||||
### Caractéristiques
|
||||
|
||||
- **Backup quotidien automatique** à 3h du matin via systemd timer
|
||||
- **Compression** zstd pour un bon ratio performance/compression
|
||||
- **Rétention intelligente** : 7 daily, 4 weekly, 6 monthly
|
||||
- **Notifications** via ntfy pour succès/échec
|
||||
- **Compatible** avec les backups Borg existants
|
||||
- **Sécurisé** : chiffrement, exclusions de fichiers sensibles
|
||||
|
||||
## Dossiers sauvegardés
|
||||
|
||||
- `/var/www` - Sites web
|
||||
- `/srv/minecraftserver` - Serveur Minecraft
|
||||
- `/srv/reddiscordbot` - Bot Discord
|
||||
- `/srv/waltercoiffure` - Walter Coiffure
|
||||
- `/etc` - Configurations système
|
||||
- `/opt/nextcloud` - Nextcloud
|
||||
- `/opt/traefik` - Reverse proxy Traefik
|
||||
- `/opt/n8n` - Automation n8n
|
||||
- `/opt/portainer` - Gestion Docker
|
||||
- `/opt/uptime-kuma` - Monitoring
|
||||
- `/opt/vaultwarden` - Gestionnaire de mots de passe
|
||||
- `/opt/mailcow-dockerized` - Serveur mail
|
||||
- `/opt/netdata` - Monitoring système
|
||||
- `/opt/gitea` - Forge Git
|
||||
- `/home` - Répertoires utilisateurs
|
||||
|
||||
## Installation
|
||||
|
||||
### Prérequis
|
||||
|
||||
- Système Linux (Debian/Ubuntu/Arch/Fedora)
|
||||
- Accès root
|
||||
- Git installé
|
||||
|
||||
### Installation rapide
|
||||
|
||||
```bash
|
||||
# Cloner le dépôt
|
||||
git clone <url-du-repo>
|
||||
cd agence66-borgmatic
|
||||
|
||||
# Copier et configurer les variables d'environnement
|
||||
cp .env.example .env
|
||||
nano .env # Éditer avec vos valeurs
|
||||
|
||||
# Éditer la configuration si nécessaire
|
||||
nano config.yaml # Ajuster le repository Borg
|
||||
|
||||
# Exécuter l'installation
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
### Configuration manuelle
|
||||
|
||||
Si vous préférez installer manuellement :
|
||||
|
||||
```bash
|
||||
# Installer Borgmatic
|
||||
sudo apt install borgbackup borgmatic # Debian/Ubuntu
|
||||
# ou
|
||||
sudo pacman -S borgmatic borg # Arch Linux
|
||||
|
||||
# Copier les fichiers
|
||||
sudo mkdir -p /etc/borgmatic/hooks
|
||||
sudo cp config.yaml /etc/borgmatic/
|
||||
sudo cp hooks/*.sh /etc/borgmatic/hooks/
|
||||
sudo chmod +x /etc/borgmatic/hooks/*.sh
|
||||
|
||||
# Copier les variables d'environnement
|
||||
sudo cp .env /etc/borgmatic/
|
||||
sudo chmod 600 /etc/borgmatic/.env
|
||||
|
||||
# Installer les services systemd
|
||||
sudo cp systemd/borgmatic.service /etc/systemd/system/
|
||||
sudo cp systemd/borgmatic.timer /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable borgmatic.timer
|
||||
sudo systemctl start borgmatic.timer
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Variables d'environnement (.env)
|
||||
|
||||
Éditez `/etc/borgmatic/.env` avec vos valeurs :
|
||||
|
||||
```bash
|
||||
# Repository Borg
|
||||
BORG_REPO=/path/to/your/repository
|
||||
# ou pour un repo distant:
|
||||
BORG_REPO=ssh://user@backup.server.com/path/to/repo
|
||||
|
||||
# Passphrase de chiffrement
|
||||
BORG_PASSPHRASE=your-secure-passphrase
|
||||
|
||||
# Configuration ntfy
|
||||
NTFY_URL=https://ntfy.sh/your-topic
|
||||
NTFY_USER=username:password
|
||||
```
|
||||
|
||||
### Configuration Borgmatic (config.yaml)
|
||||
|
||||
Le fichier `/etc/borgmatic/config.yaml` contient la configuration principale.
|
||||
|
||||
Points importants à vérifier :
|
||||
|
||||
1. **Repository** : Décommentez et configurez votre repository dans la section `location.repositories`
|
||||
2. **Chemins** : Ajustez `source_directories` si nécessaire
|
||||
3. **Exclusions** : Personnalisez `exclude_patterns` selon vos besoins
|
||||
|
||||
### Initialisation du repository Borg
|
||||
|
||||
Si vous utilisez un nouveau repository :
|
||||
|
||||
```bash
|
||||
# Repository local
|
||||
borg init --encryption=repokey-blake2 /path/to/repo
|
||||
|
||||
# Repository distant
|
||||
borg init --encryption=repokey-blake2 ssh://user@server/path/to/repo
|
||||
```
|
||||
|
||||
**IMPORTANT** : Sauvegardez la clé de chiffrement !
|
||||
|
||||
```bash
|
||||
borg key export /path/to/repo backup-key.txt
|
||||
# Conservez ce fichier en lieu sûr !
|
||||
```
|
||||
|
||||
## Utilisation
|
||||
|
||||
### Tester la configuration
|
||||
|
||||
```bash
|
||||
# Valider la configuration
|
||||
borgmatic config validate
|
||||
|
||||
# Dry-run (simulation)
|
||||
borgmatic --dry-run --verbosity 2
|
||||
|
||||
# Lister les fichiers qui seront sauvegardés
|
||||
borgmatic list --json
|
||||
```
|
||||
|
||||
### Exécuter un backup manuel
|
||||
|
||||
```bash
|
||||
# Backup avec verbosité normale
|
||||
sudo borgmatic --verbosity 1
|
||||
|
||||
# Backup avec verbosité détaillée
|
||||
sudo borgmatic --verbosity 2
|
||||
```
|
||||
|
||||
### Vérifier le timer systemd
|
||||
|
||||
```bash
|
||||
# Statut du timer
|
||||
systemctl status borgmatic.timer
|
||||
|
||||
# Voir quand le prochain backup aura lieu
|
||||
systemctl list-timers | grep borgmatic
|
||||
|
||||
# Logs du dernier backup
|
||||
journalctl -u borgmatic.service -n 100
|
||||
```
|
||||
|
||||
### Lister les backups
|
||||
|
||||
```bash
|
||||
# Lister toutes les archives
|
||||
borgmatic list
|
||||
|
||||
# Informations détaillées
|
||||
borg list /path/to/repo
|
||||
```
|
||||
|
||||
### Restaurer des fichiers
|
||||
|
||||
```bash
|
||||
# Monter une archive pour explorer
|
||||
mkdir /tmp/restore
|
||||
borg mount /path/to/repo::backup-20250116-0300 /tmp/restore
|
||||
cd /tmp/restore
|
||||
# ... copier les fichiers nécessaires ...
|
||||
cd /
|
||||
borg umount /tmp/restore
|
||||
|
||||
# Extraire directement
|
||||
borg extract /path/to/repo::backup-20250116-0300 path/to/file
|
||||
|
||||
# Avec borgmatic
|
||||
borgmatic extract --archive backup-20250116-0300 --path path/to/file
|
||||
```
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Vérifier l'intégrité
|
||||
|
||||
```bash
|
||||
# Vérification complète du repository
|
||||
borgmatic check --verbosity 2
|
||||
|
||||
# Vérification rapide
|
||||
borg check /path/to/repo
|
||||
```
|
||||
|
||||
### Nettoyer l'espace disque
|
||||
|
||||
Le nettoyage automatique (prune) est déjà configuré avec :
|
||||
|
||||
- 7 backups quotidiens
|
||||
- 4 backups hebdomadaires
|
||||
- 6 backups mensuels
|
||||
|
||||
Pour forcer un nettoyage manuel :
|
||||
|
||||
```bash
|
||||
borgmatic prune --verbosity 1
|
||||
```
|
||||
|
||||
### Compacter le repository
|
||||
|
||||
Pour libérer réellement l'espace disque après prune :
|
||||
|
||||
```bash
|
||||
borg compact /path/to/repo
|
||||
```
|
||||
|
||||
## Notifications
|
||||
|
||||
Les notifications sont envoyées via ntfy :
|
||||
|
||||
- ✅ **Succès** : notification normale avec le nom de l'archive
|
||||
- ❌ **Échec** : notification haute priorité avec le message d'erreur
|
||||
|
||||
Testez manuellement les notifications :
|
||||
|
||||
```bash
|
||||
# Test notification de succès
|
||||
/etc/borgmatic/hooks/ntfy-success.sh "test-archive" ""
|
||||
|
||||
# Test notification d'erreur
|
||||
/etc/borgmatic/hooks/ntfy-error.sh "Erreur de test"
|
||||
```
|
||||
|
||||
## Sécurité
|
||||
|
||||
- Les fichiers `.env` et les clés ne sont **jamais** commités (voir `.gitignore`)
|
||||
- Les permissions des fichiers sensibles sont restrictives (600)
|
||||
- Le service systemd utilise `ProtectSystem=strict`
|
||||
- Les logs sont dans le journal systemd, accessible uniquement en root
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Le backup ne démarre pas
|
||||
|
||||
```bash
|
||||
# Vérifier le timer
|
||||
systemctl status borgmatic.timer
|
||||
|
||||
# Vérifier le service
|
||||
systemctl status borgmatic.service
|
||||
|
||||
# Voir les logs
|
||||
journalctl -u borgmatic.service -f
|
||||
```
|
||||
|
||||
### Erreur de connexion au repository
|
||||
|
||||
```bash
|
||||
# Tester la connexion SSH (si distant)
|
||||
ssh user@backup-server
|
||||
|
||||
# Vérifier les variables d'environnement
|
||||
sudo cat /etc/borgmatic/.env
|
||||
|
||||
# Tester Borg directement
|
||||
sudo borg list $BORG_REPO
|
||||
```
|
||||
|
||||
### Problème de permissions
|
||||
|
||||
```bash
|
||||
# Vérifier les permissions des fichiers
|
||||
ls -la /etc/borgmatic/
|
||||
ls -la /etc/borgmatic/hooks/
|
||||
|
||||
# Corriger si nécessaire
|
||||
sudo chmod 600 /etc/borgmatic/.env
|
||||
sudo chmod 600 /etc/borgmatic/config.yaml
|
||||
sudo chmod +x /etc/borgmatic/hooks/*.sh
|
||||
```
|
||||
|
||||
### Notifications ntfy ne fonctionnent pas
|
||||
|
||||
```bash
|
||||
# Tester manuellement
|
||||
curl -u "$NTFY_USER" \
|
||||
-H "Title: Test" \
|
||||
-d "Message de test" \
|
||||
"$NTFY_URL"
|
||||
|
||||
# Vérifier les variables
|
||||
source /etc/borgmatic/.env
|
||||
echo $NTFY_URL
|
||||
echo $NTFY_USER
|
||||
```
|
||||
|
||||
## Migration depuis l'ancien script
|
||||
|
||||
Si vous migrez depuis l'ancien script Borg :
|
||||
|
||||
1. **Le repository existant est compatible** - pas besoin de réinitialiser
|
||||
2. **Les archives existantes restent accessibles**
|
||||
3. **Le format de nommage est identique** : `backup-YYYYMMDD-HHMM`
|
||||
4. **La rétention est la même** : 7/4/6
|
||||
|
||||
Pour vérifier la compatibilité :
|
||||
|
||||
```bash
|
||||
# Lister les anciennes archives
|
||||
borg list /path/to/existing/repo
|
||||
|
||||
# Tester avec borgmatic
|
||||
borgmatic list
|
||||
```
|
||||
|
||||
## Ressources
|
||||
|
||||
- [Documentation Borgmatic](https://torsion.org/borgmatic/)
|
||||
- [Documentation BorgBackup](https://borgbackup.readthedocs.io/)
|
||||
- [ntfy.sh](https://ntfy.sh/)
|
||||
|
||||
## Support
|
||||
|
||||
Pour tout problème :
|
||||
|
||||
1. Consultez la section Troubleshooting
|
||||
2. Vérifiez les logs : `journalctl -u borgmatic.service -n 100`
|
||||
3. Testez en mode verbeux : `borgmatic --verbosity 2`
|
||||
|
||||
## Licence
|
||||
|
||||
Configuration personnalisée pour Agence66.
|
||||
Reference in New Issue
Block a user