Dumping NIM objects to a script

With all the latest improvements to NIM like "alternate master" and the like, I recently ran across something it doesn't do automatically: Copying a subset of a NIM servers objects to another server.

At work, we have several different NIM masters in different locations. All of them serve the same resources but with different clients. We use rsync to keep the actual data on disk in sync and create NIM objects accordingly(which means that we create SPOTs only once, at the "master master" and copy the SPOT data to the other machines and simply add the SPOT object to NIM without recreating the whole thing).

When the rootvg of one of our servers failed, I simply sent a set of harddisks there, containing nothing more than the base operating system and an old copy of the NIM instance. I didn't need to care about the actual installation images, because they were on a RAID5, but the NIM database was out of sync with what was on the disk. I could have walked through NIM to find all missing resources, but the easiest way for me was to delete all the old objects and write a small script to dump the resources of our main NIM server into a shell script which would define those objects on the new NIM.

And basically, it looks like this:


#!/bin/sh

# list of handled resource types
#
supported_resources="lpp_source spot mksysb bosinst_data image_data script installp_bundle"

# select all supported resource types by default
#
wanted_resources=${supported_resources}


# use first commandline argument(if present) to select a specific resource,
# but make sure it is supported
#
if [[ -n "$1" ]]; then
wanted_resources=$1
echo "${supported_resources}" | grep "${wanted_resources}" 2>&1 >/dev/null
is_valid_resource=$?

if [[ $is_valid_resource -ne 0 ]]; then
echo "Invalid resource"
echo "Supported resources are:"
echo $supported_resources
echo
exit 1
fi
fi

#
# Extract all objects of the wanted types from the NIM server
#
for resourceType in ${wanted_resources}; do
echo
echo "###"
echo "### ${resourceType}"
echo "###"

for resource in $(lsnim -t ${resourceType} | awk '{print $1}'); do

curResourceType=$(echo $(lsnim -l ${resource} | grep type | cut -d= -f2))
curResourceComment=$(echo $(lsnim -l ${resource} | grep comments | cut -d= -f2))
curResourceLocation=$(echo $(lsnim -l ${resource} | grep location | cut -d= -f2))

curResourceName=$(echo $(lsnim -l ${resource} | grep ":$" | cut -d: -f1))


case ${curResourceType} in
lpp_source)
echo nim -o define -t "'${curResourceType}'" \
-a server='master' \
-a location="'${curResourceLocation}'" \
-a arch="'power'" \
${curResourceComment:+-a comments="'${curResourceComment}'"} \
"'${curResourceName}'" ;;

#---------------------------------------------------------------------------------------
spot)
curResourceSource=$(echo ${curResourceName} | sed -e 's/spot/lppsource/g')
curResourceLocation=$(dirname $(dirname ${curResourceLocation}))
echo nim -o define -t "'${curResourceType}'" \
-a server='master' \
-a location="'${curResourceLocation}'" \
-a source="'${curResourceSource}'" \
${curResourceComment:+-a comments="'${curResourceComment}'"} \
-a installp_flags="'-c -g'" "'${curResourceName}'" ;;

#---------------------------------------------------------------------------------------
mksysb)
echo nim -o define -t 'mksysb' \
-a server='master' \
-a location="'${curResourceLocation}'" \
${curResourceComment:+-a comments="'${curResourceComment}'"} \
"'${curResourceName}'" ;;

#---------------------------------------------------------------------------------------
bosinst_data)
echo nim -o define -t 'bosinst_data' \
-a server='master' \
-a location="'${curResourceLocation}'" \
${curResourceComment:+-a comments="'${curResourceComment}'"} \
${curResourceName} ;;

#---------------------------------------------------------------------------------------
image_data)
echo nim -o define -t 'image_data' \
-a server='master' \
-a location="'${curResourceLocation}'" \
${curResourceComment:+-a comments="'${curResourceComment}'"} \
${curResourceName} ;;

#---------------------------------------------------------------------------------------
script)
echo nim -o define -t 'script' \
-a server='master' \
-a location="'${curResourceLocation}'" \
${curResourceComment:+-a comments="'${curResourceComment}'"} \
${curResourceName} ;;

#---------------------------------------------------------------------------------------
installp_bundle)
echo nim -o define -t 'installp_bundle' \
-a server='master' \
-a location="'${curResourceLocation}'" \
${curResourceComment:+-a comments="'${curResourceComment}'"} \
${curResourceName} ;;

#---------------------------------------------------------------------------------------
*)
echo "Unknown resource type '${curResourceType}'"
exit 1 ;;
esac
done
done


Comments

Display comments as (Linear | Threaded)

    No comments


Add Comment


Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Pavatar/Gravatar/Favatar/MyBlogLog author images supported.