backup of hybrid partition tables

Well, imagine if you have a MacOs with hybrid operation systems “Linux”, “Windows”.The most difficult part is to make a backup system, that makes a backup of each partition correctly. There is a general solution to this problem.

Many backup systems fail to backup because of different partition tables(like MBR/GPT..)

What is MBR?(short version)

Master Boot Record stores information about file systems and logical partitions on the medium.The disk size is 232

What is GPT? (short version)

GUID Partition Table has the same functions as MBR and it is a replacement of MBR.Every Layout is specific  and stores on the first layout a part of protective MBR header.The capability of disk size is 264  

# partition table secure: MBR/GPT
# needed PGM: parted, sfdisk,sgdisk,sed
# safety directory (/directory), Standard: ${HOME}

#store a pc number
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1 | cut -d '.' -f 4)"
output directory-standard: ${HOME}
export LC_ALL=C                               

     bold=$(echo -e "\e[1m")                 
      red=$(echo -e "\e[1;31m")
    green=$(echo -e "\e[1;32m")
     blue=$(echo -e "\e[1;34m")
   violet=$(echo -e "\e[1;35m")
     cyan=$(echo -e "\e[1;36m")
 standard=$(echo -e "\e[0;39m")

# if the lshw is installed the device safely gets the secure name

disks=( $(which lshw >/dev/null && sudo lshw -businfo 2>/dev/null|sed -ne 's#^.*\@.*\(\/dev\/[shm][a-zA-Z]\+\) *\+disk *\+\(.*B\) \(.*\)$#\1:\3\-\2#p'|tr -s ' ' '_') )
 # sfdisk should be installed
which sfdisk 2>&1>/dev/null || { echo -e "\t${red}====> \t sfdisk muss installiert sein \t <====${standard}"; exit 1 ;}
# sgdisk should be installed
which sgdisk 2>&1>/dev/null || { echo -e "\t${red}====> \t sgdisk must be installed\t <====${standard}"; exit 1 ;}
# parted should be installed
which parted 2>&1>/dev/null || { echo -e "\t${red}====> \t parted must be installed\t <====${standard}"; exit 1 ;}

if [[ `whoami` != root ]]                    
# execution with root rights
    echo -e "\n\t\t the script \"$(basename $0)\" must have ${bold}${red}root permissions${standard} \n" 1>&2
    exit 1

 [ x$1 != 'x' -a -d $(dirname $a'/dummy') ] && backupdir=$(dirname $1'/dummy')/
 # $1 outputdirectory exists /exist?: y/n

echo -e "\n\t\t${stars}\n\t\t* backup of the partition table(MTP/GPT) *\n\t\t${stars}\n\t\t Backup-directory: ${blue}${backupdir}${standard}\n\t\t" 1>&2

  while read -r device
    pt=$(sudo parted -s /dev/${device} print|sed -ne 's@^.*Table: \(.*\)$@\1@p')
    case $pt in                              
# Liste of the know tables
      msdos) # MBR-partition table (MPT)
             echo -e "\t${standard}type:\t${green}$pt${standard}\t   Device: ${cyan}/dev/${device}${standard}\t directory: ${blue}${backup_file}.MPT${violet}" 1>&2
             $(sudo sfdisk -d /dev/${device} >${backupdir}${backup_file}.MPT)
             echo ${standard} 1>&2
      gpt)   # GUID-partition table (GPT)
             echo -e "\t${standard}Typ:\t${green}$pt${standard}\t   Device: ${cyan}/dev/${device}${standard}\tdirectory: ${blue}${backup_file}.GPT${violet}" 1>&2
             $(sudo sgdisk -b ${backupdir}${backup_file}.GPT /dev/${device} 1>&2)
             echo ${standard} 1>&2
	*)   # error case
             echo -e "${red}====> \t${standard}backup type:\t${green}$pt${standard}\tDevice:${blue}/dev/${device}${standard}\tBackup: ${red} invalid type${green} ${pt}${red} <====${standard}" 1>&2
  done < <(sed -ne 's/^.*\([shm]d[a-zA-Z]\+ *$\)/\1/p' /proc/partitions)
sleep 3

This solution is recommended for creating a custom backup system with Clonezilla or other backup software.

Leave a Reply

Your email address will not be published. Required fields are marked *