#!/usr/bin/env bash # scripts/cron-install.sh — installe le cron quotidien backup # Usage : sudo ./scripts/cron-install.sh set -euo pipefail REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" CRON_USER="${CRON_USER:-$(whoami)}" CRON_FILE="/etc/cron.d/formation-hub" if [ "$(id -u)" -ne 0 ]; then echo "Run as root (sudo) pour ecrire dans /etc/cron.d/" exit 1 fi cat > "$CRON_FILE" <> /var/log/formation-hub-backup.log 2>&1 # Healthcheck toutes les 5 minutes (logue uniquement les fails) */5 * * * * $CRON_USER cd $REPO_DIR && ./scripts/healthcheck.sh >/dev/null 2>&1 || logger -t formation-hub "healthcheck failed at \$(date -Iseconds)" EOF chmod 644 "$CRON_FILE" echo "Cron installe : $CRON_FILE" echo "" echo "Verification :" cat "$CRON_FILE" echo "" echo "Pour test manuel : sudo -u $CRON_USER cd $REPO_DIR && ./scripts/backup.sh" echo "Logs backup : tail -f /var/log/formation-hub-backup.log"