]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/usb/src/scripts/restore/full_disk
Add new usb rescue key code
[bacula/rescue] / rescue / linux / usb / src / scripts / restore / full_disk
1 #!/bin/sh
2                                 
3 if [ -f nozen ]; then 
4 DIALOG=dialog
5 else
6 DIALOG=Xdialog
7 fi
8                                 
9 MB=MB                           part=`echo $disk|cut -d"/" -f3`
10                                 fdisk -l /dev/$part |grep bytes|grep -v Units|awk '{print $5}'>samesize
11                                 cat working/diskinfo/fdisk.$part |grep bytes|grep -v Units|awk '{print $5}'>samesize2
12                                 diff samesize samesize2 >/dev/null 2>&1
13                         if [ ! $? = 0 ] ;then
14                                 nowdisk=`cat samesize`
15                                 oldisk=`cat samesize2`
16                                 $DIALOG --title "different disk" --msgbox "The size of the disk you are trying to restore \n and the one we have backed up differ for /dev/$part  \n \n The old disk size was  $oldisk  \n And the actual disk size is  $nowdisk \n \n We'll have to do things manually" 600 600
17                                 oldiskparted=`cat working/diskinfo/parted.$part`
18                                 howmanyparts=`cat working/diskinfo/parted.$part|wc -l`
19                                 howmanyparts=$(( $howmanyparts - 7 ))
20                                         $DIALOG --title "different disk" --yesno "Do you want to do it manually \n ( we will launch gparted) (yes) \n Or only adjust the LAST partition size to fit the disk ? \n (We only shrink the las partition, it will not claim empty space on the drive) (no)" 600 600
21                                         if [ $? = 0 ];then
22                                           if [ $DIALOG = Xdialog ];then
23                                           echo $$oldiskparted
24                                           $DIALOG --title "different disk" --msgbox "the old partition sizes for this disk was \n \n $oldiskparted \n \n We will now launch gparted so you can adjust you disk partitions " 600 600
25                                 gparted /dev/$part
26                                           else
27                                 $DIALOG --title "different disk" --msgbox "the old partition sizes for this disk was \n \n $oldiskparted \n \n please use fdisk or cfdisk to repartition your drive \n \n and the re-run this script pointing to the partitions of the new disks  \n (like /dev/sda1 ) instead of the whole disk (/dev/sda)" 600 600
28                                           exit 1
29                                           fi
30                                         else
31
32                                         a=` sfdisk -n /dev/$part < working/diskinfo/sfdisk.make.$part.bsi 2>&1`
33                                         echo $a > tmp
34                                         grep exceed tmp >/dev/null 2>&1
35                                                if [ $? = 0 ];then
36                                                tr ' ' '\n' < tmp >tmp2
37                                                cat tmp2|awk /given/,/sfdisk/ >tmp3
38                                                currentsize=`cat tmp3|grep -m1 "("|cut -d"(" -f2 |cut -d")" -f1`
39                                                maxsize=`cat tmp3|grep -m2 "("|cut -d"(" -f2 |cut -d")" -f1|tail -n1`
40                                                sed -i "s/$currentsize/$maxsize/g" working/diskinfo/sfdisk.make.$part.bsi
41                                                nowarn=1
42                                                   while [ $nowarn = 1 ];do
43                                                   a=` sfdisk -n /dev/$part < working/diskinfo/sfdisk.make.$part.bsi 2>&1`
44                                                   echo $a > tmp
45                                                  grep exceed tmp >/dev/null 2>&1
46                                                         if [ $? = 0 ];then
47                                                         tr ' ' '\n' < tmp >tmp2
48                                                         cat tmp2|awk /given/,/sfdisk/ >tmp3
49                                                         currentsize=`cat tmp3|grep -m1 "("|cut -d"(" -f2 |cut -d")" -f1`
50                                                         maxsize=`cat tmp3|grep -m2 "("|cut -d"(" -f2 |cut -d")" -f1|tail -n1`
51                                                         sed -i "s/$currentsize/$maxsize/g" working/diskinfo/sfdisk.make.$part.bsi
52                                                         else
53                                                         nowarn=0
54                                                         fi
55                                                   done
56                                                 partprobe /dev/$part >/dev/null 2>&1
57                                                 . ./unmount-all
58                                                 sfdisk /dev/$part < working/diskinfo/sfdisk.make.$part.bsi
59                                                 rm tmp
60                                                 rm tmp2
61                                                 rm tmp3
62                                                 fi
63                                         fi
64                 else                                            
65                                 echo ". ./unmount-all">>partitionscript
66                                 #cat working/scripts/partition.$part>>fullrestorescript
67                                 #echo "partprobe >/dev/null 2>&1">>fullrestorescript
68                                 #echo "umount /dev/"$part"* >/dev/null 2>&1">>fullrestorescript
69                                 echo "dd if=working/diskinfo/mbr."$part" of=/dev/"$part>>partitionscript
70                                 echo "partprobe /dev/"$part" >/dev/null 2>&1">>partitionscript
71                                 echo ". ./unmount-all">>partitionscript
72                    fi
73
74                         if [ -f formatscript ]; then
75                         rm formatscript
76                         fi
77 cat >formatscript <<END_OF_DATA
78 . ./unmount-all
79 #
80 #  Format all partitions on disk $disk -- created by getdiskinfo
81 #
82 echo ""
83 echo "This script will format all partitions on disk $disk."
84 echo ""
85 echo "IT WILL DESTROY ALL DATA ON DISK $disk !!!!"
86 echo ""
87 if [ ! -f noprompt ];then
88 echo -n "Are you sure you want to continue? yes/no: "
89 read a
90 if [ x\$a != xyes ] ; then
91    exit 1
92 fi 
93 fi
94 if [ ! -f badblocksnoprompt ];then
95 echo "Do you want to do a disk check for bad blocks?"
96 echo -n "It is recommended, but takes time. yes/no: "
97 read a
98 if [ x\$a = xyes ] ; then
99   check="-c"
100 else
101    check=
102 fi
103 fi
104 END_OF_DATA
105
106 formatscripto=`ls working/scripts |grep $disk|grep format`
107 cat working/scripts/$formatscripto |grep $disk|while read line;do
108                         echo $line >>formatscript
109
110                         done
111                 cat formatscript>>formatallscript
112                 rm formatscript