#!/bin/bash # last-backups version #VERSION# [ -r "#ETCDIR#/backup.conf" ] && \ . "#ETCDIR#/backup.conf" usage () { >&2 echo \ 'Usage: last-backups Show information about date of last backups and warn about outdated ones. Options: #HELPTEXT# #' [ -n "$1" ] && exit $1 exit 1 } if [ $# -eq 1 ] then if [ "$1" == "--help" ] then usage 0 elif [ "$1" == "--version" ] then >&2 echo '#VERSION#' exit 0 fi usage elif [ $# -gt 1 ] then usage fi unset namen unset veraltet unset daten for backupID in ${!backups[@]} do dest="${backups["${backupID}"]%% *}" dest="${dest%/}" while [ ! -d "${dest}" ] && [ ${maxWait} -gt 0 ] do sleep 1 maxWait=$[${maxWait}-1] done lbu=$( ls -1 ${dest} | \ grep -v "^aktuell$" | \ sed "s/^duplicity-\(inc\|full\)\.\(.*\.\)\?\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)T[0-9]\{6\}Z\..*$/\3_\4_\5/" | \ sort -n | \ uniq | \ grep "^[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}$" | \ tail -n1 ) [ "${lbu}" == "" ] && lbu="1970_01_01" delta=$[$(date +%s) - $(date -d $(echo ${lbu} | sed "s/_//g") +%s)] namen[${#namen[@]}]=$( basename $( printf '%s\n' "${dest}" \ | sed ' s#/rsync$## s#/duplicity$## ' \ | sed ' :a s#/\('"${recognSubdirRegex}"'\)$#_\1# ta ' ) ) if [ -f "/tmp/${backupID}.pid" ] && pgrep '(^|/|\s)hardlinked-backup\S*$' | grep -qxF "$(cat "/tmp/${backupID}.pid")"; then laeuft='_laeuft' else laeuft='' fi if [ ! -d "${dest}/${lbu}" ] then veraltet[${#veraltet[@]}]="LEER!${laeuft}" elif [ ${delta} -gt ${outdatedLimit} ] && \ ! printf '%s\n' "${seldomBackups[@]}" | \ grep -qxF "${backupID}" then veraltet[${#veraltet[@]}]="VERALTET!${laeuft}" elif [ ${delta} -gt ${outdatedSeldomLimit} ] then veraltet[${#veraltet[@]}]="VERALTET!${laeuft}" else veraltet[${#veraltet[@]}]="${laeuft}" fi daten[${#daten[@]}]="${lbu}" done nl=0 vl=0 dl=0 for ((i=0; i<${#namen[@]}; i++)) { [ ${#namen[${i}]} -gt ${nl} ] && nl=${#namen[${i}]} [ ${#veraltet[${i}]} -gt ${vl} ] && vl=${#veraltet[${i}]} [ ${#daten[${i}]} -gt ${dl} ] && dl=${#daten[${i}]} } for ((i=0; i<${#namen[@]}; i++)) { while [ ${#namen[${i}]} -lt ${nl} ] do namen[${i}]="${namen[${i}]} " done while [ ${#veraltet[${i}]} -lt ${vl} ] do veraltet[${i}]="${veraltet[${i}]} " done while [ ${#daten[${i}]} -lt ${dl} ] do daten[${i}]="${daten[${i}]} " done } for ((i=0; i<${#namen[@]}; i++)) { echo "${daten[${i}]} ${veraltet[${i}]} ${namen[${i}]} ${daten[${i}]}" } | \ sort | \ sed "s/^\S\+\s//"