diff options
Diffstat (limited to 'restore.in')
-rw-r--r-- | restore.in | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/restore.in b/restore.in new file mode 100644 index 0000000..c112cb6 --- /dev/null +++ b/restore.in @@ -0,0 +1,167 @@ +#! /bin/bash + +libdir=@LIBDIR@/backup +set -e +. $libdir/common.sh +set +e + +load_config +taroptions="$backup_tar_options $backup_rsh_command" + +# Options +root=/ +verbose= +logfile= +dry_run= +listonly= +confirm=1 + +guess_round() { + case $1 in + Sun|Mon|Tue) + round=0;; + Wed|Thu) + round=1;; + Fri|Sat) + round=2;; + *) + echo >&2 "$0: invalid day of week ($1)" + exit 1 + esac +} + +guess_level() { + case $1 in + Sun) + level=0;; + Mon|Wed|Fri) + level=1;; + Tue|Thu|Sat) + level=2;; + *) + echo >&2 "$0: invalid day of week ($1)" + exit 1 + esac +} + +getyn() { + echo -n "$0:" $* " [Y/n]? " + read + case $REPLY in + ''|y*|Y*) REPLY=y;; + *) REPLY=n;; + esac +} + +help() { + cat <<EOT +usage: restore [OPTIONS] [ITEM [ITEM...]] +restores this system from a backup + +OPTIONS: + -c, --confirm do not ask for confirmation; run straight into restoring + -C, --directory DIR restore into directory DIR instead of $root + -v, --verbose increase verbosity + -n, --dry-run do nothing, print what would have been done + -t, --list list archives, instead of extracting + -l, --logfile FILE log to FILE + -L, --level N set incremental dump level to stop at + -R, --round N use archives from incremental round N + -W, --week N use archives from week N + -h, --help produce this help list + +Valid ITEMs are: $backup_items +EOT + exit 0 +} + +while [ $# -ne 0 ] +do + case $1 in + -C|--directory) shift; root=$1;; + -c|--confirm) confirm=0;; + -v|--verbose) verbose="$verbose -v";; + -t|--list) listonly=1;; + -l|--logfile) shift; logfile=$1; confirm=0;; + -n|--dry-run) dry_run=echo;; + -h|--help) help;; + -L|--level) shift; level=$1;; + -R|--round) shift; round=$1;; + -W|--week) shift; week=$1;; + --) shift; break;; + -*) echo >&2 "$0: unrecognized option $1"; exit 1;; + *) break;; + esac + shift +done + +if [ -z "$listonly" ]; then + taroptions="$taroptions -x" +else + taroptions="$taroptions -t" +fi + +# Collect items to be restored. +items=$* + +test -z "$items" && items="$backup_items" + +if [ -n "$logfile" ]; then + confirm=0 + exec >>$logfile + exec 2>&1 +fi + +# Verify option consistency, guess missing values +hour=$(date +%H) +if [ $hour -gt 6 ]; then + thisweek=$(date +%U) + yestreen=$(date +%a) +else + thisweek=$(date -d yesterday +%U) + yestreen=$(date -d yesterday +%a) +fi + +if [ -z "$week" ]; then + week=$thisweek +fi +if [ -z "$round" ]; then + if [ $week = $thisweek ]; then + guess_round $yestreen + else + round=2 + fi +fi +if [ -z "$level" ]; then + if [ $week = $thisweek ]; then + guess_level $yestreen + else + # FIXME: A better guess? + level=2 + fi +fi + +echo "$0: target root directory $root" +echo "$0: items to be restored: $items" +echo "$0: restoring from week $week, round $round, level $level" + +if [ $confirm -ne 0 ]; then + getyn "Do you wish to proceed" + test $REPLY = "n" && exit 0 +fi + +$prologue_hook + +logit "started" + +for item in $items +do + eval type=\$${item}_type + ${type}_restore $item +done + +$epilogue_hook + +logit "finished" + + |