diff options
-rwxr-xr-x | backup-progress.in | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/backup-progress.in b/backup-progress.in index 4d4dde9..90492fb 100755 --- a/backup-progress.in +++ b/backup-progress.in @@ -4,10 +4,21 @@ export LC_ALL=C +declare -A nm +declare -A pc +declare -A sz + for backupID in "${!backups[@]}"; do [ -s "/tmp/${backupID}.pid" ] || continue kill -0 $(cat "/tmp/${backupID}.pid") || continue dir="${backups["${backupID}"]%% *}" + dir="${dir%/}" + nm[${#nm[@]}]=$( + echo ${dir} \ + | sed "s#/\(${recognSubdirRegex}\)\$#_\1#" \ + | sed "s#/rsync\$##; s#/duplicity\$##" \ + | sed 's#^.*/##' + ) last=$( ls -1 "$dir" \ | grep '[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}' \ @@ -35,5 +46,41 @@ for backupID in "${!backups[@]}"; do printf '100*%s/%s\n' "${current_size}" "${last_size}" \ | bc -l ) - printf '%6.2f %% (%s%s %sB) %s\n' "${percentage}" "${size}" "${decimal}" "${unit}" "${backupID}" + pc[${#pc[@]}]=$( + printf '%6.2f %%' "${percentage}" + ) + sz[${#sz[@]}]=$( + printf '(%s%s %sB)' "${size}" "${decimal}" "${unit}" + ) +done + +nm_len=$( + for n in "${nm[@]}"; do + printf '%s\n' "${#n}" + done \ + | sort -n \ + | tail -n1 +) + +pc_len=$( + for p in "${pc[@]}"; do + printf '%s\n' "${#p}" + done \ + | sort -n \ + | tail -n1 +) + +sz_len=$( + for s in "${sz[@]}"; do + printf '%s\n' "${#s}" + done \ + | sort -n \ + | tail -n1 +) + +for i in "${!nm[@]}"; do + printf '%-'"${nm_len}"'s %'"${pc_len}"'s %'"${sz_len}"'s\n' \ + "${nm[${i}]}" \ + "${pc[${i}]}" \ + "${sz[${i}]}" done |