]> arthur.barton.de Git - backup-script.git/blob - bin/backup-status
Autodetect "localhost" and 127.0.0.1 as being "local"
[backup-script.git] / bin / backup-status
1 #!/bin/bash
2 #
3 # backup-script system for cloning systems using rsync
4 # Copyright (c)2008-2013 Alexander Barton, alex@barton.de
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING, README and AUTHORS for more information.
11 #
12
13 NAME=`basename $0`
14 CONF_D="/etc/backup-script.d"
15 QUICK=0
16
17 export LC_ALL=C
18
19 declare -i count=0
20
21 # Default settings, can be overwritten in backup-script.conf:
22 default_target=""
23
24 if [ "$1" == "-q" ]; then
25         QUICK=1
26         shift
27 fi
28
29 case "$1" in
30     "-"*)
31         echo "Usage: $NAME [-p] [<system> [<system> [...]]]"
32         exit 1
33         ;;
34 esac
35
36 if [ $# -ge 1 ]; then
37         for s in $@; do
38                 if [ ! -r "${CONF_D}/$s" ]; then
39                         echo "$NAME: Can' read \"${CONF_D}/$s\"!"
40                         exit 1
41                 fi
42                 sys="$sys ${CONF_D}/$s"
43         done
44 else
45         sys=${CONF_D}/*
46 fi
47
48 [ -r "${CONF_D}/backup-script.conf" ] && source "${CONF_D}/backup-script.conf"
49
50 for f in $sys; do
51         [ -r "$f" -a -f "$f" ] || continue
52
53         fname=`basename $f`
54         case "$fname" in
55                 "backup-script.conf"|*.sh)
56                         continue
57                         ;;
58         esac
59
60         # Set global defaults
61         system="$fname"
62         target="$default_target"
63
64         # Read in system configuration file
65         source "$f"
66
67         # Validate configuration
68         [ "$system" = "localhost" -o "$system" = "127.0.0.1" ] && local=1
69
70         destdir="$target"
71         target="$target/$system"
72
73         [ -d "$target" ] || continue
74
75         # System name
76         [ "$system" = "$fname" ] && echo "$system" || echo "$system [$fname]"
77
78         # System target directory
79         echo "- Target: $target"
80         if [ "$QUICK" = "0" ]; then
81                 size=`du -sh "$target" | cut -f1`
82                 echo "- Size:" $size
83         fi
84
85         # Timestamp and result code
86         if [ -f "$target/.stamp" ]; then
87                 last=`stat "$target/.stamp" | grep "^Modify: " | cut -d':' -f2- | cut -d. -f1`
88                 [ -n "$last" ] && echo "- Date:" $last
89                 unset code
90                 source "$target/.stamp"
91                 [ -n "$code" ] && echo "- Result code:" $code
92         else
93                 echo "- No timestamp recorded!?"
94         fi
95
96         count=$count+1
97         echo
98 done
99
100 if [ $count -lt 1 ]; then
101         echo "No backups found!"
102         exit 1
103 fi
104 echo "$count system backup(s) found."
105
106 # -eof-