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;
227 pre.logdump { max-height: 120ex; }
229 .hide { display: none; }
233 font-weight: initial;
241 border: solid thin black;
244 <script type='text/javascript'><!--
245 var LAST_EXPAND = null;
246 function elt(id) { return document.getElementById(id); }
247 function elt_class_p(elt, cls) {
248 return elt.className.match('\\\\b' + cls + '\\\\b');
250 function add_elt_class(elt, cls) {
251 if (!elt_class_p(elt, cls)) elt.className += ' ' + cls;
253 function rm_elt_class(elt, cls) {
254 elt.className = elt.className.replace(
255 new RegExp('\\\\s*\\\\b' + cls + '\\\\b\\\\s*'), ' ');
257 function toggle_expand(ev, tag) {
258 var d = elt('logdump-' + tag);
259 var b = elt('expand-' + tag);
260 if (elt_class_p(d, 'hide')) do_show(d, b);
264 function do_show(d, b) {
265 rm_elt_class(d, 'hide');
266 b.textContent = '[hide]';
268 function do_hide(d, b) {
269 add_elt_class(d, 'hide');
270 b.textContent = '[show]';
271 if (LAST_EXPAND !== null && d === LAST_EXPAND[0])
274 function expand_log(tag) {
275 if (LAST_EXPAND !== null) do_hide(LAST_EXPAND[0], LAST_EXPAND[1]);
276 var d = elt('logdump-' + tag);
277 var b = elt('expand-' + tag);
278 if (elt_class_p(d, 'hide')) {
279 LAST_EXPAND = [d, b];
283 function make_toggle_button(tag) {
285 "<a class=expand-button id='expand-" + tag + "' href='#' " +
286 "onclick='toggle_expand(event, \"" + tag + "\")'>" +
290 function hide_logdump(tag) {
291 add_elt_class(elt('logdump-' + tag), 'hide');
297 <h1><tt>rsync-backup</tt> report: $now_dow $now</tt></h1>
301 html_hosttbl_begin () {
308 html_hosttbl_host () {
310 <table class=hosttbl>
311 <tr class=host><td colspan=2>$1</tc>
317 winning) link="" knil="" ;;
319 link="<a href='#log-$host:$fs' onclick='expand_log(\"$host:$fs\")'>"
326 <td class=$3>$link$4$knil</td>
330 html_hosttbl_sep () {
336 html_hosttbl_end () {
342 html_logdump_begin () {
345 <h2 id='log-$1:$2'><a name='log-$1:$2'>Log tail for <tt>$1:$2</tt></a>
346 <script type='text/javascript'><!--
347 make_toggle_button('$1:$2');
352 html_logdump_info () {
354 <div id='logdump-$1:$2' class=logdump-info><script type='text/javascript'><!--
355 hide_logdump('$1:$2');
360 html_logdump_file () {
362 <pre id='logdump-$1:$2' class=logdump>
363 <script type='text/javascript'><!--
364 hide_logdump('$1:$2');
373 html_logdump_end () { :; }
379 Checked at $now $now_time<br>
380 <tt>rsync-backup</tt> $VERSION; © 2014 Mark Wooding
390 ###--------------------------------------------------------------------------
393 INDEXDB=@pkglocalstatedir@/index.db
403 case $fs in *:*) fs=${fs%%:*} ;; esac
405 for p in "${patterns[@]}"; do
406 case $host:$fs in $p) matchp=t; break ;; esac
408 case $matchp in nil) return ;; esac
409 when=$(sqlite3 $INDEXDB \
410 "SELECT MAX(date) FROM idx WHERE host = '$host' AND fs = '$fs';")
425 jdn=$(julian "$when")
426 ago=$(( $now_jdn - $jdn ))
427 case $ago in 1 | -1) days=day ;; *) days=days ;; esac
429 -*) class=future; info="${ago#-} $days in the FUTURE" ;;
430 1 | 2) class=failed; info="$ago $days ago" ;;
431 *) class=broken; info="$ago $days ago" ;;
442 fmt hosttbl_host $host
446 fmt hosttbl_fs $host $fs $class "$info"
448 nil) failures="$failures $host:$fs" ;;
456 for fail in $failures; do
457 host=${fail%:*} fs=${fail##*:}
459 for i in "$logdir/$host/$fs.$now#"*; do
460 if [ -f "$i" ]; then log=$i; any=t; fi
462 fmt logdump_begin $host $fs
464 t) fmt logdump_file $host $fs "$log" ;;
465 nil) fmt logdump_info $host $fs "No log! No backup attempted." ;;
470 ###--------------------------------------------------------------------------
471 ### Read the configuration and we're done.
474 echo "usage: $quis [-v] [-c CONF] [-f FORMAT] [PATTERNS...]"
478 echo "$quis, rsync-backup version $VERSION"
483 while getopts "hVc:f:v" opt; do
486 V) version; config; exit 0 ;;
491 *) echo >&2 "$0: unknown format \`$OPTARG'"; exit 1 ;;
499 shift $((OPTIND - 1))
501 0) declare -a patterns=("*") ;;
502 *) declare -a patterns=("$@") ;;
505 now=$(date +"%Y-%m-%d")
506 now_time=$(date +"%H:%M:%S %z")
507 now_dow=$(date +"%A")
508 now_jdn=$(julian $now)
513 ###----- That's all, folks --------------------------------------------------