8 [ -n "$3" ] && mountdir=$3
10 [ -z "$mountdir" ] && err '$mountdir must be set'
12 rundir=${rundir:-$(dirname $0)}
14 export PATH=${rundir%/}:/bin:/usr/bin:/sbin:/usr/sbin:/sw/bin
16 if [ -z "$1" -o ! -d "$2" ]; then
19 Usage: $(basename $0) <source-dir> <relocate-dir> [<mnt-dir> [remote_user@remote_host]]
20 source-dir - Directory on backup disks to restore (relative to
22 relocate-dir - Base directory to restore files into (usually /)
23 mnt-dir - Directory where backup disk is mounted (optional)
26 # Restore everything from disks (explicitly specifying dvd mount point.)
27 % $(basename $0) / / /mnt/cdrom
29 # Restore everything from disks
32 # Restore only files under /home on disks to /home on the system
33 % $(basename $0) /home /
35 # Restore files under /home on disks to /home/home on the system
36 # (this is usually not what you want.)
37 % $(basename $0) /home /home
41 device=$(mount | grep "on ${mountdir%/} " | awk '{print$1}')
43 [ -z "$device" ] && err "Cannot determine cdrom device"
45 cp ${mountdir%/}/backups.db ${mountdir%/}/backup-status.txt $rundir
46 dbfile=${rundir%/}/backups.db
48 dates=$(cat $dbfile | list-dates.sh)
50 for date in $dates; do
52 # Check to see if files are actually needed from the current disk before requesting it.
53 cat $dbfile | files-from-date.sh $date | grep -z -Z -e "^${1%/}/" > $filelist
54 if [ -s $filelist ]; then
59 [ $? != 0 ] && err "Cannot eject the disk. Drive is busy. Run lsof $mountdir to see why."
60 echo "Please insert backup disk: $date"
61 echo "Press Enter to continue"
66 mount -t ext2 $device ${mountdir%/}
68 if grep -q $date ${mountdir%/}/backup-status.txt; then
70 elif e2label $device | grep -q $date; then
72 elif [ $loop -gt 2 ]; then
73 echo "I still can't verify the identity of the disk."
74 echo "If you are sure it is correct, press Enter to continue."
75 echo "Otherwise, press CTRL-C to abort."
79 echo "This doesn't seem to be the right disk."
84 rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress"
85 [ -z "$4" ] && cat $filelist | rsync $rsyncopts ${mountdir%/}/ ${2%/}/
86 [ -n "$4" ] && cat $filelist | rsync $rsyncopts -e ssh ${mountdir%/}/ ${4}:${2%/}/
88 echo "No files are needed from disk: $date. Skipping it."