Auto-load .env in Makefile for all borgmatic commands

- All make commands now automatically source /etc/borgmatic/.env before running
- Use 'set -a && source && set +a' pattern to export all variables
- Fixes "Cannot find variable BORG_REPO" errors when running make commands
- Applies to: test-config, dry-run, backup, list, info, check, prune, compact
- No need to manually load environment variables anymore

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
BeauTroll
2025-12-16 06:11:38 +01:00
parent 2b087414ba
commit 615192ceda

View File

@@ -21,7 +21,7 @@ install: ## Installe Borgmatic et configure le système
test-config: ## Valide la configuration Borgmatic test-config: ## Valide la configuration Borgmatic
@echo "$(BLUE)Validation de la configuration...$(NC)" @echo "$(BLUE)Validation de la configuration...$(NC)"
@sudo borgmatic config validate @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic config validate'
test-notifications: ## Teste les notifications ntfy test-notifications: ## Teste les notifications ntfy
@echo "$(BLUE)Test des notifications ntfy...$(NC)" @echo "$(BLUE)Test des notifications ntfy...$(NC)"
@@ -33,27 +33,27 @@ healthcheck: ## Vérifie la santé du système de backup
dry-run: ## Simule un backup sans l'exécuter dry-run: ## Simule un backup sans l'exécuter
@echo "$(BLUE)Simulation du backup (dry-run)...$(NC)" @echo "$(BLUE)Simulation du backup (dry-run)...$(NC)"
sudo borgmatic --dry-run --verbosity 2 @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic --dry-run --verbosity 2'
backup: ## Exécute un backup manuel backup: ## Exécute un backup manuel
@echo "$(BLUE)Exécution du backup...$(NC)" @echo "$(BLUE)Exécution du backup...$(NC)"
sudo borgmatic --verbosity 1 --stats @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic --verbosity 1 --stats'
backup-verbose: ## Exécute un backup manuel avec détails backup-verbose: ## Exécute un backup manuel avec détails
@echo "$(BLUE)Exécution du backup (mode verbeux)...$(NC)" @echo "$(BLUE)Exécution du backup (mode verbeux)...$(NC)"
sudo borgmatic --verbosity 2 --stats --list @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic --verbosity 2 --stats --list'
list: ## Liste toutes les archives de backup list: ## Liste toutes les archives de backup
@echo "$(BLUE)Archives disponibles:$(NC)" @echo "$(BLUE)Archives disponibles:$(NC)"
@borgmatic list @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic list'
list-files: ## Liste les fichiers de la dernière archive list-files: ## Liste les fichiers de la dernière archive
@echo "$(BLUE)Fichiers de la dernière archive:$(NC)" @echo "$(BLUE)Fichiers de la dernière archive:$(NC)"
@borgmatic list --archive latest @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic list --archive latest'
info: ## Affiche les informations sur le repository info: ## Affiche les informations sur le repository
@echo "$(BLUE)Informations sur le repository:$(NC)" @echo "$(BLUE)Informations sur le repository:$(NC)"
@borgmatic info @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic info'
restore: ## Lance le script de restauration interactive restore: ## Lance le script de restauration interactive
@echo "$(BLUE)Restauration interactive...$(NC)" @echo "$(BLUE)Restauration interactive...$(NC)"
@@ -61,15 +61,15 @@ restore: ## Lance le script de restauration interactive
check: ## Vérifie l'intégrité du repository et des archives check: ## Vérifie l'intégrité du repository et des archives
@echo "$(BLUE)Vérification de l'intégrité...$(NC)" @echo "$(BLUE)Vérification de l'intégrité...$(NC)"
sudo borgmatic check --verbosity 1 @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic check --verbosity 1'
prune: ## Nettoie les anciennes archives selon la politique de rétention prune: ## Nettoie les anciennes archives selon la politique de rétention
@echo "$(YELLOW)Nettoyage des anciennes archives...$(NC)" @echo "$(YELLOW)Nettoyage des anciennes archives...$(NC)"
sudo borgmatic prune --verbosity 1 @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic prune --verbosity 1'
compact: ## Compacte le repository pour libérer de l'espace compact: ## Compacte le repository pour libérer de l'espace
@echo "$(YELLOW)Compactage du repository...$(NC)" @echo "$(YELLOW)Compactage du repository...$(NC)"
sudo borg compact $(BORG_REPO) @sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borg compact $${BORG_REPO}'
status: ## Affiche le statut du timer systemd status: ## Affiche le statut du timer systemd
@echo "$(BLUE)Statut du timer Borgmatic:$(NC)" @echo "$(BLUE)Statut du timer Borgmatic:$(NC)"