Files
agence66-borgmatic/Makefile
BeauTroll 9b10a325dc
Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
Fix disk-usage command to handle SSH URLs with ports correctly
Fix the disk-usage make target to properly parse SSH URLs containing ports
and display repository statistics correctly.

Changes:
- Simplify Borg statistics parsing to show actual values
- Fix SSH connection to handle custom ports (e.g., port 23)
- Extract user@host and port separately from BORG_REPO URL
- Use ssh -p PORT syntax instead of incorrect host:port format

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 15:48:27 +01:00

148 lines
5.7 KiB
Makefile

# Makefile pour Borgmatic - Agence66
# Usage: make [commande]
.PHONY: help install test backup list restore healthcheck logs status clean disk-usage
# 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)"
@sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && 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 bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic --dry-run --verbosity 2'
backup: ## Exécute un backup manuel
@echo "$(BLUE)Exécution du backup...$(NC)"
@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
@echo "$(BLUE)Exécution du backup (mode verbeux)...$(NC)"
@sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic --verbosity 2 --stats --list'
list: ## Liste toutes les archives de backup
@echo "$(BLUE)Archives disponibles:$(NC)"
@sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic list'
list-files: ## Liste les fichiers de la dernière archive
@echo "$(BLUE)Fichiers de la dernière archive:$(NC)"
@sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic list --archive latest'
info: ## Affiche les informations sur le repository
@echo "$(BLUE)Informations sur le repository:$(NC)"
@sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic info'
disk-usage: ## Affiche l'espace disque utilisé et libre sur le serveur de backup
@echo "$(BLUE)Espace disque sur le serveur de backup:$(NC)"
@echo ""
@echo "$(YELLOW)Espace utilisé par le repository Borg:$(NC)"
@sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && borgmatic info 2>/dev/null | grep -A1 "Original size" | head -2'
@echo ""
@echo "$(YELLOW)Espace libre sur le serveur distant:$(NC)"
@sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && \
USER_HOST=$$(echo $$BORG_REPO | sed "s|ssh://||" | sed "s|:.*||") && \
PORT=$$(echo $$BORG_REPO | grep -o ":[0-9]*/" | sed "s|[:/]||g") && \
if [ -n "$$PORT" ]; then \
ssh -p $$PORT $$USER_HOST "df -h ~/ | tail -1"; \
else \
ssh $$USER_HOST "df -h ~/ | tail -1"; \
fi'
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 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
@echo "$(YELLOW)Nettoyage des anciennes archives...$(NC)"
@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
@echo "$(YELLOW)Compactage du repository...$(NC)"
@sudo bash -c 'set -a && source /etc/borgmatic/.env && set +a && 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