Advertisement
Guest User

clone.sh

a guest
May 18th, 2015
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.63 KB | None | 0 0
  1. #!/bin/sh
  2. PATHBACKUP=/root/`ifconfig | grep 10.10.10. | sed 's/:/ /g' | awk '{print $3}'`
  3. mkdir -p $PATHBACKUP
  4. TEMPFILE=`mktemp /tmp/clone.XXXXXX`
  5. trap "rm -f $TEMPFILE" 0 1 2 5 15
  6.  
  7. BackupDevices() {
  8.  NOW=`date +%Y%m%d`
  9.  mkdir -p $PATHBACKUP/$NOW
  10.  cd $PATHBACKUP/$NOW
  11.  fdisk -l > ./fdisk.txt
  12.  for DEVICE in `fdisk -l | grep NTFS | sed 's/\// /g' | awk '{print $2}'`
  13.  do
  14.   clear
  15.   DISK=`echo $DEVICE | awk '{print substr($1,0,4)}'`
  16.   echo "Копируем MBR диска $DISK\n"
  17.   dd if=/dev/$DISK of=./${DISK}.mbr bs=446 count=1
  18.   sfdisk -d /dev/$DISK > ./${DISK}.partitions
  19.   echo "\nКлонируем раздел $DEVICE\n"
  20.   ntfsclone -s -o - /dev/$DEVICE | lzop -1c > ./$DEVICE.img.lzo
  21.   echo $? > ./${DEVICE}_status.txt
  22.   setterm -dump -file ./${DEVICE}_output.txt
  23.   iconv -f cp866 -t utf8 -o ./${DEVICE}_output.txt ./${DEVICE}_output.txt
  24.  done
  25. }
  26.  
  27. RestoreDevices() {
  28.  dialog --menu "Выберите архив" 15 50 10 `ls $PATHBACKUP | nl` 2> $TEMPFILE
  29.  RESULT=$?
  30.  clear
  31.  case $RESULT in
  32.   0)
  33.    ITEM=`cat $TEMPFILE`
  34.    ls $PATHBACKUP | nl | awk '{print $1 " " $2}' > $TEMPFILE
  35.    BACKUP=`cat $TEMPFILE | grep "^$ITEM" | awk '{print $2}'`
  36.    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}'` ]
  37.    then
  38.     DISK=`fdisk -l | grep "^Disk /dev/" | sed 's/\// /g' | sed "s/:/ /g" | awk '{print $3}'`
  39.     dd if=$PATHBACKUP/$BACKUP/`ls $PATHBACKUP/$BACKUP | grep ".mbr"` of=/dev/$DISK
  40.     sfdisk /dev/$DISK < $PATHBACKUP/$BACKUP/`ls $PATHBACKUP/$BACKUP | grep ".partitions"`
  41.     partprobe -s /dev/$DISK
  42.     #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
  43.     lzop -dc $PATHBACKUP/$BACKUP/`ls $PATHBACKUP/$BACKUP | grep "img.lzo"` | ntfsclone -r -O /dev/${DISK}1 -
  44.    else
  45.     echo "Размер установленного диска меньше, чем исходного"
  46.    fi
  47.    ;;
  48.   1)
  49.    echo "Вы нажали отмену"
  50.    ;;
  51.   255)
  52.    echo "Вы нажали ESC"
  53.    ;;
  54.  esac
  55. }
  56.  
  57. dialog --timeout 10 --menu "Выберите действие:" 9 50 2 "1" "Создать резервную копию" "2" "Восстановить из резервной копии" 2> $TEMPFILE
  58. RESULT=$?
  59. clear
  60. case $RESULT in
  61.  0|255)
  62.   ACTION=`cat $TEMPFILE`
  63.   case $ACTION in
  64.    2)
  65.     RestoreDevices
  66.     poweroff
  67.     ;;
  68.    "")
  69.     echo "Вы нажали ESC"
  70.     ;;
  71.    *)
  72.     BackupDevices
  73.     poweroff
  74.     ;;
  75.   esac
  76.   ;;
  77.  1)
  78.   echo "Вы нажали отмену"
  79.   ;;
  80. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement