Initial import: monitoring, power-management, maintenance, web scripts
This commit is contained in:
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
# Archive sessions older than 7 days to S3, keep archives 30 days, then delete.
|
||||
set -euo pipefail
|
||||
|
||||
ARCHIVE_DIR="${HERMES_HOME:-$HOME/.hermes}/archives"
|
||||
RETENTION_DAYS=30
|
||||
AGE_DAYS=7
|
||||
S3_BUCKET="hermes-archives"
|
||||
S3_ENDPOINT="https://s3.keller-laurent.org"
|
||||
DATE=$(date +%F)
|
||||
ARCHIVE_FILE="sessions-${DATE}.jsonl"
|
||||
|
||||
mkdir -p "$ARCHIVE_DIR"
|
||||
|
||||
# 1. Export sessions older than AGE_DAYS to a dated archive file
|
||||
if hermes sessions export "$ARCHIVE_DIR/$ARCHIVE_FILE" 2>/dev/null; then
|
||||
echo "✅ Exported sessions to $ARCHIVE_DIR/$ARCHIVE_FILE"
|
||||
|
||||
# 2. Upload to S3
|
||||
mc cp "$ARCHIVE_DIR/$ARCHIVE_FILE" "minio/$S3_BUCKET/" 2>/dev/null && \
|
||||
echo "✅ Uploaded to s3://$S3_BUCKET/$ARCHIVE_FILE"
|
||||
else
|
||||
echo "ℹ️ No sessions to export (or export failed)"
|
||||
fi
|
||||
|
||||
# 3. Prune sessions older than AGE_DAYS from the DB
|
||||
yes | hermes sessions prune --older-than "$AGE_DAYS" 2>/dev/null && \
|
||||
echo "✅ Pruned sessions older than ${AGE_DAYS} days" || \
|
||||
echo "ℹ️ No sessions to prune"
|
||||
|
||||
# 4. Delete local archive files older than RETENTION_DAYS
|
||||
find "$ARCHIVE_DIR" -name 'sessions-*.jsonl' -type f -mtime +"$RETENTION_DAYS" -delete 2>/dev/null
|
||||
echo "✅ Cleaned local archives older than ${RETENTION_DAYS} days"
|
||||
|
||||
# 5. Clean old archives from S3 (older than RETENTION_DAYS)
|
||||
mc find "minio/$S3_BUCKET" --name "sessions-*.jsonl" --older-than "${RETENTION_DAYS}d" \
|
||||
--exec "mc rm {}" 2>/dev/null || true
|
||||
echo "✅ Cleaned S3 archives older than ${RETENTION_DAYS} days"
|
||||
|
||||
# 6. Report
|
||||
echo ""
|
||||
echo "=== Archives dans s3://$S3_BUCKET ==="
|
||||
mc ls "minio/$S3_BUCKET/" 2>/dev/null || echo "(empty)"
|
||||
echo ""
|
||||
echo "=== Archives locales ==="
|
||||
ls -lh "$ARCHIVE_DIR"/ 2>/dev/null || echo "(empty)"
|
||||
@@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
# Script d'analyse hebdomadaire des éléments obsolètes sur le système
|
||||
# Génère un rapport et l'envoie par email à admin@keller-laurent.org
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REPORT=$(mktemp)
|
||||
trap 'rm -f "$REPORT"' EXIT
|
||||
|
||||
{
|
||||
echo "═══════════════════════════════════════════════"
|
||||
echo " RAPPORT HEBDOMADAIRE — ÉLÉMENTS OBSOLÈTES"
|
||||
echo " $(date '+%Y-%m-%d %H:%M') — $(hostname)"
|
||||
echo "═══════════════════════════════════════════════"
|
||||
echo ""
|
||||
|
||||
# ── 1. Paquets orphelins (autoremove) ──
|
||||
echo "── 1. PAQUETS ORPHELINS (autoremove) ──────────"
|
||||
orphans=$(apt-get --just-print autoremove 2>&1 | grep "Remv" | sed 's/Remv //' | sed 's/ \[.*//' || true)
|
||||
orphan_count=$(echo "$orphans" | grep -c . || true)
|
||||
if [ "$orphan_count" -eq 0 ]; then
|
||||
echo " Aucun paquet orphelin."
|
||||
else
|
||||
orphan_size=$(dpkg-query -Wf '${Package}\t${Installed-Size}\n' $orphans 2>/dev/null | awk '{sum+=$2} END {printf "%.0f", sum/1024}')
|
||||
echo " Paquets: $orphan_count | Taille: ${orphan_size:-0} MB"
|
||||
echo ""
|
||||
echo " Top 10 plus gros :"
|
||||
dpkg-query -Wf '${Package}\t${Installed-Size}\n' $orphans 2>/dev/null | sort -t$'\t' -k2 -rn | head -10 | awk '{printf " %-40s %d MB\n", $1, $2/1024}'
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# ── 2. Anciens noyaux ──
|
||||
echo "── 2. ANCIENS NOYAUX ──────────────────────────"
|
||||
current_kernel=$(uname -r)
|
||||
installed_kernels=$(dpkg -l 'linux-image-*' 2>/dev/null | grep '^ii' | awk '{print $2}' | sort -V || true)
|
||||
old_kernels=$(echo "$installed_kernels" | grep -v "$(echo $current_kernel | sed 's/-[^-]*$//')" || true)
|
||||
old_count=$(echo "$old_kernels" | grep -c . || true)
|
||||
echo " Noyau actif : $current_kernel"
|
||||
if [ "$old_count" -eq 0 ]; then
|
||||
echo " Aucun ancien noyau."
|
||||
else
|
||||
echo " Anciens noyaux installés : $old_count"
|
||||
echo "$old_kernels" | sed 's/^/ /'
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# ── 3. Cache APT ──
|
||||
echo "── 3. CACHE APT ───────────────────────────────"
|
||||
apt_cache=$(du -sh /var/cache/apt/archives/ 2>/dev/null | awk '{print $1}')
|
||||
echo " Taille : $apt_cache"
|
||||
echo ""
|
||||
|
||||
# ── 4. Journaux systemd ──
|
||||
echo "── 4. JOURNAUX SYSTEMD ────────────────────────"
|
||||
journal_size=$(journalctl --disk-usage 2>&1 | grep -oP '[\d.]+[GMK]' || echo "?")
|
||||
echo " Taille : $journal_size"
|
||||
echo ""
|
||||
|
||||
# ── 5. Conteneurs/images Docker inutilisés ──
|
||||
if command -v docker &>/dev/null; then
|
||||
echo "── 5. DOCKER ──────────────────────────────────"
|
||||
unused_containers=$(docker container ls -a --filter status=exited --filter status=created -q 2>/dev/null | wc -l)
|
||||
dangling_images=$(docker images -f dangling=true -q 2>/dev/null | wc -l)
|
||||
unused_volumes=$(docker volume ls -f dangling=true -q 2>/dev/null | wc -l)
|
||||
echo " Conteneurs arrêtés : $unused_containers"
|
||||
echo " Images dangling : $dangling_images"
|
||||
echo " Volumes orphelins : $unused_volumes"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# ── 6. Espace disque ──
|
||||
echo "── 6. ESPACE DISQUE ───────────────────────────"
|
||||
df -h / | tail -1 | awk '{printf " Utilisé: %s / %s (%s libre)\n", $3, $2, $4}'
|
||||
echo ""
|
||||
|
||||
# ── 7. Fichiers temporaires volumineux ──
|
||||
echo "── 7. FICHIERS TEMPORAIRES VOLUMINEUX ─────────"
|
||||
tmp_size=$(du -sh /tmp 2>/dev/null | awk '{print $1}')
|
||||
echo " /tmp : $tmp_size"
|
||||
echo ""
|
||||
|
||||
echo "═══════════════════════════════════════════════"
|
||||
echo " FIN DU RAPPORT"
|
||||
echo "═══════════════════════════════════════════════"
|
||||
} > "$REPORT"
|
||||
|
||||
# Output for cron delivery
|
||||
cat "$REPORT"
|
||||
Reference in New Issue
Block a user