220.backup-bsdlabels (WAS: Re: periodic(8) / daily bsdlabel / fdisk / softraid*)

Brian A. Seklecki lavalamp at spiritual-machines.org
Tue Sep 20 19:27:09 PDT 2005


Here's a basic script to accomplish this.  No support for checking 
geom/gmirror/vinum configurations.  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."

Maybe someone more intimate with these 3 RAID APIs on FBSD can offer some 
insight.

Obviously, this script will need to be re-written to do sanity checks 
especially with secure file operations.  NetBSD has a nice function in 
/etc/security called migrate_file() {...} for safely rotating.  And lines 
42 and 44 are just ugly.

Also, do non-i386/amd64 platforms support fdisk(8)?  I know NetBSD uses 
sunlabel(8)+disklabel(8) on Sparc64?

But this does what I need it to do.  Given a solid off-site tape backup of 
/var, I can recover /var/backup/(fdisk|disklabel) to a temp machine, and 
recovery my slices.

In the event of a complete system loss, I can use fdisk(8) output to 
verify that the number of sectors on my hardward or software RAID 
meta-device match as they were previously on the newly created RAID.

PR is misc/86388!

http://digitalfreaks.org/~lavalamp/220.backup-bsdlabels

Thanks all!

~BAS


---------

#!/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

On Tue, 20 Sep 2005, Brian A. Seklecki wrote:

>
> All:
>
> I just realized that the stock perdiodic scripts dont backup fdisk/disklabel 
> output.  I'm taken back a bit; NetBSD and OpenBSD have always done this 
> (archive to /var/backup).  We backup the password and group files, but not 
> system info.
>
> Obviously, RAID can mitigate the need for this, but imagine a DRP scenario 
> where you have to recover a host to an offsite warm/cold failover facility 
> from off-site tape backups.  You can get your vendor to provide identical 
> hardware, but without disk parition/slice info, how are you going to recover 
> your disks?
>
> It's bad enough we don't have a unified way to talk to RAID controllers 
> yet...the least we can do is try.
>
> We should probably also backup gmirror/gvinum config outputs...
>
> *sigh*
>
> ~BAS
>

l8*
 	-lava

x.25 - minix - bitnet - plan9 - 110 bps - ASR 33 - base8


More information about the freebsd-questions mailing list