X-Git-Url: https://git.sur5r.net/?p=bacula%2Frescue;a=blobdiff_plain;f=rescue%2Flinux%2Fusb%2Fsrc%2Fscripts%2Frestore%2Fnewsize;fp=rescue%2Flinux%2Fusb%2Fsrc%2Fscripts%2Frestore%2Fnewsize;h=b5e1780f47dadbf54b8e6cd853ead0f1abac063d;hp=0000000000000000000000000000000000000000;hb=4dd8d7fe401088b31113cd54fc0cc87ae121c971;hpb=fb21b5066e01a80263767f2406829a10dfa58303 diff --git a/rescue/linux/usb/src/scripts/restore/newsize b/rescue/linux/usb/src/scripts/restore/newsize new file mode 100644 index 0000000..b5e1780 --- /dev/null +++ b/rescue/linux/usb/src/scripts/restore/newsize @@ -0,0 +1,62 @@ +#!/bin/sh +if [ -f nozen ]; then +DIALOG=dialog +else +DIALOG=Xdialog +fi +set -x +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" 60 60 + 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 ? (no)" 60 60 + 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 " 60 60 + 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)" 60 60 + exit 1 + fi + else + + a=` sfdisk -n /dev/$part < working/diskinfo/sfdisk.$part.make.bsi 2>&1` + echo $a > tmp + grep Warning tmp + 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.$part.make.bsi 2>&1` + echo $a > tmp + grep Warning tmp + 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 + + partprobe /dev/$part >/dev/null 2>&1 + . ./unmount-all + sfdisk /dev/$part < working/diskinfo/sfdisk.$part.make.bsi + fi