X-Git-Url: https://git.sur5r.net/?p=bacula%2Frescue;a=blobdiff_plain;f=rescue%2Flinux%2Fusb%2Fsrc%2Fscripts%2Frestore%2Ffull_disk;fp=rescue%2Flinux%2Fusb%2Fsrc%2Fscripts%2Frestore%2Ffull_disk;h=fbfef36cb2c1b0e3d1a0b32a705f7d4982c5d9f4;hp=0000000000000000000000000000000000000000;hb=4dd8d7fe401088b31113cd54fc0cc87ae121c971;hpb=fb21b5066e01a80263767f2406829a10dfa58303 diff --git a/rescue/linux/usb/src/scripts/restore/full_disk b/rescue/linux/usb/src/scripts/restore/full_disk new file mode 100644 index 0000000..fbfef36 --- /dev/null +++ b/rescue/linux/usb/src/scripts/restore/full_disk @@ -0,0 +1,112 @@ +#!/bin/sh + +if [ -f nozen ]; then +DIALOG=dialog +else +DIALOG=Xdialog +fi + +MB=MB part=`echo $disk|cut -d"/" -f3` + fdisk -l /dev/$part |grep bytes|grep -v Units|awk '{print $5}'>samesize + cat working/diskinfo/fdisk.$part |grep bytes|grep -v Units|awk '{print $5}'>samesize2 + diff samesize samesize2 >/dev/null 2>&1 + if [ ! $? = 0 ] ;then + nowdisk=`cat samesize` + oldisk=`cat samesize2` + $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 + oldiskparted=`cat working/diskinfo/parted.$part` + howmanyparts=`cat working/diskinfo/parted.$part|wc -l` + howmanyparts=$(( $howmanyparts - 7 )) + $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 + if [ $? = 0 ];then + if [ $DIALOG = Xdialog ];then + echo $$oldiskparted + $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 + gparted /dev/$part + else + $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 + exit 1 + fi + else + + a=` sfdisk -n /dev/$part < working/diskinfo/sfdisk.make.$part.bsi 2>&1` + echo $a > tmp + grep exceed tmp >/dev/null 2>&1 + if [ $? = 0 ];then + tr ' ' '\n' < tmp >tmp2 + cat tmp2|awk /given/,/sfdisk/ >tmp3 + currentsize=`cat tmp3|grep -m1 "("|cut -d"(" -f2 |cut -d")" -f1` + maxsize=`cat tmp3|grep -m2 "("|cut -d"(" -f2 |cut -d")" -f1|tail -n1` + sed -i "s/$currentsize/$maxsize/g" working/diskinfo/sfdisk.make.$part.bsi + nowarn=1 + while [ $nowarn = 1 ];do + a=` sfdisk -n /dev/$part < working/diskinfo/sfdisk.make.$part.bsi 2>&1` + echo $a > tmp + grep exceed tmp >/dev/null 2>&1 + if [ $? = 0 ];then + tr ' ' '\n' < tmp >tmp2 + cat tmp2|awk /given/,/sfdisk/ >tmp3 + currentsize=`cat tmp3|grep -m1 "("|cut -d"(" -f2 |cut -d")" -f1` + maxsize=`cat tmp3|grep -m2 "("|cut -d"(" -f2 |cut -d")" -f1|tail -n1` + sed -i "s/$currentsize/$maxsize/g" working/diskinfo/sfdisk.make.$part.bsi + else + nowarn=0 + fi + done + partprobe /dev/$part >/dev/null 2>&1 + . ./unmount-all + sfdisk /dev/$part < working/diskinfo/sfdisk.make.$part.bsi + rm tmp + rm tmp2 + rm tmp3 + fi + fi + else + echo ". ./unmount-all">>partitionscript + #cat working/scripts/partition.$part>>fullrestorescript + #echo "partprobe >/dev/null 2>&1">>fullrestorescript + #echo "umount /dev/"$part"* >/dev/null 2>&1">>fullrestorescript + echo "dd if=working/diskinfo/mbr."$part" of=/dev/"$part>>partitionscript + echo "partprobe /dev/"$part" >/dev/null 2>&1">>partitionscript + echo ". ./unmount-all">>partitionscript + fi + + if [ -f formatscript ]; then + rm formatscript + fi +cat >formatscript <>formatscript + + done + cat formatscript>>formatallscript + rm formatscript