source: MondoRescue/branches/stable/mondo/mondo/restore-scripts/mondo/restore-bigfiles-from-iso@ 567

Last change on this file since 567 was 567, checked in by bcornec, 18 years ago

Same for mondo: setup modes correctly in SVN and get rid of %attr an %defattr in spec files to get correct packages

  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 3.1 KB
RevLine 
[1]1#!/bin/sh
2
3
4MOUNTPT=/tmp/mojo-jojo-iso
5
6Die() {
7 echo "$1" >> /dev/stderr
8 exit 1
9}
10
11
12mount_iso_for_me() {
13 [ -e "$1/$2.iso" ] || Die "ISO #$2 not found at $1. Terminating."
14 mount $1/$2.iso -o loop,ro $MOUNTPT || Die "Cannot mount ISO $isoloc/$isono"
15}
16
17
18
19trap_me_here() {
20 i=1
21 while [ "$i" -le "50" ] ; do
22 umount $isoloc/$i.iso 2> /dev/null
23 i=$(($i+1))
24 done
25 echo "Terminating in reponse to a signal caught by the OS"
26 exit 1
27}
28
29
30
31process_this_cd() {
32 local restorepath res
33 isono=$1
34 restorepath=$2
35
36 find $MOUNTPT/archives | grep "slice-" > /dev/null || Die "No bigfiles at $MOUNTPT"
37 mkdir -p $restorepath
38 cd $restorepath
39 for slicename in `find $MOUNTPT/archives | grep "slice-" | sort` ; do
40# echo -en "Slice = $slicename \r"
41 echo -en "."
42 if echo "$slicename" | grep "slice-[0-9]*.00000\.dat" 2> /dev/null; then
[273]43 CHECKSUM=`head -n1 $slicename | cut -f1`
44 OUTFNAME=`head -n1 $slicename | cut -f2`
[1]45 OUTFNAME=`echo "$restorepath/$OUTFNAME" | tr -s '/' '/'`
46 echo "Now restoring $OUTFNAME"
47 [ "$OUTFNAME" ] || Die "No filename?! WTF?"
48 rm -f "$OUTFNAME" 2> /dev/null
49 mkdir -p "$OUTFNAME" 2> /dev/null
50 rmdir "$OUTFNAME" 2> /dev/null
51 > "$OUTFNAME" || Die "Cannot write to $OUTFNAME"
52 elif [ ! -s "$slicename" ] ; then
53 echo "Finished restoring $OUTFNAME"
54 res=`md5sum "$OUTFNAME" | cut -d' ' -f1`
55# echo "Orig=$CHECKSUM. Disk=$res"
56 if [ "$CHECKSUM" != "$res" ] ; then
57 echo "Warning - checksums do not match"
58 fi
59 CHECKSUM=""
60 OUTFNAME=""
61 else
62 [ "$OUTFNAME" = "" ] && Die "No filename to write to! Are you sure you inserted the _first_ ISO to begin with?"
63 if echo "$slicename" | grep "bz2" > /dev/null ; then
64 bzip2 -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
65 elif echo "$slicename" | grep "lzo" > /dev/null ; then
66 lzop -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
67 else
68 cat $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
69 fi
70 fi
71 done
72}
73
74
75
76
77# ------------------- main -------------------
78
79trap trap_me_here SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
80[ "$#" -eq "1" ] || Die "restore-bigfiles-from-iso <location of ISOs> --- e.g. /storage/ISOs"
81isoloc=$1
82mkdir -p $MOUNTPT
83isono=1
84OUTFNAME=""
85CHECKSUM=""
86
87def="/RESTORED"
88echo -en "Restore path (default is '$def') --> "
89read restorepath
90[ "$restorepath" ] || restorepath=$def
91while [ ! -e "$isoloc/$isono.iso" ] ; do
92 echo "Skipping CD #$isono (does not exist)"
93 isono=$(($isono+1))
94 [ "$isono" -gt "50" ] && Die "Ran out of ISOs to try"
95done
96while [ -e "$isoloc/$isono.iso" ] ; do
97 echo "Processing CD #$isono"
98 mount_iso_for_me $isoloc $isono
99 process_this_cd $isono $restorepath
100 umount $isoloc/$isono.iso || Die "Unable to unmount ISO $isono"
101 isono=$(($isono+1))
102done
103echo "OK, done."
104exit 0
105
106
107
108
Note: See TracBrowser for help on using the repository browser.