Article Listing 1 Listing 2 Listing 3 Listing 4 oct2006.tar

Listing 2 shadow script

#!/bin/bash

# Set defaults
secdisk="c0t2d0"

# Figure out which disk is our "primary disk" and which is the "shadow disk"
rootdisk=`df / | awk '{print $2}' | sed 's/(\/dev\/dsk\///' | sed 's/s.$//'`
if [ $rootdisk = "c0t2d0" ]
then
   secdisk="c0t0d0"
   eeprom boot-device="disk2 disk net"
else
   eeprom boot-device="disk disk2 net"
fi

# Define variables
yes="y"

echo "Executing \"$0\" on `date`"
echo "Shadowing $rootdisk to $secdisk......."

# Get rid of any existing snapshots and unmount any associated filesystems
umount -f /extra/root
umount -f /extra/usr
umount -f /extra/var
umount -f /extra/home
fssnap -d /
fssnap -d /usr
fssnap -d /var
fssnap -d /export/home
rm /extra/snapshots/*

# Prepare the secondary disk
echo "Creating new file systems on secondary disk...."
newfs /dev/rdsk/${secdisk}s0 <<<$yes
newfs /dev/rdsk/${secdisk}s3 <<<$yes
newfs /dev/rdsk/${secdisk}s4 <<<$yes
newfs /dev/rdsk/${secdisk}s6 <<<$yes

echo "Mounting file systems on secondary disk...."
if [ ! -d /extra/root ];then mkdir /extra/root;fi
mount /dev/dsk/${secdisk}s0 /extra/root
if [ ! -d /extra/usr ];then mkdir /extra/usr;fi
mount /dev/dsk/${secdisk}s3 /extra/usr
if [ ! -d /extra/var ];then mkdir /extra/var;fi
mount /dev/dsk/${secdisk}s4 /extra/var
if [ ! -d /extra/home ];then mkdir /extra/home;fi
mount /dev/dsk/${secdisk}s6 /extra/home

# Create directory to hold backing store files if necessary
if [ ! -d /extra/snapshots ];then mkdir /extra/snapshots;fi

echo "Backing up file systems on primary disk to secondary disk...."

# Backup root slice to secondary disk
ufsdump 0f - `fssnap -o bs=/extra/snapshots /` | (cd /extra/root && \
  ufsrestore rf -)
fssnap -d /

# "Fix up" config files with hard coded disk device file names
cat /etc/vfstab | sed s/$rootdisk/$secdisk/g > /extra/root/etc/vfstab
cat /etc/dumpadm.conf | sed \
  s/$rootdisk/$secdisk/g > /extra/root/etc/dumpadm.conf
umount /extra/root

# Backup /usr slice to secondary disk
ufsdump 0f - `fssnap -o bs=/extra/snapshots /usr` | (cd /extra/usr && \
  ufsrestore rf -)
umount /extra/usr
fssnap -d /usr

# Backup /var slice to secondary disk
ufsdump 0f - `fssnap -o bs=/extra/snapshots /var` | (cd /extra/var && \
  ufsrestore rf -)
umount /extra/var
fssnap -d /var

# Backup /export/home slice to secondary disk
ufsdump 0f - `fssnap -o bs=/extra/snapshots /export/home` | \
  (cd /extra/home && ufsrestore rf -)
umount /extra/home
fssnap -d /export/home

# Remove backing store files
rm /extra/snapshots/*

echo "-----------------------------------------------"