#!/bin/ksh #< recover: take results of searching *.new, restore files. PATH=/bin:/usr/bin:/usr/local/bin export PATH : ${TMPDIR="/tmp"} tag=`basename $0` # We need something to look for. case "$#" in 0) echo need something to restore; exit 1 ;; *) pattern="$1" ;; esac # Make a work directory. { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/rcXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" } || { echo "$tag: mktemp failed in $TMPDIR" >&2 exit 1 } # For testing: in production, go to the directory you want to search. ## cd /backup/inc/2009/0404 cwd=`pwd` cd $tmp grep $pattern $cwd/*.new | cat -n | sed -e 's!.new:\.*/!.pax.gz !' | while read k pfile target do gunzip -c $pfile | pax -r $target b=`basename $target` mv $target $b.$k done echo results in $tmp exit 0