Merge branch 'master' of home:dvl/backup
authorCarl N Baldwin <cnb@hpsvcnb.fc.hp.com>
Tue, 25 Oct 2005 22:14:53 +0000 (16:14 -0600)
committerCarl N Baldwin <cnb@hpsvcnb.fc.hp.com>
Tue, 25 Oct 2005 22:14:53 +0000 (16:14 -0600)
scripts/Makefile.am
scripts/drive.sh
scripts/find-cmd.sh [deleted file]
scripts/restore-header.sh [new file with mode: 0755]
scripts/restore-script.sh [changed mode: 0644->0755]
scripts/rsync-cmd.sh [deleted file]

index 2afda8723b96e31e92fd516013f87dae88a278f1..ba618aaa3f466883c1274f3456f9e7a3f200bb42 100644 (file)
@@ -1,9 +1,22 @@
 bin_SCRIPTS = \
        drive.sh \
        files-from-date.sh \
-       find-cmd.sh \
        list-dates.sh \
        restore-script.sh \
-       rsync-cmd.sh
+       restore.sh
 
-EXTRA_DIST = $(bin_SCRIPTS)
+EXTRA_DIST = $(bin_SCRIPTS) restore-header.sh
+
+restore_scripts = \
+       files-from-date.sh \
+       list-dates.sh \
+       restore-script.sh
+
+restore_tar = restore.tgz
+
+restore.sh : restore-header.sh $(restore_tar)
+       { cat $<; cat $(restore_tar); } > $@
+       chmod +x $@
+
+$(restore_tar) : $(restore_scripts)
+       tar cf - $^ | gzip > $@
index 1693212a8c5b422e9b229b2e9583b73beed1df78..0b0268933ac5c18d1e0c80c350870558bdd55cd0 100755 (executable)
@@ -15,6 +15,7 @@ backups="$tmpdir/backup-list.db"
 statusfile="$tmpdir/backup-status.txt"
 isomountdir="/backup/iso-mount"
 isoimage="/backup/iso-mount.iso"
+restorescript="$scriptsdir/restore.sh"
 
 echo "Creating the iso image in $isoimage"
 touch $isoimage
@@ -34,7 +35,12 @@ chmod 700 $tmpdir
 touch $currentfiles
 chmod 600 $currentfiles
 echo "Running find to get the status of files"
-find-cmd.sh /home > $currentfiles
+{
+  for type in d f l; do
+    findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0"
+    find /home -type $type -printf "$findformat"
+  done
+} > $currentfiles
 
 echo "Determining list of files to backup with lsbackups"
 {
@@ -44,10 +50,11 @@ echo "Determining list of files to backup with lsbackups"
 } | lsbackups > $backups 2>$statusfile
 
 echo "Running rsync to pack the image"
-cat $backups | rsync-cmd.sh $isomountdir
+rsyncopts="-l -p -t -g -o -0 --files-from=- --stats --progress"
+cat $backups | rsync $rsyncopts / $isomountdir
 
 echo "Copying over database and status file"
-cp $statusfile $backupdb $isomountdir
+cp $statusfile $backupdb $restorescript $isomountdir
 
 # umount $isomountdir
 
diff --git a/scripts/find-cmd.sh b/scripts/find-cmd.sh
deleted file mode 100755 (executable)
index 51a3749..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-[ $# == 1 ] || exit 1
-
-{
-  for type in d f l; do
-    find $1 -type $type -printf "$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0"
-  done
-}
diff --git a/scripts/restore-header.sh b/scripts/restore-header.sh
new file mode 100755 (executable)
index 0000000..a147c62
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+export rundir=/tmp/restore-$(date +%Y%m%d%H%M%S)
+if ! mkdir $rundir; then
+  echo >&2 "Cannot create temp dir"
+  exit 1
+fi
+
+unset CDPATH
+export mountdir=$(cd $(dirname $0) && pwd)
+
+SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`
+
+# take the archive portion of this file and pipe it to tar
+tail +$SKIP $0 | tar xzf - -C $rundir
+
+exec $rundir/restore-script.sh ${1+"$@"}
+
+__ARCHIVE_FOLLOWS__
old mode 100644 (file)
new mode 100755 (executable)
index 402bb84..1bf8dcc
@@ -1,24 +1,34 @@
 #!/bin/sh
 
+export PATH=$rundir:/bin:/usr/bin
+
 if [ $# != 1 ]; then
-  echo >&2 "Usage: $0 <target-directory>"
-  echo >&2 "Example: $0 /"
+  echo >&2 "Usage: $0 <source-directory> <target-directory>"
+  echo >&2 "Example: $0 / /"
   exit 1
 fi
 
-tmpdir=/tmp/restore-$(date +%Y%m%d%H%M%S)
-
-export PATH=$tmpdir:/bin:/usr/bin
+device=$(mount | grep "on $mountdir " | awk '{print$1}')
 
-# Get the device with the CD in it here
-device=/dev/hdc
+cp $mountdir/backups.db $mountdir/backup-status.txt $rundir
+dbfile=$rundir/backups.db
 
 for date in $(cat $dbfile | list-dates.sh); do
-  eject $device
-  echo >&2 "Please insert backup disk:  $date"
-  echo >&2 "Then press any key"
-  read bogus
-  # Mount the media
-  # rsync-cmd.sh won't work here in its current encarnation
-  cat $dbfile | files-from-date.sh | rsync-cmd.sh $1
+  success=false
+  while ! $success; do
+    eject $device
+    echo >&2 "Please insert backup disk:  $date"
+    read bogus
+
+    # Mount the media
+    mount -t ext2 $device $mountdir
+    if [ "" != "$(grep -l $date $mountdir/backup-status.txt)" ]; then
+      success=true
+    else
+      echo >&2 "This doesn't seem to be the right disk."
+    fi
+  done
+
+  rsyncopts="-l -p -t -g -o -0 --files-from=- --stats --progress "
+  cat $dbfile | files-from-date.sh | rsync $rsyncopts $1 $2
 done
diff --git a/scripts/rsync-cmd.sh b/scripts/rsync-cmd.sh
deleted file mode 100755 (executable)
index aa7e9f7..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-# This file just has some ideas about how to do the rsync command with the list
-# of file produced by lsbackups
-
-[ $# == 1 ] || exit 1
-[ -d $1   ] || exit 1
-
-# -H ? -W ?
-rsync_opts='-W -H -l -p -t -g -o -0 --files-from=-'
-
-other_opts='--stats --progress'
-
-# Should also include directories in there
-rsync $rsync_opts $other_opts / $1