Should always run from installed directory
[backups/.git] / scripts / restore-script.sh
1 #!/bin/sh
2
3 export PATH=$rundir:/bin:/usr/bin
4
5 if [ $# != 1 ]; then
6   echo >&2 "Usage: $0 <source-directory> <target-directory>"
7   echo >&2 "Example: $0 / /"
8   exit 1
9 fi
10
11 device=$(mount | grep "on $mountdir " | awk '{print$1}')
12
13 cp $mountdir/backups.db $mountdir/backup-status.txt $rundir
14 dbfile=$rundir/backups.db
15
16 for date in $(cat $dbfile | list-dates.sh); do
17   success=false
18   while ! $success; do
19     eject $device
20     echo >&2 "Please insert backup disk:  $date"
21     read bogus
22
23     # Mount the media
24     mount -t ext2 $device $mountdir
25     if [ "" != "$(grep -l $date $mountdir/backup-status.txt)" ]; then
26       success=true
27     else
28       echo >&2 "This doesn't seem to be the right disk."
29     fi
30   done
31
32   rsyncopts="-l -p -t -g -o -0 --files-from=- --stats --progress "
33   cat $dbfile | files-from-date.sh | rsync $rsyncopts $1 $2
34 done