#! /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 getyn() { echo -n "$0:" $* " [Y/n]? " read case $REPLY in ''|y*|Y*) REPLY=y;; *) REPLY=n;; esac } help() { cat <&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 $prologue_hook test -z "$epilogue_hook" && trap "$epilogue_hook" EXIT INT QUIT TERM # Guess missing values if [ -z "$week" ]; then hour=$(date +%H) if [ $hour -gt 6 ]; then week=$(date +%U) else week=$(date -d yesterday +%U) fi fi if [ -z "$round" ]; then round=$(find $backup_archive_dir \ -regex '.*-'$week'-[0-9][0-9]*-[0-9][0-9]*\..*' \ -printf '%f\n' | sed 's/.*-'$week'-\([0-9][0-9]*\)-[0-9][0-9]*\..*/\1/' | sort +0 -1 | tail -1) fi if [ -z "$level" ]; then level=$(find $backup_archive_dir \ -regex '.*-'$week-$round'-[0-9][0-9]*\..*' \ -printf '%f\n' | sed 's/.*-'$week-$round'-\([0-9][0-9]*\)\..*/\1/' | sort +0 -1 | tail -1) 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 logit "started" for item in $items do eval type=\$${item}_type ${type}_restore $item done $epilogue_hook trap '' EXIT INT QUIT TERM logit "finished"