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

Last change on this file since 998 was 998, checked in by bruno, 13 years ago

Attempt to solve #113

  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 3.3 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 "Slice = $slicename    \r"
41        echo -en "."
42        if echo "$slicename" | grep "slice-[0-9]*.00000\.dat" 2> /dev/null; then
43            CHECKSUM=`head -n1 $slicename | cut -f1`
44            OUTFNAME=`head -n1 $slicename | cut -f2`
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 "gz" > /dev/null ; then
66                gzip -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
67            elif echo "$slicename" | grep "lzo" > /dev/null ; then
68                lzop -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
69            else
70                cat $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
71            fi
72        fi
73    done
74}
75
76
77
78
79# ------------------- main -------------------
80
81trap trap_me_here SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
82[ "$#" -eq "1" ] || Die "restore-bigfiles-from-iso <location of ISOs> --- e.g. /storage/ISOs"
83isoloc=$1
84mkdir -p $MOUNTPT
85isono=1
86OUTFNAME=""
87CHECKSUM=""
88
89def="/RESTORED"
90echo -en "Restore path (default is '$def') --> "
91read restorepath
92[ "$restorepath" ] || restorepath=$def
93while [ ! -e "$isoloc/$isono.iso" ] ; do
94    echo "Skipping CD #$isono (does not exist)"
95    isono=$(($isono+1))
96    [ "$isono" -gt "50" ] && Die "Ran out of ISOs to try"
97done
98while [ -e "$isoloc/$isono.iso" ] ; do
99    echo "Processing CD #$isono"
100    mount_iso_for_me $isoloc $isono
101    process_this_cd $isono $restorepath
102    umount $isoloc/$isono.iso || Die "Unable to unmount ISO $isono"
103    isono=$(($isono+1))
104done
105echo "OK, done."
106exit 0
107
108
109
110
Note: See TracBrowser for help on using the repository browser.