From 7c019b5631e559b23d6b5fb6d9ad0f53d08c5a22 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 24 Apr 2023 09:31:33 +0200 Subject: [PATCH] Added listarchives script. --- Plan Borg/bin/listarchives | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 Plan Borg/bin/listarchives diff --git a/Plan Borg/bin/listarchives b/Plan Borg/bin/listarchives new file mode 100755 index 0000000..3906f7a --- /dev/null +++ b/Plan Borg/bin/listarchives @@ -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