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

Last change on this file since 1193 was 1193, checked in by Bruno Cornec, 17 years ago

Remove some useless \r in code
Remove center_string usage as it's now broiken for dynamically created strings

  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 3.2 KB
Line 
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 "."
41 if echo "$slicename" | grep "slice-[0-9]*.00000\.dat" 2> /dev/null; then
42 CHECKSUM=`head -n1 $slicename | cut -f1`
43 OUTFNAME=`head -n1 $slicename | cut -f2`
44 OUTFNAME=`echo "$restorepath/$OUTFNAME" | tr -s '/' '/'`
45 echo "Now restoring $OUTFNAME"
46 [ "$OUTFNAME" ] || Die "No filename?! WTF?"
47 rm -f "$OUTFNAME" 2> /dev/null
48 mkdir -p "$OUTFNAME" 2> /dev/null
49 rmdir "$OUTFNAME" 2> /dev/null
50 > "$OUTFNAME" || Die "Cannot write to $OUTFNAME"
51 elif [ ! -s "$slicename" ] ; then
52 echo "Finished restoring $OUTFNAME"
53 res=`md5sum "$OUTFNAME" | cut -d' ' -f1`
54# echo "Orig=$CHECKSUM. Disk=$res"
55 if [ "$CHECKSUM" != "$res" ] ; then
56 echo "Warning - checksums do not match"
57 fi
58 CHECKSUM=""
59 OUTFNAME=""
60 else
61 [ "$OUTFNAME" = "" ] && Die "No filename to write to! Are you sure you inserted the _first_ ISO to begin with?"
62 if echo "$slicename" | grep "bz2" > /dev/null ; then
63 bzip2 -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
64 elif echo "$slicename" | grep "gz" > /dev/null ; then
65 gzip -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
66 elif echo "$slicename" | grep "lzo" > /dev/null ; then
67 lzop -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
68 else
69 cat $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
70 fi
71 fi
72 done
73}
74
75
76
77
78# ------------------- main -------------------
79
80trap trap_me_here SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
81[ "$#" -eq "1" ] || Die "restore-bigfiles-from-iso <location of ISOs> --- e.g. /storage/ISOs"
82isoloc=$1
83mkdir -p $MOUNTPT
84isono=1
85OUTFNAME=""
86CHECKSUM=""
87
88def="/RESTORED"
89echo -en "Restore path (default is '$def') --> "
90read restorepath
91[ "$restorepath" ] || restorepath=$def
92while [ ! -e "$isoloc/$isono.iso" ] ; do
93 echo "Skipping CD #$isono (does not exist)"
94 isono=$(($isono+1))
95 [ "$isono" -gt "50" ] && Die "Ran out of ISOs to try"
96done
97while [ -e "$isoloc/$isono.iso" ] ; do
98 echo "Processing CD #$isono"
99 mount_iso_for_me $isoloc $isono
100 process_this_cd $isono $restorepath
101 umount $isoloc/$isono.iso || Die "Unable to unmount ISO $isono"
102 isono=$(($isono+1))
103done
104echo "OK, done."
105exit 0
106
107
108
109
Note: See TracBrowser for help on using the repository browser.