For the purpose of disaster recovery we do wish to backup:

  1. GPT partition table,
  2. disk geometry (to restore to different sizes drives)
  3. and the corresponding file systems of each partition.

For example rsync can do the remaining file and folder backup and restore part. The five partitions on a GPT partitioned disk and its FAT and RAID-1 style BTRFS file systems need to be back-upped too.

Sgdisk doesn't restore file system

There are sgdisk drive backup and restore commands. That does only backup and restore the partition configuration, without having the file systems restored on the corresponding partitions.

File does output many file system details

# file -sL /dev/sda?
/dev/sda1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "mkfs.fat", sectors/cluster 8, Media descriptor 0xf8, sectors/track 32, heads 64, hidden sectors 8192, sectors 2097152 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 2048, reserved 0x1, serial number 0x7181b420, unlabeled
/dev/sda2: BTRFS Filesystem label "root", sectorsize 4096, nodesize 16384, leafsize 16384, UUID=b81e9d42-c0a2-4a1e-8197-f6775419f654, 3018244096/20971520000 bytes used, 1 devices
/dev/sda3: BTRFS Filesystem label "home", sectorsize 4096, nodesize 16384, leafsize 16384, UUID=2cf4e529-b242-4913-b283-fd18df73316a, 194707456/9965666304 bytes used, 1 devices

There is potential for a backup of the file -sL output, still missing how to restore this part.

Online backup

We need an online (not having to take the system down to make a backup) "clone" command that does not backup the folder and files themselves. In other words all the drive configuration before files and folders can be restored (with a different tool).


Which command(s) do(es) take care of drive disaster recovery before files and folders?

Note: A one-liner is rewarded as a better answer over having to enter multiple commands.


Considering only the GPT partition table you should bet a sensible backup with

export DISK=/dev/sda
echo -e "b\n/tmp/gpt-backup-"${DISK##*/}"\nq\n" | gdisk $DISK

But this backup is in binary format.

For my purposes I always prefer a simple gdisk -l /dev/sda. Unless you need to restore to exactly the same device a textual backup is the better choice, as you need to adjust anyway.

In my personal experience I always needed to restore the contents, but the filesystem type itself is usually irrelevant. You can restore from from e.g. a rsync based backup as long as the target mount point fits the data you want to restore and offers the same features as before (ACLs, extended attributes, hardlinks).

In general the guideline is to backup the relevant data, not the precise layout on disk. This keeps the process simple, easy to verify and independent of specifics not needed in praxis.

  • I see purpose for having a textual output, especially when the output is a script itself. Then the one-line command to restore is to run that script to re-create the partitions and file systems, optionally after some adaptations to the script. – Pro Backup Feb 20 '17 at 18:17
  • A simpler version of the backup command above is sgdisk -b ${DISK##*/} $DISK. – Johan Myréen Feb 20 '17 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.