Incommunique

Powered by a whole foods plant based diet, a well dressed penguin and an over-active imagination

Backing up Veritas configurations

Over at Symantec they recommend you backup your Veritas configurations for disaster recovery but then say “What is not a good idea is to set up a cron job to back them up often.” Well why not? Because you could be backing up a dodgy configuration is their reasoning I suppose. Sounds like we need to keep a few copies if there have been changes then. Perl is my usual weapon of choice but this seemed like a good fit with shell. Use the code at your own risk but it seems to work OK for the environment I’m currently working in…





#!/bin/ksh
#
# backup veritas configurations
#
# as specified at http://seer.entsupport.symantec.com/docs/180321.htm
#
# saves the last x differing copies of your veritas config, a config is only saved
# if it is different to what has already been saved
#


DIR=“/path/to/someplace/to/store/veritas_configs”
NUM_OF_BACKUPS=5 # we keep the newest this many…

device_to_os_native () {
device=“$1”
# use vxdisk -e list as vxdisk path doesn’t work for all versions
os_native=vxdisk -e list | grep "^$device" | awk '{print $NF}'
echo $os_native
}

if [ ! -f “/etc/vx/volboot” ]; then
[ -t 1 ] && echo “Veritas not running here, exiting”
exit
fi

if [ /usr/bin/id | grep -c "^uid=0(root)" -ne 1 ]; then
[ -t 1 ] && echo “$0 can only be run as root”
exit
fi

HOST=uname -n
DATE=date +"%Y%m%d-%H%M%S"

vxdisk_list=“${DIR}/${HOST}_vxdisk_list.${DATE}”
vxdisk_list_detail=“${DIR}/${HOST}_vxdisk_list_detail.${DATE}”
prtvtoc_all_disk=“${DIR}/${HOST}_prtvtoc_all_disk.${DATE}”
vxdg_detail=“${DIR}/${HOST}_vxdg_detail.${DATE}”

>$vxdisk_list
>$vxdisk_list_detail
>$prtvtoc_all_disk
>$vxdg_detail

vxdisk list >>$vxdisk_list
vxdisk -q list | awk ‘{print $1}’ | xargs vxdisk list >>$vxdisk_list_detail

for disk in vxdisk -q list | awk '{ if ($2 != "simple") print $1 }' ; do
if [ echo $disk | grep -c 'c.*t.*d.*s.*' -ge 1 ]; then
disk=“/dev/rdsk/$disk”
else
os_native=device_to_os_native $disk
disk=“/dev/rdsk/$os_native”
fi
prtvtoc $disk >>$prtvtoc_all_disk
done



for vxdg in vxdg -q list | awk '{print $1}'; do
vxprint -g $vxdg -rhmvps >>$vxdg_detail
done



for file in vxdisk_list vxdisk_list_detail prtvtoc_all_disk vxdg_detail ; do
# get the second last file (last file is the one we just created)
last=ls -1tr ${DIR}/${HOST}_${file}.* 2>/dev/null | tail -2 | head -1

eval “current=\${$file}”
# if $last == $current then it’s then we have no previous data
# for this host
if [ “$last” != “$current” ]; then

# if current has the same contents as last then delete current
# diff exits 0 if the files are the same…
/usr/bin/diff $current $last >/dev/null 2>&1
if [ $? -eq 0 ]; then
# files are the same
[ -t 1 ] && echo “Configuration unchanged removing $current”
rm -f $current
fi
fi

# if there are more than 5 copies of file
# delete the oldest copies down to 5

files=ls -1tr ${DIR}/${HOST}_${file}.* 2>/dev/null
num_of_files=echo "$files" | wc -l | sed -e "s/ //g"
if [ $num_of_files -gt $NUM_OF_BACKUPS ]; then
num_to_del=$(($num_of_files - $NUM_OF_BACKUPS))
count=0
for file in $files ; do
[ $count -eq $num_to_del ] && break
[ -t 1 ] && echo “Removing older version of $file”
rm -f $file
count=$(($count + 1))
done

fi
done



Share