summaryrefslogtreecommitdiff
path: root/lastBackups
blob: 83fcbedc0c373830af5ecaa8f688563bafe1286d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash

. /etc/backup.conf

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="2000_01_01"
  delta=$[$(date +%s) - $(date -d $(echo ${lbu} | sed "s/_//g") +%s)]
  namen[${#namen[@]}]="$(basename $(echo ${dest} | sed "s#/\(${recognSubdirRegex}\)\$#_\1#" | sed "s#/rsync\$##; s#/duplicity\$##"))"
  [ ! "$(ls -A ${dest}/${lbu})" ] &&
    veraltet[${#veraltet[@]}]="LEER!" ||
    [ ${delta} -gt ${outdatedLimit} ] && \
      veraltet[${#veraltet[@]}]="VERALTET!" || \
      veraltet[${#veraltet[@]}]=""
  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//"