Added listarchives script.

This commit is contained in:
Christian P. MOMON 2023-04-24 09:31:33 +02:00
parent 0b30e8d732
commit 7c019b5631
1 changed files with 58 additions and 0 deletions

58
Plan Borg/bin/listarchives Executable file
View File

@ -0,0 +1,58 @@
#!/bin/bash
SCRIPT_NAME="$(basename "$0")"
roundn()
{
echo $(echo "($1+0.5)/1" | bc)
}
convert_duration()
{
local input="$1"
local minutes
if [[ $input =~ ([0-9]+)\ minutes ]]; then
minutes=${BASH_REMATCH[1]}
else
minutes=0
fi
local seconds
if [[ $input =~ ([0-9\.]+)\ seconds ]]; then
seconds=${BASH_REMATCH[1]}
seconds=$(roundn $seconds)
if [ $seconds -eq "60" ]; then
seconds=0
minutes=$(($minutes+1))
fi
else
seconds=0
fi
printf "00:%02d:%02d\n" ${minutes} ${seconds}
}
#
CONFIG="$1"
if [ -f "$CONFIG" ]; then
export BORG_PASSCOMMAND="cat /srv/borg/.borg-passphrase"
BORG_REPOS="/var/backups/borg/"
cd $BORG_REPOS
ARCHIVE_COUNT=0
REPO_COUNT=0
echo "ARCHIVE FILES Diff Duration"
echo "------------------------------------------------------------------------------------------------"
for ARCHIVE in $(borgmatic -c $CONFIG list | awk '{print$1}' | tail +2); do
#echo "== $ARCHIVE"
INFOS=$(borgmatic -c "$CONFIG" info --archive "$ARCHIVE")
#echo "$INFOS"
DURATION=$(echo "$INFOS" | grep Duration)
DURATION=$(convert_duration "${DURATION:10}")
DIFF_SIZE=$(echo "$INFOS" | grep "This archive" | awk '{ print $7" "$8}')
FILES=$(echo "$INFOS" | grep "Number of files" | awk '{ print $4 }')
printf "%-30s %10s %10s %s\n" "$ARCHIVE" "$FILES" "$DIFF_SIZE" "$DURATION"
done
echo "------------------------------------------------------------------------------------------------"
fi