Cloning a Veritas Diskgroup Structure

Written by:

I have a Solaris 10 system configured with Veritas File Systems. The goal is to clone the diskgroup structure onto another systems so as to save time building the structure manually. I want all the volumes the same size and the same names as my source.

Below is a script used to perform this task. The script must be run from the source server. It then gets all of the diskgroup structure information then outputs into a file the commands needed to recreate.

Copy the output file to the destination server and run it. Key thing here to note is that on your destination server, you must have already created the diskgroup and have the same amount of disk space allocated as your source.

# Veritas Diskgroup Clone Script
# This script needs to run from the source server.
# This script will create another script that will contain the steps needed
# to clone the veritas diskgroup layout structure.
# After running the output script on the target system, it will also verify
# if the new filesystem is in the /etc/vfstab file and mount the new volumes.
# Note: The destination server must have the diskgroup created and all the
#   necessary disks added to it but with no volumes configured.


if [ -z ${DG} ] || [ -z $OUTF ] ; then
        print -u2 "Usage: ${Me} diskgroup outputfile "
        exit 1

echo "Output script: $OUTF"
echo "This output script may need to be modified to fit the target system"

exec 2>&1
exec 1>${OUTF}

echo "echo"
echo "echo \"---------------------------------\""
echo "echo \"    This script is distructive. \""
echo "echo \"    MODIFY THIS SCRIPT to use a different mount point or \""
echo "echo \"    different diskgroup if being used to clone to another server. \""
echo "echo"
echo "echo \"    Press ctrl-c to abort or enter to contine\""
echo "echo"
echo "read ans"

vxprint -g ${DG} -v | grep "^v " | grep ENABLED |
while read line

  VOL=`echo $line | awk '{print $2}'`
  SZ=`echo $line | awk '{print $5}'`

  echo "/usr/sbin/vxassist -g $DG -U fsgen make $VOL ${SZ} layout=nostripe,nolog"
  #echo "/usr/sbin/mkfs -F vxfs -o bsize=8192 /dev/vx/rdsk/$DG/$VOL"
  MKFS_CMD=`/usr/sbin/mkfs -m /dev/vx/rdsk/$DG/$VOL"`
  echo "/usr/sbin/$MKFS_CMD"
  MNT_PT=`df -k /dev/vx/dsk/$DG/$VOL | tail -1 | awk '{print $6}'`
  OWNER=`ls -ld $MNT_PT | awk '{print $3}'`
  GROUP=`ls -ld $MNT_PT | awk '{print $4}'`

  echo "if [ ! -d $MNT_PT ]; then"
  echo "  mkdir -p $MNT_PT"
  echo "  chmod 755 $MNT_PT"
  echo "fi"

  echo "chown $OWNER:$GROUP $MNT_PT"

  echo "grep -v \"#\" /etc/vfstab | grep \"/dev/vx/dsk/$DG/$VOL\" > /dev/null"
  echo "if [ \$? -ne 0 ]; then"
  echo "   echo \"/dev/vx/dsk/$DG/$VOL  /dev/vx/rdsk/$DG/$VOL   $MNT_PT vxfs    3       yes     -\">> /etc/vfstab"
  echo "fi"
  echo "/usr/sbin/mount -F vxfs $MNT_PT"


Cloning a Veritas Diskgroup Structure
1 vote, 4.00 avg. rating (50% score)

One response to “Cloning a Veritas Diskgroup Structure”

  1. […] Get the source code for the Cloning a Veritas Diskgroup Structure script. […]

Leave a Reply