3 ### Check that dumps have been made as expected.
5 ### (c) 2013 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the `rsync-backup' program.
12 ### rsync-backup is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### rsync-backup is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with rsync-backup; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 ###--------------------------------------------------------------------------
32 ### Stubs for the configuration file.
43 ###--------------------------------------------------------------------------
44 ### Output format switch.
47 defformat () { formats=$formats$1:; }
55 case $fmtstate in $state) break ;; esac
56 case "$fmtstate,$state" in
62 fmtstate=hosttbl_begin
64 hosttbl_begin,hosttbl_*)
65 ${fmt}_hosttbl_begin "$@"
68 hosttbl_host,hosttbl_fs)
71 hosttbl_fs,hosttbl_host)
72 ${fmt}_hosttbl_sep "$@"
75 hosttbl_begin,* | hosttbl_end,*)
76 fmtstate=logdump_begin
79 ${fmt}_hosttbl_end "$@"
82 logdump_begin,logdump_*)
85 logdump_out,logdump_info | logdump_out,logdump_file)
88 logdump_*,logdump_begin)
89 ${fmt}_logdump_end "$@"
90 fmtstate=logdump_begin
105 echo >&2 "$quis: FATAL! NO PROGRESS IN FMT STATE MACHINE"
111 ${fmt}_$fmtstate "$@"
114 ###--------------------------------------------------------------------------
115 ### Plain text output.
120 txt_hosttbl_begin () { :; }
121 txt_hosttbl_host () { echo "HOST $1"; }
122 txt_hosttbl_fs () { printf " %-23s %s\n" "$2" "$4"; }
123 txt_hosttbl_sep () { echo; }
124 txt_hosttbl_end () { :; }
126 txt_logdump_begin () {
129 -----------------------------------------------------------------------------
135 txt_logdump_info () { echo "!!! $3"; }
136 txt_logdump_file () { cat "$3"; }
137 txt_logdump_end () { :; }
144 ###--------------------------------------------------------------------------
151 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
152 "http://www.w3c.org/TR/html4/strict.dtd">
155 <title>$now rsync-backup report</title>
156 <style type='text/css'><!--
163 h1, h2 { font-family: sans-serif; font-weight: bold; }
167 border-bottom: solid medium black;
173 border-top: solid thin black;
185 border-top: solid medium black;
195 border-collapse: collapse;
196 display: inline-table;
199 table.hosttbl tr.fs td {
200 border: solid thin black;
202 table.hosttbl td { padding: 0.5ex 0.5em; }
203 table.hosttbl tr.host td {
207 font-family: monospace;
209 table.hosttbl td.fs {
210 font-family: monospace;
213 table.hosttbl td.winning { background: #2f4; }
214 table.hosttbl td.failed { background: #f80; }
215 table.hosttbl td.broken { background: #f11; }
216 table.hosttbl td.never { background: #66f; }
223 border: solid thin black;
231 border: solid thin black;
237 <h1><tt>rsync-backup</tt> report: $now</tt></h1>
241 html_hosttbl_begin () {
248 html_hosttbl_host () {
250 <table class=hosttbl>
251 <tr class=host><td colspan=2>$1</tc>
257 winning) link="" knil="" ;;
258 *) link="<a href='#log-$host:$fs'>" knil="</a>";;
263 <td class=$3>$link$4$knil</td>
267 html_hosttbl_sep () {
273 html_hosttbl_end () {
279 html_logdump_begin () {
282 <h2><a name='log-$1:$2'>Log tail for <tt>$1:$2</tt></a></h2>
286 html_logdump_info () {
288 <div class=logdump-info>$3</div>
292 html_logdump_file () {
302 html_logdump_end () { :; }
308 Checked at $now $now_time.
309 <br><tt>rsync-backup</tt> $VERSION; © 2014 Mark Wooding
319 ###--------------------------------------------------------------------------
322 INDEXDB=@pkglocalstatedir@/index.db
332 case $fs in *:*) fs=${fs%%:*} ;; esac
334 for p in "${patterns[@]}"; do
335 case $host:$fs in $p) matchp=t; break ;; esac
337 case $matchp in nil) return ;; esac
338 when=$(sqlite3 $INDEXDB \
339 "SELECT MAX(date) FROM idx WHERE host = '$host' AND fs = '$fs';")
354 jdn=$(julian "$when")
355 ago=$(( $now_jdn - $jdn ))
356 case $ago in 1 | -1) days=day ;; *) days=days ;; esac
358 -*) class=future; info="${ago#-} $days in the FUTURE" ;;
359 1 | 2) class=failed; info="$ago $days ago" ;;
360 *) class=broken; info="$ago $days ago" ;;
371 fmt hosttbl_host $host
375 fmt hosttbl_fs $host $fs $class "$info"
377 nil) failures="$failures $host:$fs" ;;
385 for fail in $failures; do
386 host=${fail%:*} fs=${fail##*:}
388 for i in "$logdir/$host/$fs.$now#"*; do
389 if [ -f "$i" ]; then log=$i; any=t; fi
391 fmt logdump_begin $host $fs
393 t) fmt logdump_file $host $fs "$log" ;;
394 nil) fmt logdump_info $host $fs "No log! No backup attempted." ;;
399 ###--------------------------------------------------------------------------
400 ### Read the configuration and we're done.
403 echo "usage: $quis [-v] [-c CONF] [-f FORMAT] [PATTERNS...]"
407 echo "$quis, rsync-backup version $VERSION"
412 while getopts "hVc:f:v" opt; do
415 V) version; config; exit 0 ;;
420 *) echo >&2 "$0: unknown format \`$OPTARG'"; exit 1 ;;
428 shift $((OPTIND - 1))
430 0) declare -a patterns=("*") ;;
431 *) declare -a patterns=("$@") ;;
434 now=$(date +"%Y-%m-%d")
435 now_time=$(date +"%H:%M:%S %z")
436 now_jdn=$(julian $now)
441 ###----- That's all, folks --------------------------------------------------