misc/86388: periodic(8) daily should backup bsdlabel(8) / fdisk(8)
disk labels
Seklecki at FreeBSD.org
Seklecki at FreeBSD.org
Tue Sep 20 19:20:06 PDT 2005
>Number: 86388
>Category: misc
>Synopsis: periodic(8) daily should backup bsdlabel(8) / fdisk(8) disk labels
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Wed Sep 21 02:20:05 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Seklecki, Brian A.
>Release: 5.3 Releng
>Organization:
Collaborative Fusion, Inc. / Spiritual Machines
>Environment:
FreeBSD soundwave 5.3-RELEASE-p20 FreeBSD 5.3-RELEASE-p20 #0: Wed Jul 27 16:03:34 EDT 2005 root at soundwave.collaborativefusion.com:/usr/obj/usr/src/sys/GENERIC i386
>Description:
Open/NetBSD have periodic(8) (well, actually /etc/perdiodic) scripts to backup fdisk(8) and disklabel(8) output. This is exceptionally useful in the event that you need to recover your system from an offsite storage tape backup to another facility on new (identical) hardware. Without disk partition / slice layout information, you have no idea how your system was originally partitioned.
Of course, depending on whether you're using software or hardware RAID, you might not even know how your RAID was setup. We also need a way to extract software RAID configurations (vinnum, geom, gmirror, CCD ex.) to a config file reference. For example, RAIDFrame's raidctl(8) has a nice "-G" flag:
"-G dev
Generate the configuration of the RAIDframe device in a format suitable for use with the -c or -C options."
There is one caveat: If you're using software RAID CCD, you have your ccd.conf(5) and the output of the component disks` bsdlabel(8) using my solution to determine where on the disk the CCD slice began.
There's no way to backup hardware RAID configuration layouts until the OS has a unified RAID API (see OpenBSD's msic@ list for details on something coming in the next release there).
>How-To-Repeat:
Sit around for a few weeks every year and brainstorm DRP (Disaster Recovery Planning) scnearios in a 100% FreeBSD environment.
>Fix:
I wrote an ugly little script for periodic to accomplish this here initially, until someone commits a higher quality one to the fbsd src tree:
The script is viewable at the following URL as well:
http://digitalfreaks.org/~lavalamp/220.backup-bsdlabels
-------------
#!/bin/sh
#
# $FreeBSD: src/etc/periodic/daily/220.backup-bsdlablels******
#
# If there is a global system configuration file, suck it in.
#
if [ -r /etc/defaults/periodic.conf ]
then
. /etc/defaults/periodic.conf
source_periodic_confs
fi
case "$daily_backup_bsdlabels_enable" in
[Yy][Ee][Ss])
bak=/var/backups
disks=`sysctl -n kern.disks`
if [ -z "$disks" ]; then
echo '$daily_backup_disklabels_enable" is set but no disk probed by kernel.' \
"perhaps NFS diskless client."
rc = 2
else
for i in $disks; do
# first order of business is to check for an existing backup-backup
if [ -f $bak/fdisk.$i.bak ] ; then
rc=1
echo "rotating $bak/fdisk.$i.bak"
cp -p $bak/fdisk.$i.bak $bak/fdisk.$i.bak2 || rc=3
fi
echo "backing up fdisk for $i"
fdisk $i > "$bak/fdisk.$i.bak" 2>/dev/null || rc=3
# again exept now we have to get a list of patitions/slices
# sparc64 can have...9 hopefully slices on a sunlabel?
part_slices=$(echo /dev/${i}s[0-9])
for j in $(echo "$part_slices" | sed 's/\/dev\///'); do
if [ -f $bak/disklabel.${j}.bak ] ; then
rc=1
echo "rotating $bak/disklabel.${j}.bak"
cp -p $bak/disklabel.${j}.bak $bak/disklabel.${j}.bak2 || rc=3
fi
echo "backing up disklabel for ${j}"
disklabel /dev/${j} > "$bak/disklabel.${j}.bak" 2>/dev/null || rc=3
done
done
fi;;
*) rc=0;;
esac
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list