Backup disk partition tables

In storage environment, the file system reliability is almost a common issue. As for my understanding, when a ext3 file system is under use, its integrity is keeping broken day by day, as most of the threaded applicatons cannot take fully control of data blocks. After a long time running, fsck becomes a must, otherwise your filesystem is not reliable any more. If you are using RAID, the disk partition might be lost sometimes. It’s more common if you face some hardware issues.
Also for some desktop users, to backup disk partitions would secure your data as well, especilly for the ones that interested in installing various systems over and over again. You know in this situation, the disk partition table is easily got damaged by misoperations.

I created a simpe shell script some months ago which can be used to backup disk partion tables for each logic device.
As you see, this script is very simple,

#!/bin/bash
#
# Created by joseph@2009-02, https://www.admon.org/
#
# This script is intended for backup diskpartions within the following
# two formats:
# /dev/cciss/c0d9p2, /dev/sdd12 which is mounted as /datum
#

IPSuffix=$(/sbin/ifconfig eth0 |awk ‘/inet addr/{print $2}’ |sed ‘s/addr:94.75.214.//;s/addr:94.75.215.//’)

Disklist=$(df -kh |awk ‘//datum//{print $1}’|sed ‘s/([a-z])[0-9]{1,}$/1/;s/p.*//’| sort| uniq)

for i in $Disklist
do
Disk=$(echo $i |awk -F/¬† ‘{print $NF}’)
/sbin/sfdisk -d $i 2>/dev/null > ~admon/var/disk-${Disk}.${IPSuffix}
done

Detailed manpage about  the major command sfdisk is available here at about.com.

If you face any issues when using this script, please dont be hesitate to drop me a mail.

Share Button

One thought on “Backup disk partition tables

Leave a comment

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