initial commit
This commit is contained in:
40
.env.example
Normal file
40
.env.example
Normal file
@@ -0,0 +1,40 @@
|
||||
# Configuration Borgmatic - Variables d'environnement
|
||||
# Copier ce fichier vers .env et remplir avec vos valeurs réelles
|
||||
|
||||
# ============================================
|
||||
# CONFIGURATION BORG
|
||||
# ============================================
|
||||
|
||||
# Passphrase de chiffrement Borg (si utilisé)
|
||||
BORG_PASSPHRASE=your-secure-passphrase-here
|
||||
|
||||
# Repository Borg
|
||||
# Exemples:
|
||||
# - Local: /mnt/backup/borg-repo
|
||||
# - Remote SSH: ssh://user@backup.example.com:22/path/to/repo
|
||||
# - BorgBase: ssh://xxxxx@xxxxx.repo.borgbase.com/./repo
|
||||
BORG_REPO=/path/to/borg/repository
|
||||
|
||||
# Clé SSH pour connexion au serveur de backup distant (si applicable)
|
||||
# BORG_RSH="ssh -i /root/.ssh/borg_backup_key"
|
||||
|
||||
# ============================================
|
||||
# NOTIFICATIONS NTFY
|
||||
# ============================================
|
||||
|
||||
# URL du serveur ntfy
|
||||
NTFY_URL=https://ntfy.sh/your-topic-name
|
||||
|
||||
# Authentification ntfy (format: username:password)
|
||||
# Laisser vide si pas d'authentification
|
||||
NTFY_USER=username:password
|
||||
|
||||
# ============================================
|
||||
# OPTIONS AVANCÉES
|
||||
# ============================================
|
||||
|
||||
# Niveau de log (0=minimal, 1=normal, 2=debug)
|
||||
BORGMATIC_LOG_LEVEL=1
|
||||
|
||||
# Désactiver les vérifications d'intégrité si nécessaire
|
||||
# BORGMATIC_SKIP_CHECKS=yes
|
||||
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
# Fichiers sensibles - NE JAMAIS COMMITER
|
||||
.env
|
||||
*.key
|
||||
*.pem
|
||||
*.ppk
|
||||
*_rsa
|
||||
*_ed25519
|
||||
passphrase.txt
|
||||
borg-key-*.txt
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
logs/
|
||||
|
||||
# Backups et dumps temporaires
|
||||
*.sql
|
||||
*.dump
|
||||
backup-*.tar.gz
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
*~
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Cache Python
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
|
||||
# Fichiers de test
|
||||
test-backup/
|
||||
.test/
|
||||
54
CHANGELOG.md
Normal file
54
CHANGELOG.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Changelog
|
||||
|
||||
Toutes les modifications notables de ce projet seront documentées dans ce fichier.
|
||||
|
||||
## [1.0.0] - 2025-12-16
|
||||
|
||||
### Ajouté
|
||||
|
||||
- Configuration Borgmatic complète compatible avec les backups Borg existants
|
||||
- Service et timer systemd pour exécution quotidienne à 3h du matin
|
||||
- Scripts de hooks pour notifications ntfy (succès et échec)
|
||||
- Script d'installation automatisé (`install.sh`)
|
||||
- Scripts utilitaires :
|
||||
- `scripts/restore.sh` : restauration interactive
|
||||
- `scripts/healthcheck.sh` : vérification de santé du système
|
||||
- `scripts/test-notifications.sh` : test des notifications ntfy
|
||||
- Documentation complète :
|
||||
- `README.md` : documentation principale
|
||||
- `QUICKSTART.md` : guide de démarrage rapide
|
||||
- `TODO.md` : améliorations futures
|
||||
- Configuration des exclusions (logs, cache, tmp)
|
||||
- Politique de rétention : 7 daily, 4 weekly, 6 monthly
|
||||
- Compression zstd
|
||||
- Template `.env.example` pour variables d'environnement
|
||||
- `.gitignore` pour éviter de commiter les secrets
|
||||
|
||||
### Chemins sauvegardés
|
||||
|
||||
- `/var/www` - Sites web
|
||||
- `/srv/minecraftserver` - Serveur Minecraft
|
||||
- `/srv/reddiscordbot` - Bot Discord
|
||||
- `/srv/waltercoiffure` - Application 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
|
||||
|
||||
### Compatibilité
|
||||
|
||||
- Compatible avec les archives Borg existantes
|
||||
- Même format de nommage : `backup-YYYYMMDD-HHMM`
|
||||
- Même politique de rétention que l'ancien script
|
||||
- Migration transparente depuis l'ancien script Bash
|
||||
|
||||
## [À venir]
|
||||
|
||||
Voir [TODO.md](TODO.md) pour la liste complète des améliorations prévues.
|
||||
135
Makefile
Normal file
135
Makefile
Normal file
@@ -0,0 +1,135 @@
|
||||
# Makefile pour Borgmatic - Agence66
|
||||
# Usage: make [commande]
|
||||
|
||||
.PHONY: help install test backup list restore healthcheck logs status clean
|
||||
|
||||
# Couleurs pour l'affichage
|
||||
BLUE := \033[0;34m
|
||||
GREEN := \033[0;32m
|
||||
YELLOW := \033[1;33m
|
||||
NC := \033[0m
|
||||
|
||||
help: ## Affiche cette aide
|
||||
@echo "$(BLUE)Borgmatic - Agence66$(NC)"
|
||||
@echo ""
|
||||
@echo "$(YELLOW)Commandes disponibles:$(NC)"
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
|
||||
|
||||
install: ## Installe Borgmatic et configure le système
|
||||
@echo "$(BLUE)Installation de Borgmatic...$(NC)"
|
||||
sudo ./install.sh
|
||||
|
||||
test-config: ## Valide la configuration Borgmatic
|
||||
@echo "$(BLUE)Validation de la configuration...$(NC)"
|
||||
borgmatic config validate
|
||||
|
||||
test-notifications: ## Teste les notifications ntfy
|
||||
@echo "$(BLUE)Test des notifications ntfy...$(NC)"
|
||||
./scripts/test-notifications.sh
|
||||
|
||||
healthcheck: ## Vérifie la santé du système de backup
|
||||
@echo "$(BLUE)Vérification de la santé du système...$(NC)"
|
||||
sudo ./scripts/healthcheck.sh
|
||||
|
||||
dry-run: ## Simule un backup sans l'exécuter
|
||||
@echo "$(BLUE)Simulation du backup (dry-run)...$(NC)"
|
||||
sudo borgmatic --dry-run --verbosity 2
|
||||
|
||||
backup: ## Exécute un backup manuel
|
||||
@echo "$(BLUE)Exécution du backup...$(NC)"
|
||||
sudo borgmatic --verbosity 1 --stats
|
||||
|
||||
backup-verbose: ## Exécute un backup manuel avec détails
|
||||
@echo "$(BLUE)Exécution du backup (mode verbeux)...$(NC)"
|
||||
sudo borgmatic --verbosity 2 --stats --list
|
||||
|
||||
list: ## Liste toutes les archives de backup
|
||||
@echo "$(BLUE)Archives disponibles:$(NC)"
|
||||
@borgmatic list
|
||||
|
||||
list-files: ## Liste les fichiers de la dernière archive
|
||||
@echo "$(BLUE)Fichiers de la dernière archive:$(NC)"
|
||||
@borgmatic list --archive latest
|
||||
|
||||
info: ## Affiche les informations sur le repository
|
||||
@echo "$(BLUE)Informations sur le repository:$(NC)"
|
||||
@borgmatic info
|
||||
|
||||
restore: ## Lance le script de restauration interactive
|
||||
@echo "$(BLUE)Restauration interactive...$(NC)"
|
||||
sudo ./scripts/restore.sh
|
||||
|
||||
check: ## Vérifie l'intégrité du repository et des archives
|
||||
@echo "$(BLUE)Vérification de l'intégrité...$(NC)"
|
||||
sudo borgmatic check --verbosity 1
|
||||
|
||||
prune: ## Nettoie les anciennes archives selon la politique de rétention
|
||||
@echo "$(YELLOW)Nettoyage des anciennes archives...$(NC)"
|
||||
sudo borgmatic prune --verbosity 1
|
||||
|
||||
compact: ## Compacte le repository pour libérer de l'espace
|
||||
@echo "$(YELLOW)Compactage du repository...$(NC)"
|
||||
sudo borg compact $(BORG_REPO)
|
||||
|
||||
status: ## Affiche le statut du timer systemd
|
||||
@echo "$(BLUE)Statut du timer Borgmatic:$(NC)"
|
||||
@systemctl status borgmatic.timer --no-pager
|
||||
@echo ""
|
||||
@echo "$(BLUE)Prochaines exécutions:$(NC)"
|
||||
@systemctl list-timers | grep borgmatic
|
||||
|
||||
logs: ## Affiche les logs du service
|
||||
@echo "$(BLUE)Logs du service Borgmatic:$(NC)"
|
||||
journalctl -u borgmatic.service -n 50 --no-pager
|
||||
|
||||
logs-follow: ## Suit les logs en temps réel
|
||||
@echo "$(BLUE)Logs en temps réel (Ctrl+C pour arrêter):$(NC)"
|
||||
journalctl -u borgmatic.service -f
|
||||
|
||||
enable: ## Active et démarre le timer systemd
|
||||
@echo "$(GREEN)Activation du timer...$(NC)"
|
||||
sudo systemctl enable borgmatic.timer
|
||||
sudo systemctl start borgmatic.timer
|
||||
@echo "$(GREEN)Timer activé !$(NC)"
|
||||
|
||||
disable: ## Désactive le timer systemd
|
||||
@echo "$(YELLOW)Désactivation du timer...$(NC)"
|
||||
sudo systemctl disable borgmatic.timer
|
||||
sudo systemctl stop borgmatic.timer
|
||||
@echo "$(YELLOW)Timer désactivé$(NC)"
|
||||
|
||||
restart-timer: ## Redémarre le timer systemd
|
||||
@echo "$(BLUE)Redémarrage du timer...$(NC)"
|
||||
sudo systemctl restart borgmatic.timer
|
||||
@systemctl status borgmatic.timer --no-pager
|
||||
|
||||
env-example: ## Affiche un exemple de fichier .env
|
||||
@cat .env.example
|
||||
|
||||
edit-config: ## Édite la configuration Borgmatic
|
||||
@sudo nano /etc/borgmatic/config.yaml
|
||||
|
||||
edit-env: ## Édite les variables d'environnement
|
||||
@sudo nano /etc/borgmatic/.env
|
||||
|
||||
clean: ## Nettoie les fichiers temporaires
|
||||
@echo "$(YELLOW)Nettoyage...$(NC)"
|
||||
@rm -f *.log
|
||||
@rm -rf restore/ restore-*/
|
||||
@echo "$(GREEN)Nettoyage terminé$(NC)"
|
||||
|
||||
quick-setup: ## Configuration rapide (copie .env.example vers .env)
|
||||
@if [ ! -f .env ]; then \
|
||||
echo "$(BLUE)Création du fichier .env...$(NC)"; \
|
||||
cp .env.example .env; \
|
||||
echo "$(GREEN)Fichier .env créé !$(NC)"; \
|
||||
echo "$(YELLOW)Éditez maintenant .env avec vos vraies valeurs:$(NC)"; \
|
||||
echo " nano .env"; \
|
||||
else \
|
||||
echo "$(YELLOW)Le fichier .env existe déjà$(NC)"; \
|
||||
fi
|
||||
|
||||
# Alias pratiques
|
||||
backup-now: backup ## Alias pour 'backup'
|
||||
ls: list ## Alias pour 'list'
|
||||
check-health: healthcheck ## Alias pour 'healthcheck'
|
||||
148
QUICKSTART.md
Normal file
148
QUICKSTART.md
Normal file
@@ -0,0 +1,148 @@
|
||||
# Guide de démarrage rapide - Borgmatic
|
||||
|
||||
Installation et configuration en 5 minutes.
|
||||
|
||||
## Installation rapide
|
||||
|
||||
```bash
|
||||
# 1. Cloner le dépôt (si pas déjà fait)
|
||||
git clone <url-du-repo>
|
||||
cd agence66-borgmatic
|
||||
|
||||
# 2. Configurer les variables d'environnement
|
||||
cp .env.example .env
|
||||
nano .env # Éditer avec vos valeurs (voir ci-dessous)
|
||||
|
||||
# 3. Installer
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
## Configuration .env
|
||||
|
||||
Éditez `.env` avec vos valeurs :
|
||||
|
||||
```bash
|
||||
# Repository Borg
|
||||
BORG_REPO=/chemin/vers/votre/repo
|
||||
# ou pour un repo distant:
|
||||
# BORG_REPO=ssh://user@backup-server.com/path/to/repo
|
||||
|
||||
# Passphrase de chiffrement
|
||||
BORG_PASSPHRASE=votre-passphrase-securisee
|
||||
|
||||
# Notifications ntfy
|
||||
NTFY_URL=https://ntfy.sh/votre-topic
|
||||
NTFY_USER=username:password
|
||||
```
|
||||
|
||||
## Initialiser le repository (si nouveau)
|
||||
|
||||
```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: Sauvegarder la clé !
|
||||
borg key export /path/to/repo backup-key.txt
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
# 1. Tester les notifications
|
||||
./scripts/test-notifications.sh
|
||||
|
||||
# 2. Vérifier la santé du système
|
||||
sudo ./scripts/healthcheck.sh
|
||||
|
||||
# 3. Test à vide (dry-run)
|
||||
sudo borgmatic --dry-run --verbosity 2
|
||||
|
||||
# 4. Premier backup réel
|
||||
sudo borgmatic --verbosity 1
|
||||
```
|
||||
|
||||
## Vérifier le timer
|
||||
|
||||
```bash
|
||||
# Vérifier que le timer est actif
|
||||
systemctl status borgmatic.timer
|
||||
|
||||
# Voir quand le prochain backup aura lieu
|
||||
systemctl list-timers | grep borgmatic
|
||||
```
|
||||
|
||||
## Commandes utiles
|
||||
|
||||
```bash
|
||||
# Lister les backups
|
||||
borgmatic list
|
||||
|
||||
# Voir les logs
|
||||
journalctl -u borgmatic.service -f
|
||||
|
||||
# Exécuter un backup manuel
|
||||
sudo borgmatic
|
||||
|
||||
# Restaurer des fichiers
|
||||
./scripts/restore.sh
|
||||
|
||||
# Vérifier l'intégrité
|
||||
sudo borgmatic check
|
||||
```
|
||||
|
||||
## Compatibilité avec ancien script
|
||||
|
||||
Si vous migriez depuis l'ancien script Borg :
|
||||
|
||||
1. Votre repository existant **est compatible**
|
||||
2. Les archives existantes **restent accessibles**
|
||||
3. Le format de nommage **est identique**
|
||||
4. Aucune migration n'est nécessaire
|
||||
|
||||
Pour vérifier :
|
||||
|
||||
```bash
|
||||
# Lister les anciennes archives
|
||||
borg list $BORG_REPO
|
||||
|
||||
# Tester avec borgmatic
|
||||
borgmatic list
|
||||
```
|
||||
|
||||
## Migration depuis ancien repository
|
||||
|
||||
Si vous avez un repository Borg existant, il suffit de :
|
||||
|
||||
```bash
|
||||
# 1. Pointer BORG_REPO vers votre repository existant dans .env
|
||||
BORG_REPO=/path/to/existing/repo
|
||||
|
||||
# 2. Utiliser la même passphrase
|
||||
BORG_PASSPHRASE=votre-ancienne-passphrase
|
||||
|
||||
# 3. Tester
|
||||
borgmatic list # Devrait afficher vos anciennes archives
|
||||
```
|
||||
|
||||
## En cas de problème
|
||||
|
||||
```bash
|
||||
# Vérifier la santé
|
||||
sudo ./scripts/healthcheck.sh
|
||||
|
||||
# Voir les logs
|
||||
journalctl -u borgmatic.service -n 50
|
||||
|
||||
# Tester la configuration
|
||||
borgmatic config validate
|
||||
|
||||
# Mode verbeux
|
||||
sudo borgmatic --verbosity 2
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Consultez le [README.md](README.md) pour plus de détails.
|
||||
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.
|
||||
109
TODO.md
Normal file
109
TODO.md
Normal file
@@ -0,0 +1,109 @@
|
||||
# TODO - Améliorations futures
|
||||
|
||||
## Priorité haute
|
||||
|
||||
- [ ] Configurer le repository Borg réel (local ou distant)
|
||||
- [ ] Renseigner les vraies valeurs dans `/etc/borgmatic/.env`
|
||||
- [ ] Tester le premier backup complet
|
||||
- [ ] Vérifier que les notifications ntfy fonctionnent
|
||||
- [ ] Documenter la passphrase et sauvegarder la clé Borg
|
||||
|
||||
## Priorité moyenne
|
||||
|
||||
- [ ] Configurer un backup du repository Borg lui-même (offsite)
|
||||
- [ ] Mettre en place un monitoring externe (healthchecks.io ou similaire)
|
||||
- [ ] Ajouter des hooks PostgreSQL/MySQL si nécessaire
|
||||
- [ ] Configurer des alertes en cas d'échec de backup
|
||||
- [ ] Tester une restauration complète sur un système de test
|
||||
|
||||
## Améliorations possibles
|
||||
|
||||
### Monitoring et alertes
|
||||
|
||||
- [ ] Intégration avec healthchecks.io pour monitoring externe
|
||||
- [ ] Dashboard Grafana pour visualiser l'historique des backups
|
||||
- [ ] Alertes par email en plus de ntfy
|
||||
- [ ] Métriques Prometheus pour le monitoring
|
||||
|
||||
### Sécurité
|
||||
|
||||
- [ ] Rotation automatique des clés de chiffrement
|
||||
- [ ] Audit des permissions des fichiers de configuration
|
||||
- [ ] Backup de la clé Borg dans un gestionnaire de secrets (Vaultwarden)
|
||||
- [ ] Authentification SSH avec clés dédiées
|
||||
|
||||
### Performance
|
||||
|
||||
- [ ] Optimiser les patterns d'exclusion
|
||||
- [ ] Ajouter des exclusions pour les caches Docker
|
||||
- [ ] Tester différents algorithmes de compression
|
||||
- [ ] Parallélisation des backups si plusieurs destinations
|
||||
|
||||
### Backups de bases de données
|
||||
|
||||
- [ ] Hook pre-backup pour PostgreSQL (si Gitea/autres utilisent PG)
|
||||
- [ ] Hook pre-backup pour MySQL/MariaDB (si utilisé)
|
||||
- [ ] Hook pre-backup pour dump des conteneurs Docker
|
||||
- [ ] Backup des volumes Docker critiques
|
||||
|
||||
### Restauration
|
||||
|
||||
- [ ] Documenter la procédure de disaster recovery complète
|
||||
- [ ] Script de restauration automatisée sur nouveau serveur
|
||||
- [ ] Tester régulièrement la restauration (tous les 3 mois)
|
||||
- [ ] Documenter la restauration sélective par service
|
||||
|
||||
### Documentation
|
||||
|
||||
- [ ] Vidéo tutoriel pour la restauration
|
||||
- [ ] Runbook pour les situations d'urgence
|
||||
- [ ] Documentation de l'architecture de backup
|
||||
- [ ] Guide de migration vers nouveau serveur
|
||||
|
||||
### Testing
|
||||
|
||||
- [ ] Tests automatisés de la configuration
|
||||
- [ ] Simulation d'échec et vérification des alertes
|
||||
- [ ] Test de restauration automatisé
|
||||
- [ ] CI/CD pour valider les modifications de config
|
||||
|
||||
## Notes
|
||||
|
||||
### Services à considérer pour backup séparé
|
||||
|
||||
Certains services pourraient nécessiter des stratégies de backup spécifiques :
|
||||
|
||||
- **Nextcloud** : dump de la base de données avant backup
|
||||
- **Mailcow** : backup des emails et configuration
|
||||
- **Gitea** : dump de la base de données Git
|
||||
- **Vaultwarden** : backup critique à vérifier régulièrement
|
||||
|
||||
### Optimisations d'exclusion
|
||||
|
||||
Ajouter ces exclusions si nécessaire :
|
||||
```yaml
|
||||
- '*/venv/*'
|
||||
- '*/env/*'
|
||||
- '*/.git/objects/*' # Si backup de repos Git
|
||||
- '*/docker/overlay2/*'
|
||||
- '*/docker/volumes/*' # Déjà géré par les apps
|
||||
```
|
||||
|
||||
### Backup offsite
|
||||
|
||||
Considérer :
|
||||
- BorgBase (service cloud spécialisé Borg)
|
||||
- Serveur distant dédié
|
||||
- Stockage cloud chiffré (S3, Backblaze B2)
|
||||
- Rclone pour copier vers le cloud après backup Borg
|
||||
|
||||
### Rotation et rétention
|
||||
|
||||
Configuration actuelle :
|
||||
- 7 daily (1 semaine)
|
||||
- 4 weekly (1 mois)
|
||||
- 6 monthly (6 mois)
|
||||
|
||||
Considérer :
|
||||
- Ajouter `keep_yearly: 2` pour archives annuelles
|
||||
- Ajuster selon l'espace disque disponible
|
||||
108
config.yaml
Normal file
108
config.yaml
Normal file
@@ -0,0 +1,108 @@
|
||||
# Configuration Borgmatic pour backup serveur Agence66
|
||||
# Compatible avec les backups Borg existants
|
||||
|
||||
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 (à définir selon votre configuration)
|
||||
# Décommentez et adaptez selon votre setup :
|
||||
# repositories:
|
||||
# - /path/to/local/repo
|
||||
# - ssh://user@backup-server/path/to/repo
|
||||
|
||||
# Patterns d'exclusion
|
||||
exclude_patterns:
|
||||
- '*.log'
|
||||
- '*/cache/*'
|
||||
- '*/tmp/*'
|
||||
- '**/__pycache__'
|
||||
- '*/node_modules/*'
|
||||
|
||||
# Un seul fichier de config
|
||||
one_file_system: false
|
||||
|
||||
storage:
|
||||
# Format du nom d'archive (compatible avec votre format actuel)
|
||||
archive_name_format: 'backup-{now:%Y%m%d-%H%M}'
|
||||
|
||||
# Compression (identique à votre config)
|
||||
compression: zstd
|
||||
|
||||
# Chiffrement - décommentez et configurez si nécessaire
|
||||
# encryption_passphrase: sera lu depuis la variable d'environnement BORG_PASSPHRASE
|
||||
|
||||
# Vérification de l'intégrité du repo
|
||||
check_last: 3
|
||||
|
||||
# Options supplémentaires
|
||||
ssh_command: ssh -o StrictHostKeyChecking=accept-new
|
||||
|
||||
retention:
|
||||
# Politique de rétention (identique à votre config)
|
||||
keep_daily: 7
|
||||
keep_weekly: 4
|
||||
keep_monthly: 6
|
||||
|
||||
# Préfixe des archives à considérer
|
||||
prefix: 'backup-'
|
||||
|
||||
consistency:
|
||||
# Vérifications d'intégrité
|
||||
checks:
|
||||
- name: repository
|
||||
frequency: 2 weeks
|
||||
- name: archives
|
||||
frequency: 1 month
|
||||
|
||||
# Vérifier uniquement les dernières archives pour économiser du temps
|
||||
check_last: 3
|
||||
|
||||
hooks:
|
||||
# Hooks pour notifications ntfy
|
||||
before_backup:
|
||||
- echo "Backup démarré: $(date)"
|
||||
|
||||
after_backup:
|
||||
- /etc/borgmatic/hooks/ntfy-success.sh "{archive_name}" "{stats}"
|
||||
|
||||
on_error:
|
||||
- /etc/borgmatic/hooks/ntfy-error.sh "{error}"
|
||||
|
||||
# Actions avant/après
|
||||
before_actions:
|
||||
- systemctl is-active docker || systemctl start docker
|
||||
|
||||
# Commandes PostgreSQL/MySQL si nécessaire
|
||||
# postgresql_databases:
|
||||
# - name: all
|
||||
# format: custom
|
||||
|
||||
# mysql_databases:
|
||||
# - name: all
|
||||
# format: sql
|
||||
|
||||
output:
|
||||
# Niveau de verbosité (0 = minimal, 1 = normal, 2 = verbeux)
|
||||
verbosity: 1
|
||||
|
||||
# Afficher les statistiques
|
||||
stats: true
|
||||
|
||||
# Envoyer les logs vers syslog
|
||||
syslog_facility: LOG_USER
|
||||
26
hooks/ntfy-error.sh
Executable file
26
hooks/ntfy-error.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Hook Borgmatic - Notification d'erreur via ntfy
|
||||
# Arguments: $1 = error message
|
||||
#
|
||||
|
||||
# Charger les variables d'environnement
|
||||
if [ -f /etc/borgmatic/.env ]; then
|
||||
source /etc/borgmatic/.env
|
||||
fi
|
||||
|
||||
ERROR_MSG="${1:-Erreur inconnue}"
|
||||
|
||||
# Envoyer notification d'erreur
|
||||
curl -s -u "$NTFY_USER" \
|
||||
-H "Title: ❌ Backup échoué" \
|
||||
-H "Priority: high" \
|
||||
-H "Tags: x,backup,alert" \
|
||||
-d "Le backup a échoué !
|
||||
Erreur: ${ERROR_MSG}
|
||||
Date: $(date '+%Y-%m-%d %H:%M:%S')
|
||||
Vérifiez les logs: journalctl -u borgmatic.service -n 50" \
|
||||
"$NTFY_URL"
|
||||
|
||||
echo "Notification d'erreur envoyée à ntfy"
|
||||
exit 0
|
||||
30
hooks/ntfy-success.sh
Executable file
30
hooks/ntfy-success.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Hook Borgmatic - Notification de succès via ntfy
|
||||
# Arguments: $1 = archive_name, $2 = stats
|
||||
#
|
||||
|
||||
# Charger les variables d'environnement
|
||||
if [ -f /etc/borgmatic/.env ]; then
|
||||
source /etc/borgmatic/.env
|
||||
fi
|
||||
|
||||
ARCHIVE_NAME="${1:-inconnu}"
|
||||
STATS="${2:-}"
|
||||
|
||||
# Extraire la taille depuis les stats si disponible
|
||||
# Borgmatic passe les stats en JSON, on peut parser ou utiliser directement
|
||||
SIZE="voir logs pour détails"
|
||||
|
||||
# Envoyer notification de succès
|
||||
curl -s -u "$NTFY_USER" \
|
||||
-H "Title: ✅ Backup réussi" \
|
||||
-H "Priority: default" \
|
||||
-H "Tags: white_check_mark,backup" \
|
||||
-d "Backup terminé avec succès.
|
||||
Archive: ${ARCHIVE_NAME}
|
||||
Date: $(date '+%Y-%m-%d %H:%M:%S')" \
|
||||
"$NTFY_URL"
|
||||
|
||||
echo "Notification de succès envoyée à ntfy"
|
||||
exit 0
|
||||
153
install.sh
Executable file
153
install.sh
Executable file
@@ -0,0 +1,153 @@
|
||||
#!/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 - Agence66${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}"
|
||||
|
||||
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
|
||||
|
||||
echo -e "${GREEN}✅ Borgmatic et Borg installés${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
|
||||
cp hooks/ntfy-success.sh /etc/borgmatic/hooks/
|
||||
cp hooks/ntfy-error.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}⚠️ La configuration nécessite des ajustements${NC}"
|
||||
echo -e "${YELLOW} Vérifiez /etc/borgmatic/config.yaml${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 "1. Éditez les configurations:"
|
||||
echo " - ${YELLOW}/etc/borgmatic/.env${NC} (variables d'environnement)"
|
||||
echo " - ${YELLOW}/etc/borgmatic/config.yaml${NC} (configuration Borg)"
|
||||
echo ""
|
||||
echo "2. Initialisez votre repository Borg (si nouveau):"
|
||||
echo " ${YELLOW}borg init --encryption=repokey-blake2 /path/to/repo${NC}"
|
||||
echo ""
|
||||
echo "3. Testez votre configuration:"
|
||||
echo " ${YELLOW}borgmatic --dry-run --verbosity 2${NC}"
|
||||
echo ""
|
||||
echo "4. Exécutez un premier backup manuel:"
|
||||
echo " ${YELLOW}borgmatic --verbosity 1${NC}"
|
||||
echo ""
|
||||
echo "5. Vérifiez le timer systemd:"
|
||||
echo " ${YELLOW}systemctl status borgmatic.timer${NC}"
|
||||
echo " ${YELLOW}systemctl list-timers | grep borgmatic${NC}"
|
||||
echo ""
|
||||
echo "6. Démarrez le timer:"
|
||||
echo " ${YELLOW}systemctl start borgmatic.timer${NC}"
|
||||
echo ""
|
||||
echo -e "${GREEN}Le backup s'exécutera automatiquement tous les jours à 3h du matin${NC}"
|
||||
echo ""
|
||||
221
scripts/healthcheck.sh
Executable file
221
scripts/healthcheck.sh
Executable file
@@ -0,0 +1,221 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Script de vérification de santé des backups Borgmatic
|
||||
# Usage: ./healthcheck.sh
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
# Couleurs
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Charger les variables d'environnement
|
||||
if [ -f /etc/borgmatic/.env ]; then
|
||||
source /etc/borgmatic/.env
|
||||
elif [ -f .env ]; then
|
||||
source .env
|
||||
fi
|
||||
|
||||
ERRORS=0
|
||||
WARNINGS=0
|
||||
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
echo -e "${BLUE}Healthcheck Borgmatic - Agence66${NC}"
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
echo ""
|
||||
|
||||
# 1. Vérifier que Borgmatic est installé
|
||||
echo -e "${YELLOW}🔍 Vérification de l'installation...${NC}"
|
||||
if command -v borgmatic &> /dev/null; then
|
||||
VERSION=$(borgmatic --version 2>&1 | head -1)
|
||||
echo -e "${GREEN}✅ Borgmatic installé: ${VERSION}${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Borgmatic n'est pas installé${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
|
||||
if command -v borg &> /dev/null; then
|
||||
VERSION=$(borg --version)
|
||||
echo -e "${GREEN}✅ Borg installé: ${VERSION}${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Borg n'est pas installé${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 2. Vérifier la configuration
|
||||
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 borgmatic config validate > /dev/null 2>&1; then
|
||||
echo -e "${GREEN}✅ Configuration valide${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Configuration invalide${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}❌ Fichier de configuration non trouvé${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
|
||||
if [ -f /etc/borgmatic/.env ]; then
|
||||
echo -e "${GREEN}✅ Fichier .env trouvé${NC}"
|
||||
|
||||
# Vérifier les variables essentielles
|
||||
if [ -z "$BORG_REPO" ]; then
|
||||
echo -e "${RED}❌ BORG_REPO non défini${NC}"
|
||||
((ERRORS++))
|
||||
else
|
||||
echo -e "${GREEN}✅ BORG_REPO défini${NC}"
|
||||
fi
|
||||
|
||||
if [ -z "$NTFY_URL" ]; then
|
||||
echo -e "${YELLOW}⚠️ NTFY_URL non défini (notifications désactivées)${NC}"
|
||||
((WARNINGS++))
|
||||
else
|
||||
echo -e "${GREEN}✅ NTFY_URL défini${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}❌ Fichier .env non trouvé${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 3. Vérifier les services systemd
|
||||
echo -e "${YELLOW}🔍 Vérification des services systemd...${NC}"
|
||||
if systemctl is-enabled borgmatic.timer &> /dev/null; then
|
||||
echo -e "${GREEN}✅ Timer borgmatic activé${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Timer borgmatic non activé${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
|
||||
if systemctl is-active borgmatic.timer &> /dev/null; then
|
||||
echo -e "${GREEN}✅ Timer borgmatic en cours d'exécution${NC}"
|
||||
|
||||
# Afficher la prochaine exécution
|
||||
NEXT=$(systemctl list-timers | grep borgmatic | awk '{print $1, $2, $3, $4}')
|
||||
if [ -n "$NEXT" ]; then
|
||||
echo -e "${BLUE} Prochaine exécution: ${NEXT}${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Timer borgmatic arrêté${NC}"
|
||||
((WARNINGS++))
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 4. Vérifier le repository
|
||||
if [ -n "$BORG_REPO" ]; then
|
||||
echo -e "${YELLOW}🔍 Vérification du repository...${NC}"
|
||||
|
||||
if borg info "$BORG_REPO" &> /dev/null; then
|
||||
echo -e "${GREEN}✅ Repository accessible${NC}"
|
||||
|
||||
# Informations sur le repository
|
||||
REPO_INFO=$(borg info "$BORG_REPO" 2>&1 || true)
|
||||
|
||||
# Nombre d'archives
|
||||
ARCHIVE_COUNT=$(borg list "$BORG_REPO" --short 2>/dev/null | wc -l)
|
||||
echo -e "${BLUE} Nombre d'archives: ${ARCHIVE_COUNT}${NC}"
|
||||
|
||||
if [ "$ARCHIVE_COUNT" -eq 0 ]; then
|
||||
echo -e "${YELLOW}⚠️ Aucune archive trouvée (repository vide)${NC}"
|
||||
((WARNINGS++))
|
||||
else
|
||||
# Dernière archive
|
||||
LAST_ARCHIVE=$(borg list "$BORG_REPO" --short 2>/dev/null | tail -1)
|
||||
echo -e "${BLUE} Dernière archive: ${LAST_ARCHIVE}${NC}"
|
||||
|
||||
# Vérifier l'âge de la dernière archive
|
||||
LAST_DATE=$(echo "$LAST_ARCHIVE" | grep -oP '\d{8}-\d{4}' || echo "")
|
||||
if [ -n "$LAST_DATE" ]; then
|
||||
LAST_TIMESTAMP=$(date -d "${LAST_DATE:0:8} ${LAST_DATE:9:2}:${LAST_DATE:11:2}" +%s 2>/dev/null || echo "0")
|
||||
NOW=$(date +%s)
|
||||
AGE_HOURS=$(( (NOW - LAST_TIMESTAMP) / 3600 ))
|
||||
|
||||
echo -e "${BLUE} Âge de la dernière archive: ${AGE_HOURS}h${NC}"
|
||||
|
||||
if [ "$AGE_HOURS" -gt 48 ]; then
|
||||
echo -e "${RED}❌ Dernière archive trop ancienne (>48h)${NC}"
|
||||
((ERRORS++))
|
||||
elif [ "$AGE_HOURS" -gt 30 ]; then
|
||||
echo -e "${YELLOW}⚠️ Dernière archive ancienne (>30h)${NC}"
|
||||
((WARNINGS++))
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}❌ Repository inaccessible ou non initialisé${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# 5. Vérifier les hooks
|
||||
echo -e "${YELLOW}🔍 Vérification des hooks...${NC}"
|
||||
if [ -f /etc/borgmatic/hooks/ntfy-success.sh ]; then
|
||||
echo -e "${GREEN}✅ Hook de succès trouvé${NC}"
|
||||
if [ -x /etc/borgmatic/hooks/ntfy-success.sh ]; then
|
||||
echo -e "${GREEN}✅ Hook de succès exécutable${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Hook de succès non exécutable${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Hook de succès non trouvé${NC}"
|
||||
((WARNINGS++))
|
||||
fi
|
||||
|
||||
if [ -f /etc/borgmatic/hooks/ntfy-error.sh ]; then
|
||||
echo -e "${GREEN}✅ Hook d'erreur trouvé${NC}"
|
||||
if [ -x /etc/borgmatic/hooks/ntfy-error.sh ]; then
|
||||
echo -e "${GREEN}✅ Hook d'erreur exécutable${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Hook d'erreur non exécutable${NC}"
|
||||
((ERRORS++))
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Hook d'erreur non trouvé${NC}"
|
||||
((WARNINGS++))
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 6. Vérifier les logs récents
|
||||
echo -e "${YELLOW}🔍 Logs récents...${NC}"
|
||||
if journalctl -u borgmatic.service -n 1 &> /dev/null; then
|
||||
LAST_LOG=$(journalctl -u borgmatic.service -n 1 --no-pager 2>/dev/null | tail -1)
|
||||
if [ -n "$LAST_LOG" ]; then
|
||||
echo -e "${BLUE} Dernier log: ${LAST_LOG:0:100}...${NC}"
|
||||
fi
|
||||
|
||||
# Chercher des erreurs récentes
|
||||
ERROR_COUNT=$(journalctl -u borgmatic.service --since "24 hours ago" -p err --no-pager 2>/dev/null | wc -l)
|
||||
if [ "$ERROR_COUNT" -gt 0 ]; then
|
||||
echo -e "${RED}❌ ${ERROR_COUNT} erreurs dans les dernières 24h${NC}"
|
||||
((ERRORS++))
|
||||
else
|
||||
echo -e "${GREEN}✅ Aucune erreur dans les dernières 24h${NC}"
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Résumé
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
echo -e "${BLUE}Résumé${NC}"
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
|
||||
if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then
|
||||
echo -e "${GREEN}✅ Tout est OK !${NC}"
|
||||
exit 0
|
||||
elif [ $ERRORS -eq 0 ]; then
|
||||
echo -e "${YELLOW}⚠️ ${WARNINGS} avertissement(s)${NC}"
|
||||
exit 0
|
||||
else
|
||||
echo -e "${RED}❌ ${ERRORS} erreur(s), ${WARNINGS} avertissement(s)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
138
scripts/restore.sh
Executable file
138
scripts/restore.sh
Executable file
@@ -0,0 +1,138 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Script de restauration interactive Borgmatic
|
||||
# Usage: ./restore.sh
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
# Couleurs
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Charger les variables d'environnement
|
||||
if [ -f /etc/borgmatic/.env ]; then
|
||||
source /etc/borgmatic/.env
|
||||
elif [ -f .env ]; then
|
||||
source .env
|
||||
else
|
||||
echo -e "${RED}❌ Fichier .env non trouvé${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$BORG_REPO" ]; then
|
||||
echo -e "${RED}❌ BORG_REPO non défini${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
echo -e "${BLUE}Script de restauration Borgmatic${NC}"
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
echo ""
|
||||
|
||||
# 1. Lister les archives disponibles
|
||||
echo -e "${YELLOW}📦 Archives disponibles:${NC}"
|
||||
echo ""
|
||||
borg list "$BORG_REPO" --short
|
||||
echo ""
|
||||
|
||||
# 2. Demander quelle archive restaurer
|
||||
read -p "Nom de l'archive à restaurer (ou 'latest' pour la plus récente): " ARCHIVE_NAME
|
||||
|
||||
if [ "$ARCHIVE_NAME" == "latest" ]; then
|
||||
ARCHIVE_NAME=$(borg list "$BORG_REPO" --short | tail -1)
|
||||
echo -e "${GREEN}Archive sélectionnée: ${ARCHIVE_NAME}${NC}"
|
||||
fi
|
||||
|
||||
# 3. Vérifier que l'archive existe
|
||||
if ! borg list "$BORG_REPO::$ARCHIVE_NAME" > /dev/null 2>&1; then
|
||||
echo -e "${RED}❌ Archive non trouvée: $ARCHIVE_NAME${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Afficher le contenu de l'archive
|
||||
echo ""
|
||||
echo -e "${YELLOW}📂 Contenu de l'archive (répertoires principaux):${NC}"
|
||||
borg list "$BORG_REPO::$ARCHIVE_NAME" | head -50
|
||||
echo ""
|
||||
|
||||
# 5. Options de restauration
|
||||
echo -e "${YELLOW}Options de restauration:${NC}"
|
||||
echo "1. Monter l'archive pour exploration"
|
||||
echo "2. Extraire des fichiers/dossiers spécifiques"
|
||||
echo "3. Extraire l'archive complète (ATTENTION!)"
|
||||
echo "4. Annuler"
|
||||
echo ""
|
||||
read -p "Choix [1-4]: " CHOICE
|
||||
|
||||
case $CHOICE in
|
||||
1)
|
||||
# Monter l'archive
|
||||
MOUNT_POINT="/tmp/borg-restore-${ARCHIVE_NAME}"
|
||||
mkdir -p "$MOUNT_POINT"
|
||||
|
||||
echo -e "${YELLOW}📌 Montage de l'archive dans: ${MOUNT_POINT}${NC}"
|
||||
borg mount "$BORG_REPO::$ARCHIVE_NAME" "$MOUNT_POINT"
|
||||
|
||||
echo -e "${GREEN}✅ Archive montée avec succès${NC}"
|
||||
echo ""
|
||||
echo "Vous pouvez maintenant explorer et copier les fichiers depuis:"
|
||||
echo -e "${BLUE}${MOUNT_POINT}${NC}"
|
||||
echo ""
|
||||
echo "Pour démonter quand vous avez terminé:"
|
||||
echo -e "${YELLOW}borg umount ${MOUNT_POINT}${NC}"
|
||||
;;
|
||||
|
||||
2)
|
||||
# Extraction sélective
|
||||
read -p "Chemin du fichier/dossier à extraire (ex: /etc/nginx): " PATH_TO_RESTORE
|
||||
read -p "Destination (défaut: ./restore): " RESTORE_DEST
|
||||
RESTORE_DEST=${RESTORE_DEST:-./restore}
|
||||
|
||||
mkdir -p "$RESTORE_DEST"
|
||||
|
||||
echo -e "${YELLOW}🔄 Extraction en cours...${NC}"
|
||||
borg extract --progress "$BORG_REPO::$ARCHIVE_NAME" "$PATH_TO_RESTORE" --destination "$RESTORE_DEST"
|
||||
|
||||
echo -e "${GREEN}✅ Extraction terminée dans: ${RESTORE_DEST}${NC}"
|
||||
;;
|
||||
|
||||
3)
|
||||
# Extraction complète
|
||||
echo -e "${RED}⚠️ ATTENTION: Cette opération va extraire TOUTE l'archive${NC}"
|
||||
read -p "Êtes-vous sûr? (tapez 'OUI' en majuscules): " CONFIRM
|
||||
|
||||
if [ "$CONFIRM" != "OUI" ]; then
|
||||
echo -e "${YELLOW}Annulé${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
read -p "Destination (défaut: ./restore-full): " RESTORE_DEST
|
||||
RESTORE_DEST=${RESTORE_DEST:-./restore-full}
|
||||
|
||||
mkdir -p "$RESTORE_DEST"
|
||||
|
||||
echo -e "${YELLOW}🔄 Extraction complète en cours (peut prendre du temps)...${NC}"
|
||||
borg extract --progress "$BORG_REPO::$ARCHIVE_NAME" --destination "$RESTORE_DEST"
|
||||
|
||||
echo -e "${GREEN}✅ Extraction complète terminée dans: ${RESTORE_DEST}${NC}"
|
||||
;;
|
||||
|
||||
4)
|
||||
echo -e "${YELLOW}Annulé${NC}"
|
||||
exit 0
|
||||
;;
|
||||
|
||||
*)
|
||||
echo -e "${RED}❌ Choix invalide${NC}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}==================================================${NC}"
|
||||
echo -e "${GREEN}✅ Opération terminée${NC}"
|
||||
echo -e "${GREEN}==================================================${NC}"
|
||||
110
scripts/test-notifications.sh
Executable file
110
scripts/test-notifications.sh
Executable file
@@ -0,0 +1,110 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Script de test des notifications ntfy
|
||||
# Usage: ./test-notifications.sh
|
||||
#
|
||||
|
||||
# Couleurs
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Charger les variables d'environnement
|
||||
if [ -f /etc/borgmatic/.env ]; then
|
||||
source /etc/borgmatic/.env
|
||||
elif [ -f .env ]; then
|
||||
source .env
|
||||
else
|
||||
echo -e "${RED}❌ Fichier .env non trouvé${NC}"
|
||||
echo "Créez un fichier .env avec NTFY_URL et NTFY_USER"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$NTFY_URL" ]; then
|
||||
echo -e "${RED}❌ NTFY_URL non défini dans .env${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
echo -e "${BLUE}Test des notifications ntfy${NC}"
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Configuration:${NC}"
|
||||
echo " URL: $NTFY_URL"
|
||||
echo " Auth: $([ -n "$NTFY_USER" ] && echo "✅ Configurée" || echo "❌ Non configurée")"
|
||||
echo ""
|
||||
|
||||
# Test 1: Notification simple
|
||||
echo -e "${YELLOW}📤 Test 1: Notification simple...${NC}"
|
||||
RESPONSE=$(curl -s -w "\n%{http_code}" -u "$NTFY_USER" \
|
||||
-H "Title: Test Borgmatic" \
|
||||
-H "Priority: default" \
|
||||
-H "Tags: test" \
|
||||
-d "Ceci est un test de notification depuis le script de configuration Borgmatic" \
|
||||
"$NTFY_URL")
|
||||
|
||||
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
echo -e "${GREEN}✅ Notification simple envoyée avec succès${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Échec (HTTP $HTTP_CODE)${NC}"
|
||||
echo "$RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
|
||||
# Test 2: Notification de succès (simule un backup réussi)
|
||||
echo -e "${YELLOW}📤 Test 2: Notification de succès de backup...${NC}"
|
||||
RESPONSE=$(curl -s -w "\n%{http_code}" -u "$NTFY_USER" \
|
||||
-H "Title: ✅ Backup réussi" \
|
||||
-H "Priority: default" \
|
||||
-H "Tags: white_check_mark,backup" \
|
||||
-d "Test de notification de succès
|
||||
Archive: test-backup-$(date +%Y%m%d-%H%M)
|
||||
Date: $(date '+%Y-%m-%d %H:%M:%S')
|
||||
Taille: 15.2 GB" \
|
||||
"$NTFY_URL")
|
||||
|
||||
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
echo -e "${GREEN}✅ Notification de succès envoyée avec succès${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Échec (HTTP $HTTP_CODE)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
|
||||
# Test 3: Notification d'erreur (simule un backup échoué)
|
||||
echo -e "${YELLOW}📤 Test 3: Notification d'erreur de backup...${NC}"
|
||||
RESPONSE=$(curl -s -w "\n%{http_code}" -u "$NTFY_USER" \
|
||||
-H "Title: ❌ Backup échoué" \
|
||||
-H "Priority: high" \
|
||||
-H "Tags: x,backup,alert" \
|
||||
-d "Test de notification d'erreur
|
||||
Erreur: Ceci est un test - pas de vraie erreur !
|
||||
Date: $(date '+%Y-%m-%d %H:%M:%S')
|
||||
Vérifiez les logs: journalctl -u borgmatic.service -n 50" \
|
||||
"$NTFY_URL")
|
||||
|
||||
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
echo -e "${GREEN}✅ Notification d'erreur envoyée avec succès${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Échec (HTTP $HTTP_CODE)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}==================================================${NC}"
|
||||
echo -e "${GREEN}✅ Tous les tests de notification ont réussi !${NC}"
|
||||
echo -e "${GREEN}==================================================${NC}"
|
||||
echo ""
|
||||
echo "Vérifiez que vous avez reçu 3 notifications sur votre appareil:"
|
||||
echo " 1. Notification de test simple"
|
||||
echo " 2. Notification de succès de backup"
|
||||
echo " 3. Notification d'erreur de backup"
|
||||
echo ""
|
||||
39
systemd/borgmatic.service
Normal file
39
systemd/borgmatic.service
Normal file
@@ -0,0 +1,39 @@
|
||||
[Unit]
|
||||
Description=Borgmatic backup
|
||||
Documentation=https://torsion.org/borgmatic/
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
ConditionACPower=true
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
|
||||
# Sécurité
|
||||
ProtectSystem=strict
|
||||
PrivateTmp=yes
|
||||
ReadWritePaths=/var/log/borgmatic
|
||||
|
||||
# Variables d'environnement
|
||||
EnvironmentFile=/etc/borgmatic/.env
|
||||
|
||||
# Nice et IONice pour ne pas surcharger le système
|
||||
Nice=19
|
||||
IOSchedulingClass=2
|
||||
IOSchedulingPriority=7
|
||||
|
||||
# Délai avant timeout (2 heures)
|
||||
TimeoutStartSec=7200
|
||||
|
||||
# Exécuter borgmatic
|
||||
ExecStart=/usr/bin/borgmatic --verbosity 1 --syslog-verbosity 1
|
||||
|
||||
# En cas d'échec, continuer (le hook d'erreur gère la notification)
|
||||
SuccessExitStatus=0 1
|
||||
|
||||
# Logging
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=borgmatic
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
16
systemd/borgmatic.timer
Normal file
16
systemd/borgmatic.timer
Normal file
@@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=Run borgmatic backup daily at 3 AM
|
||||
Documentation=https://torsion.org/borgmatic/
|
||||
|
||||
[Timer]
|
||||
# Exécuter tous les jours à 3h du matin
|
||||
OnCalendar=*-*-* 03:00:00
|
||||
|
||||
# Si le système était éteint, exécuter au démarrage
|
||||
Persistent=true
|
||||
|
||||
# Randomisation pour éviter la surcharge (± 15 minutes)
|
||||
RandomizedDelaySec=15min
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Reference in New Issue
Block a user