Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- PATHBACKUP=/root/`ifconfig | grep 10.10.10. | sed 's/:/ /g' | awk '{print $3}'`
- mkdir -p $PATHBACKUP
- TEMPFILE=`mktemp /tmp/clone.XXXXXX`
- trap "rm -f $TEMPFILE" 0 1 2 5 15
- BackupDevices() {
- NOW=`date +%Y%m%d`
- mkdir -p $PATHBACKUP/$NOW
- cd $PATHBACKUP/$NOW
- fdisk -l > ./fdisk.txt
- for DEVICE in `fdisk -l | grep NTFS | sed 's/\// /g' | awk '{print $2}'`
- do
- clear
- DISK=`echo $DEVICE | awk '{print substr($1,0,4)}'`
- echo "Копируем MBR диска $DISK\n"
- dd if=/dev/$DISK of=./${DISK}.mbr bs=446 count=1
- sfdisk -d /dev/$DISK > ./${DISK}.partitions
- echo "\nКлонируем раздел $DEVICE\n"
- ntfsclone -s -o - /dev/$DEVICE | lzop -1c > ./$DEVICE.img.lzo
- echo $? > ./${DEVICE}_status.txt
- setterm -dump -file ./${DEVICE}_output.txt
- iconv -f cp866 -t utf8 -o ./${DEVICE}_output.txt ./${DEVICE}_output.txt
- done
- }
- RestoreDevices() {
- dialog --menu "Выберите архив" 15 50 10 `ls $PATHBACKUP | nl` 2> $TEMPFILE
- RESULT=$?
- clear
- case $RESULT in
- 0)
- ITEM=`cat $TEMPFILE`
- ls $PATHBACKUP | nl | awk '{print $1 " " $2}' > $TEMPFILE
- BACKUP=`cat $TEMPFILE | grep "^$ITEM" | awk '{print $2}'`
- if [ `fdisk -l | grep "^Disk /dev/" | awk '{print $5}'` -ge `cat $PATHBACKUP/$BACKUP/\`ls $PATHBACKUP/$BACKUP | grep "fdisk.txt"\` | grep "^Disk /dev/" | awk '{print $5}'` ]
- then
- DISK=`fdisk -l | grep "^Disk /dev/" | sed 's/\// /g' | sed "s/:/ /g" | awk '{print $3}'`
- dd if=$PATHBACKUP/$BACKUP/`ls $PATHBACKUP/$BACKUP | grep ".mbr"` of=/dev/$DISK
- sfdisk /dev/$DISK < $PATHBACKUP/$BACKUP/`ls $PATHBACKUP/$BACKUP | grep ".partitions"`
- partprobe -s /dev/$DISK
- #echo "o\nn\np\n1\n1\n`cat $PATHBACKUP/$BACKUP/\`ls $PATHBACKUP/$BACKUP | grep 'fdisk.txt'\` | grep '^/dev/' | awk '{print $4}'`\nw\n" | fdisk /dev/$DISK
- lzop -dc $PATHBACKUP/$BACKUP/`ls $PATHBACKUP/$BACKUP | grep "img.lzo"` | ntfsclone -r -O /dev/${DISK}1 -
- else
- echo "Размер установленного диска меньше, чем исходного"
- fi
- ;;
- 1)
- echo "Вы нажали отмену"
- ;;
- 255)
- echo "Вы нажали ESC"
- ;;
- esac
- }
- dialog --timeout 10 --menu "Выберите действие:" 9 50 2 "1" "Создать резервную копию" "2" "Восстановить из резервной копии" 2> $TEMPFILE
- RESULT=$?
- clear
- case $RESULT in
- 0|255)
- ACTION=`cat $TEMPFILE`
- case $ACTION in
- 2)
- RestoreDevices
- poweroff
- ;;
- "")
- echo "Вы нажали ESC"
- ;;
- *)
- BackupDevices
- poweroff
- ;;
- esac
- ;;
- 1)
- echo "Вы нажали отмену"
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement