How To Backup LDOM Configurations

A system administrator must backup the LDOM configuration before rebooting the box. This is for those situations wherein later you feel - "If only I had taken the backup of the configuration files ... bla bla!" Now, there are number of commands that should help you. I have a condensed form, in the name of the script - backupldom.ksh
#!/bin/ksh


# This script creates XML backup files of all configured domains
# and saves an SP config
# export Variables
HOST=`hostname`
SCR=`basename $0`
LOG=/tmp/$SCR.`date +%Y+%m.log`
PATH=/opt/SUNWldm/bin:/bin:/usr/sbin/:/sbin
BDIR=/var/adm/doc
ID=`/usr/ucb/whoami`

usage(){
echo "You must be root to run this script"
}

export_config(){
if [[ ! -d /var/adm/doc ]];then
mkdir -p /var/adm/doc
fi

echo "Moving current XML files in $BDIR to 'filename'.backup"
for XML in `ls $BDIR/*.xml`
do
mv $XML $XML.backup
done
echo ""

for LDOM in `ldm ls |grep -v ^NAME| awk '{print $1}'`
do
if [[ $LDOM = primary ]];
then
echo "Backing up LDOM $LDOM to $BDIR as $LDOM-$HOST.xml"
ldm ls-constraints -x $LDOM > $BDIR/$LDOM-$HOST.xml
else
echo "Backing up LDOM $LDOM to $BDIR as $LDOM.xml"
ldm ls-constraints -x $LDOM > $BDIR/$LDOM.xml
fi
done

echo "Saving extended information 'ldm ls -e -p' to ldm-extended.out"
mv $BDIR/ldm-extended.out $BDIR/ldm-extended.out.backup
ldm ls -e -p > $BDIR/ldm-extended.out

echo ""
echo "-------------------------"
echo "Backup of LDOM's complete"
echo "If this is a cluster environment, ensure you scp the guest LDOM"
echo "XML files to the adoptive nodes"
echo "-------------------------"
echo ""
}

save_sp_config(){
echo ""
echo "We will now backup the LDOM Configuration to the Service Processor"
echo ""
echo "Current list of the saved Service Processor configs:"
ldm ls-spconfig
echo ""
echo "Is there an existing configuration you want to over-write?[Y|N]"
read overwrite
# if [ $overwrite = "Y" -o $overwrite = "y" ];then
if [[ $overwrite = "Y" || $overwrite = "y" ]];then
echo "Enter the name of config you want to overwrite:"
read overwrite_config
echo "Removing/adding the config...."
ldm rm-spconfig $overwrite_config
ldm add-spconfig $overwrite_config
echo ""
echo "The current SP configurations are:"
ldm ls-spconfig
echo ""
else
echo "OK, we will add a new config, enter the name of the config:[prod]"
read new_config
if [[ -z $new_config ]];then
export new_config=prod
fi
echo "Adding new config $new_config to the SP"
ldm add-spconfig $new_config
echo ""
echo "The current SP configs are:"
ldm ls-spconfig
echo ""
fi
}

# MAIN
if [[ $ID != root ]];then
usage && exit 1
fi
export_config
sleep 5
save_sp_config

This is a very useful script. Quite handy when you wish to back reference your configuration or have a quick recovery.

Sharing is caring! If you like the post, please share the word ...


1 comment :

  1. This is awesome explanation. Thanks a Ton.

    ReplyDelete