Risky way to backup and restore guid partition tables
#!/bin/sh
# The number of partition tables could be varied and uncertain.
# So is the length of backup file.
# Only works in limited situations
# Won't work if any new partition is added to the partition table later
# Require sudo privilege
# Use the code only after you know what you're doing. Use at your own risk.
# Change the variables in the script if necessary
# https://askubuntu.com/questions/57908/how-can-i-quickly-copy-a-gpt-partition-scheme-from-one-hard-drive-to-another
read -r partition_count < ./partition_count.txt
echo "partition_count: " $partition_count
byte_size=$(((128 * $partition_count) + 1024))
echo "byte size: " $byte_size
dd if=./GPT_TABLE_BACKUP of=/dev/sda bs=1 count=$byte_size
echo "Done."