Networker

Re: [Networker] Automating a second clone?

2005-07-13 10:18:40
Subject: Re: [Networker] Automating a second clone?
From: Davina Treiber <Treiber AT HOTPOP DOT COM>
To: NETWORKER AT LISTSERV.TEMPLE DOT EDU
Date: Wed, 13 Jul 2005 15:15:15 +0100
George Sinclair wrote:
> How best can I automate the creation of a second clone?
> 
> We have a group that runs every morning with "Clones" set to 'yes', so
> we end up with all the savesets cloned to another pool. This works just
> fine, but I would also like to automate the creation of a second clone
> but to a different pool. In other words, I'd like the same original
> savesets cloned to this second pool after the first clones complete. How
> best can I do this?
> 
> I don't want to wait to clone the whole original volume. I'd prefer to
> have it done each day so I don't fall behind, but the only thing I see
> involves backup groups and automatic cloning but no way to just automate
> *only* a clone. Is it a simple matter to just write a script to run out
> of cron, on the primary server, that first determines which original
> savesets have not yet been cloned to the second pool and then just  runs
> 'nsrclone' on each saveset, cloning them to the second pool? How would
> it know that the original volume was not still in use?
> 

When you want a second clone to a different pool the task becomes
marginally more complex than just querying copies=n and cloning, however
it's not desperately difficult. I have been working on a script recently
that clones to two pools. I'll strip out just the bits that relate to
cloning and post it below.

#!/bin/ksh
export PATH="/bin:/usr/bin:/usr/ucb:/usr/sbin"
export LC_TIME=fr_BE.ISO8859-1
if [ "$(tty)" = "not a tty" ]; then
        LOGDIR=/nsr/logs/housekeepdiskdev
        LOGFILE="$LOGDIR/$(date +\%Y\%m\%d\%H\%M\%S).$$"
        exec 1> $LOGFILE
        exec 2>&1
        find $LOGDIR -mtime +30 -exec rm -f {} \;
fi

NSRSERVER=$(uname -n)   # default to this server
SOURCEPOOL=
CLONEPOOL=
VERBOSE=                # not verbose by default
while getopts s:b:f:n:v OPT; do
        case $OPT in
            s)
                NSRSERVER="$OPTARG" ;;
            b)
                SOURCEPOOL="$OPTARG" ;;
            f)
                OFFSITECLONEPOOL="$OPTARG" ;;
            n)
                ONSITECLONEPOOL="$OPTARG" ;;
            v)
                VERBOSITY="-v" ;;
            '?')
                echo "Usage: housekeepdiskdev and some options..."
                exit 1
                ;;
        esac
done
if [ -z "$SOURCEPOOL" ]; then
        echo "Pool parameter (-b) must be supplied"
        exit 1
fi
if [ -z "$OFFSITECLONEPOOL" ]; then
        echo "Offsite clone pool parameter (-f) must be supplied"
        exit 1
fi
if [ -z "$ONSITECLONEPOOL" ]; then
        echo "Onsite clone pool parameter (-n) must be supplied"
        exit 1
fi

# Lock file handling
THISPROG=$(basename $0)
LOCKFILE="/var/run/$THISPROG.$SOURCEPOOL.pid"
if [ -f "$LOCKFILE" ]; then
        PID=$(cat "$LOCKFILE" 2> /dev/null)
        if [ -n "$(ps -p $PID | grep -v PID)" ]; then
                echo "$THISPROG already running, exiting."
                exit 1
        else
                echo "Replacing stale lock file \"$LOCKFILE\""
                echo $$ > "$LOCKFILE"
        fi
else
        echo $$ > "$LOCKFILE"
fi

SOURCESSIDFILE=/tmp/sourcessids.$$
TARGETSSIDFILE=/tmp/targetssids.$$
SSIDS2CLONE=/tmp/ssids2clone.$$

# Extract a list of ssids for cloning to offsite pool
(
mminfo -s $NSRSERVER -q "!incomplete,!ssrecycle,pool=$SOURCEPOOL"
-r "ssid" 2> /dev/null
mminfo -s $NSRSERVER -q "!incomplete,!ssrecycle,pool=$ONSITECLONEPOOL"
-r "ssid" 2> /dev/null
) | sort -nu > $SOURCESSIDFILE
mminfo -s $NSRSERVER -q "pool=$OFFSITECLONEPOOL,!incomplete,!ssrecycle"
-r "ssid" 2> /dev/null \
| sort -nu > $TARGETSSIDFILE
diff $SOURCESSIDFILE $TARGETSSIDFILE | grep "^< " | sed 's/^< //' >
$SSIDS2CLONE

# Clone them
[ -s $SSIDS2CLONE ] && nsrclone -s $NSRSERVER $VERBOSITY -b
"$OFFSITECLONEPOOL" -S -f $SSIDS2CLONE

# Extract a list of ssids for cloning to onsite pool
(
mminfo -s $NSRSERVER -q "!incomplete,!ssrecycle,pool=$SOURCEPOOL"
-r "ssid" 2> /dev/null
mminfo -s $NSRSERVER -q "!incomplete,!ssrecycle,pool=$OFFSITECLONEPOOL"
-r "ssid" 2> /dev/null
) | sort -nu > $SOURCESSIDFILE
mminfo -s $NSRSERVER -q "pool=$ONSITECLONEPOOL,!incomplete,!ssrecycle"
-r "ssid" 2> /dev/null \
| sort -nu > $TARGETSSIDFILE
diff $SOURCESSIDFILE $TARGETSSIDFILE | grep "^< " | sed 's/^< //' >
$SSIDS2CLONE

# Clone them
[ -s $SSIDS2CLONE ] && nsrclone -s $NSRSERVER $VERBOSITY -b
"$ONSITECLONEPOOL" -S -f $SSIDS2CLONE

rm -f $SOURCESSIDFILE $TARGETSSIDFILE $SSIDS2CLONE $LOCKFILE 2> /dev/null

--
Note: To sign off this list, send a "signoff networker" command via email
to listserv AT listserv.temple DOT edu or visit the list's Web site at
http://listserv.temple.edu/archives/networker.html where you can
also view and post messages to the list. Questions regarding this list
should be sent to stan AT temple DOT edu
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

<Prev in Thread] Current Thread [Next in Thread>