#!/bin/bash THIS=`basename $0` COLUMNS=$(stty size 2>/dev/null||echo 80); COLUMNS=${COLUMNS##* } while getopts ":qfh" optname; do case "$optname" in "f") FORCE="y";; "q") QUIET="y"; RDIFFBACKUPOPTIONS="--terminal-verbosity 0";; "h") HELP="y";; "?") echo "Unknown option $OPTARG"; exit 1;; ":") echo "No argument value for option $OPTARG"; exit 1;; *) # Should not occur echo "Unknown error while processing options"; exit 1;; esac done shift $(($OPTIND-1)) if [ -z "$QUIET" -o -n "$HELP" -o -z "$1" ]; then echo -en "\n$THIS v0.1216 by Dominic address@hidden" [ -z "$HELP" -a -n "$1" ] && echo -n " (-h for help)" echo -e "\n${THIS//?/=}\n" fi if [ -n "$HELP" -o -z "$1" ]; then echo -e "Forces regression of an rdiff-backup archive even if natural regression does not occur. Can be useful if a repository is corrupted and regression is neither automatic nor can be initiated with --check-destination-dir.\n\nUsage: \t$THIS [options] archive-path\nExample: \t$THIS -f /home/fred/backup\nOptions:\tf - Force, proceed with no prompt\n\t\th - Help, this help text\n\t\tq - Quiet, no output unless error\n"|fold -s -w $COLUMNS exit fi if [ ! -d "$1" ]; then echo "Cannot find directory \"$1\", aborting..." exit 1 fi ARCHIVE=$1 if [ ! -d "$ARCHIVE/rdiff-backup-data" ]; then echo "$ARCHIVE does not appear to be a valid rdiff-backup repository, aborting..." exit 1 fi [ -z "$QUIET" ] && echo "Using repository: $ARCHIVE" WHENLAST=`ls $ARCHIVE/rdiff-backup-data/current_mirror*|sed 's/.*current_mirror\.\([^.]*\).*/\1/'` NUMCURRENT=`echo $WHENLAST|awk '{print NF}'` if [ $NUMCURRENT -ne 2 ]; then if [ $NUMCURRENT -ne 1 ]; then echo "$NUMCURRENT current_mirror files, aborting..." exit 1 else [ -z "$QUIET" ] && echo "rdiff-backup does not recognise this repository as damaged" fi else [ -z "$QUIET" ] && echo "rdiff-backup recognises this repository as damaged" fi PREVRUN=`ls $ARCHIVE/rdiff-backup-data/mirror_metadata*|tail -n2|head -n1|sed 's/.*mirror_metadata\.\([^.]*\).*/\1/'` if [ -z "$FORCE" ]; then read -n 1 -t 30 -p "About to regress $ARCHIVE repository from $WHENLAST to $PREVRUN: ok (y/-)? " [ "$REPLY" != "y" ] && echo " - aborting..." && exit 1 fi [ -z "$QUIET" ] && echo -e "\nStarted `date`" if [ $NUMCURRENT -eq 1 ]; then cp -a "$ARCHIVE/rdiff-backup-data/current_mirror.$WHENLAST.data" "$ARCHIVE/rdiff-backup-data/current_mirror.$PREVRUN.data" [ -z "$QUIET" ] && echo "Copied current_mirror" fi [ -z "$QUIET" ] && echo "Regressing, this may take a long time, please be patient..." rdiff-backup $RDIFFBACKUPOPTIONS --check-destination-dir $ARCHIVE [ -z "$QUIET" ] && echo "Ended `date`" [ -z "$QUIET" ] && [ $? -eq 0 ] && echo "Regression completed successfully, current mirror is now $PREVRUN" || echo "There was an error while attempting to regress repository..." REQOWNER=`ls -dl "$ARCHIVE/rdiff-backup-data/increments"|awk '{print $3":"$4}'` THISOWNER=`ls -l "$ARCHIVE/rdiff-backup-data/mirror_metadata.$PREVRUN.snapshot.gz"|awk '{print $3":"$4}'` if [ "$THISOWNERS" != "$REQOWNER" ]; then chown $REQOWNER "$ARCHIVE/rdiff-backup-data/mirror_metadata.$PREVRUN.snapshot.gz" chown $REQOWNER "$ARCHIVE/rdiff-backup-data/current_mirror.$PREVRUN.data" fi