Skip to main content

PBS Disk Size of Backups

Specificare il nome del file, del quale si vuole valutare la dimensione, nella variabile "FILE_PATH".

#!/bin/bash

FILE_PATH=/S3cache-1/ns/pveISOnew/vm/102/2026-10-06T12\:14\:30Z/drive-ide0.img.fidx
FIRST_FOLDER=$(printf '%s' "$FILE_PATH" | awk -F'/' '{print $2}')
TOTAL_SIZE=0
COUNT=0

while read -r line; do
    hash=$(printf '%s' "$line" | tr -d '"')
    length=$(printf '%s' "$hash" | wc -c)
    if [ "$length" -ne 64 ]; then
        continue
    fi

    prefix=$(printf '%s' "$hash" | cut -c1-4)
    path="/${FIRST_FOLDER}/.chunks/${prefix}/${hash}"

    if [ -f "$path" ]; then
        # Usa du per ottenere la dimensione in byte
        size=$(du -b -- "$path" 2>/dev/null | awk '{print $1}')
        if [ -n "$size" ]; then
            TOTAL_SIZE=$((TOTAL_SIZE + size))
            COUNT=$((COUNT + 1))
        fi
    else
        echo "FILE NON TROVATO: $path"
    fi
done < <(proxmox-backup-debug inspect file "$FILE_PATH")

# Formatta il totale in modo leggibile
if [ "$TOTAL_SIZE" -ge 1099511627776 ]; then
    total_human="$(awk "BEGIN {printf \"%.2f\", $TOTAL_SIZE / 1024^4}") TB"
elif [ "$TOTAL_SIZE" -ge 1073741824 ]; then
    total_human="$(awk "BEGIN {printf \"%.2f\", $TOTAL_SIZE / 1024^3}") GB"
elif [ "$TOTAL_SIZE" -ge 1048576 ]; then
    total_human="$(awk "BEGIN {printf \"%.2f\", $TOTAL_SIZE / 1024^2}") MB"
elif [ "$TOTAL_SIZE" -ge 1024 ]; then
    total_human="$(awk "BEGIN {printf \"%.2f\", $TOTAL_SIZE / 1024}") KB"
else
    total_human="$TOTAL_SIZE byte"
fi

echo ""
echo "===================================================="
echo "Riepilogo:"
echo "  File trovati:      $COUNT"
echo "  Dimensione totale: $total_human ($TOTAL_SIZE byte)"
echo "===================================================="