Files
agence66-borgmatic/scripts/disk-usage.sh
BeauTroll 07a98d5617
Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
Fix duplicate output in disk-usage script with awk
Replace grep-based parsing with awk to properly capture header and data
lines without duplicates.

Changes:
- Use awk to capture header line (Original/Compressed/Deduplicated size)
- Print header followed by matching "All archives" line with sizes
- Exit immediately after first match to prevent duplicates

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-18 16:09:56 +01:00

44 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
#
# Script d'affichage de l'espace disque du serveur de backup
# Usage: ./disk-usage.sh
#
set -e
# Couleurs
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Charger et exporter les variables d'environnement
if [ -f /etc/borgmatic/.env ]; then
set -a
source /etc/borgmatic/.env
set +a
elif [ -f .env ]; then
set -a
source .env
set +a
fi
echo -e "${BLUE}Espace disque sur le serveur de backup:${NC}"
echo ""
# Statistiques du repository Borg
echo -e "${YELLOW}Espace utilisé par le repository Borg (toutes archives):${NC}"
borgmatic info 2>/dev/null | awk '/Original size.*Compressed size.*Deduplicated size/{header=$0; next} /All archives:.*[GT]B/{if(header) print header; print; exit}'
echo ""
# Espace libre sur le serveur distant
echo -e "${YELLOW}Espace libre sur le serveur distant:${NC}"
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