#! @BASH@ ### ### Check that dumps have been made as expected. ### ### (c) 2013 Mark Wooding ### ###----- Licensing notice --------------------------------------------------- ### ### This file is part of the `rsync-backup' program. ### ### rsync-backup is free software; you can redistribute it and/or modify ### it under the terms of the GNU General Public License as published by ### the Free Software Foundation; either version 2 of the License, or ### (at your option) any later version. ### ### rsync-backup is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU General Public License for more details. ### ### You should have received a copy of the GNU General Public License ### along with rsync-backup; if not, write to the Free Software Foundation, ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. set -e quis=${0##*/} . @pkgdatadir@/lib.sh ###-------------------------------------------------------------------------- ### Stubs for the configuration file. defhook () { :; } addhook () { :; } retain () { :; } snaptype () { :; } like () { :; } retry () { :; } user () { :; } ###-------------------------------------------------------------------------- ### Output format switch. formats=: defformat () { formats=$formats$1:; } fmtstate=begin fmt () { state=$1; shift while :; do ostate=$fmtstate case $fmtstate in $state) break ;; esac case "$fmtstate,$state" in begin,end) fmtstate=end ;; begin,*) ${fmt}_header "$@" fmtstate=hosttbl_begin ;; hosttbl_begin,hosttbl_*) ${fmt}_hosttbl_begin "$@" fmtstate=hosttbl_host ;; hosttbl_host,hosttbl_fs) fmtstate=hosttbl_fs ;; hosttbl_fs,hosttbl_host) ${fmt}_hosttbl_sep "$@" fmtstate=hosttbl_host ;; hosttbl_begin,* | hosttbl_end,*) fmtstate=logdump_begin ;; hosttbl_*,*) ${fmt}_hosttbl_end "$@" fmtstate=hosttbl_end ;; logdump_begin,logdump_*) fmtstate=logdump_out ;; logdump_out,logdump_info | logdump_out,logdump_file) fmtstate=$state ;; logdump_*,logdump_begin) ${fmt}_logdump_end "$@" fmtstate=logdump_begin ;; logdump_end,*) fmtstate=footer ;; logdump_*,*) fmtstate=logdump_end ;; footer,end) ${fmt}_footer "$@" fmtstate=end ;; esac case $fmtstate in "$ostate") echo >&2 "$quis: FATAL! NO PROGRESS IN FMT STATE MACHINE" exit 9 ;; esac done ${fmt}_$fmtstate "$@" } ###-------------------------------------------------------------------------- ### Plain text output. defformat txt txt_header () { :; } txt_hosttbl_begin () { :; } txt_hosttbl_host () { echo "HOST $1"; } txt_hosttbl_fs () { printf " %-23s %s\n" "$2" "$4"; } txt_hosttbl_sep () { echo; } txt_hosttbl_end () { :; } txt_logdump_begin () { cat < $now rsync-backup report

rsync-backup report: $now_dow $now

EOF } html_hosttbl_begin () { cat <Overview EOF } html_hosttbl_host () { cat < $1 EOF } html_hosttbl_fs () { case $3 in winning) link="" knil="" ;; *) link="" knil="" ;; esac cat < $2 $link$4$knil EOF } html_hosttbl_sep () { cat < EOF } html_hosttbl_end () { cat < EOF } html_logdump_begin () { cat <Log tail for $1:$2 EOF } html_logdump_info () { cat <$3 EOF } html_logdump_file () { cat < $3 EOF cat "$3" cat < EOF } html_logdump_end () { :; } html_footer () { cat < Checked at $now $now_time
rsync-backup $VERSION; © 2014 Mark Wooding EOF } html_end () { :; } ###-------------------------------------------------------------------------- ### Main checking. INDEXDB=@pkglocalstatedir@/index.db host () { host=$1; } patterns= showhost= failures= backup () { for fs in "$@"; do case $fs in *:*) fs=${fs%%:*} ;; esac matchp=nil for p in "${patterns[@]}"; do case $host:$fs in $p) matchp=t; break ;; esac done case $matchp in nil) return ;; esac when=$(sqlite3 -batch -list -separator \| -noheader $INDEXDB \ "SELECT MAX(date) FROM idx WHERE host = '$host' AND fs = '$fs';") case $when in "") class=never info="NEVER" show=t win=nil ;; "$now") class=winning info="today" show=$verbose win=t ;; *) jdn=$(julian "$when") ago=$(( $now_jdn - $jdn )) case $ago in 1 | -1) days=day ;; *) days=days ;; esac case $ago in -*) class=future; info="${ago#-} $days in the FUTURE" ;; 1 | 2) class=failed; info="$ago $days ago" ;; *) class=broken; info="$ago $days ago" ;; esac show=t win=nil ;; esac case $show in t) case $showhost in "$host") ;; *) fmt hosttbl_host $host showhost=$host ;; esac fmt hosttbl_fs $host $fs $class "$info" case $win in nil) failures="$failures $host:$fs" ;; esac ;; esac done } failure_logs () { for fail in $failures; do host=${fail%:*} fs=${fail##*:} any=nil for i in "$logdir/$host/$fs.$now#"*; do if [ -f "$i" ]; then log=$i; any=t; fi done fmt logdump_begin $host $fs case $any in t) fmt logdump_file $host $fs "$log" ;; nil) fmt logdump_info $host $fs "No log! No backup attempted." ;; esac done } ###-------------------------------------------------------------------------- ### Read the configuration and we're done. usage () { echo "usage: $quis [-v] [-c CONF] [-f FORMAT] [PATTERNS...]" } version () { echo "$quis, rsync-backup version $VERSION" } verbose=nil while getopts "hVc:f:v" opt; do case "$opt" in h) usage; exit 0 ;; V) version; config; exit 0 ;; c) conf=$OPTARG ;; f) case $formats in *":$OPTARG:"*) ;; *) echo >&2 "$0: unknown format \`$OPTARG'"; exit 1 ;; esac fmt=$OPTARG ;; v) verbose=t ;; *) exit 1 ;; esac done shift $((OPTIND - 1)) case $# in 0) declare -a patterns=("*") ;; *) declare -a patterns=("$@") ;; esac now=$(date +"%Y-%m-%d") now_time=$(date +"%H:%M:%S %z") now_dow=$(date +"%A") now_jdn=$(julian $now) . "$conf" failure_logs fmt end ###----- That's all, folks --------------------------------------------------