Networker

Re: [Networker] Custom "clone" scripts?

2002-12-11 10:07:38
Subject: Re: [Networker] Custom "clone" scripts?
From: "Maarten Boot (CWEU-USERS/CWNL)" <Maarten.Boot AT NL.COMPUWARE DOT COM>
To: NETWORKER AT LISTMAIL.TEMPLE DOT EDU
Date: Wed, 11 Dec 2002 16:09:13 +0100
Just to give you an idea

The correct formulating of the query and the report is essential

then I filter all platforms that are not servers and bild a list of ssid

any ssid of a continuation saveset is ignored (we have still a few
version 5 clients)

and any ssid with a pssid of nonzero (basically another way to test if
it is a continuation saveset is also dropped .

this list is then processed for cloning if the -w option is given.

the 2 modules for file locking are not included in the attachment
they are not essential for understanding the clone script

if you need them holler.

Maarten


"Robert L. Harris" wrote:
>
>   Does anyone have a good shell/perl type script that'll take complete,
> full backups that haven't been cloned and clone them off to tapes?
> We're currently using one from someone who left and the sucker is rather
> complicated just trying to figure out what's valid to clone.  Before I
> write my own I'd like to look at some other's examples and see what
> options there are to do it faster and easier.
>
> Robert
>
> :wq!
> ---------------------------------------------------------------------------
> Robert L. Harris                     | PGP Key ID: FC96D405
>
> DISCLAIMER:
>       These are MY OPINIONS ALONE.  I speak for no-one else.
> FYI:
>  perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
>
> --
> Note: To sign off this list, send a "signoff" command via email
> to listserv AT listmail.temple DOT edu or visit the list's Web site at
> http://listmail.temple.edu/archives/networker.html where you can
> also view and post messages to the list.
> =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

--
Maarten.Boot _at_ nl.compuware.com

It is crucial to know when it is appropriate to withdraw our attention
from things that disturb our
mind. However, if the only way we know how to deal with certain objects
is to avoid them, there will
be a severe limit as to how far our spiritual practice can take us.


--
Note: To sign off this list, send a "signoff" command via email
to listserv AT listmail.temple DOT edu or visit the list's Web site at
http://listmail.temple.edu/archives/networker.html where you can
also view and post messages to the list.
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
-Lama Thubten Yeshe, "Introduction to Tantra"
#!/usr/local/bin/perl5  -w
#=================================================================

my $SWITCHOFF = 0;

use strict;
use English;

use CWNL::Legato;
use CWNL::Lock;

use Getopt::Long;

$\ = "\n";
$, = " ";

#=================================================================

sub usage {
        print "usage: nsr_clone.pl [-with_cloning] [-silent] [-verbose] 
[-help]";
        print "\t-silent stops the summary";
        print "\t-verbose shows all records in the cloning process";
        print "\t-with_cloning starts the actual cloning otherwise info only";
        print "\t-help shows this";

        exit 0;
}

#=================================================================

my $VERBOSE = 0;
my $SILENT = 0;
my $WITH_CLONEING = 0;

# HANDLE OPTIONS
{
        no strict 'vars';

        $GetOpt::Long::order = $PERMUTE;
        $GetOpt::Long::order = $PERMUTE;

        $opt_verbose = 0;
        $opt_silent = 0;
        $opt_help = 0;
        $opt_with_cloning = 0;

        &GetOptions(
                "verbose",
                "silent",
                "help",
                "with_cloning",
        ) || &usage;


        if( $opt_verbose )   { $VERBOSE = 1; }
        if( $opt_silent )   { $SILENT = 1; }
        if( $opt_help )   { &usage; }
        if( $opt_with_cloning )   { $WITH_CLONEING = 1; }

}

#=================================================================
# BUILD THE QUERY

my @QUERY = ();
{
        my $from_pool2="CWNLSERVERS";

        #my $to_old = "12 hours ago";
        #my $to_old = "24 hours ago";
        my $to_old = "48 hours ago";

        # select all savesets that are FULL from POOL
        #               and have 1 copy only
        #               and are complete
        #               and not recyclable
        #               and whose parent_savesetid is 0
        #               are older than 12 hours but not older that 7 days
        #

        push(@QUERY,"savetime > $to_old");
        push(@QUERY,"pool=$from_pool2");
        push(@QUERY,"copies=1");
        push(@QUERY,"!incomplete");
        push(@QUERY,"!ssrecycle");
}

#=================================================================
# BUILD THE REPORT

my @REPORT = ();
{

        # list the savesetid and the name
        # name is selected to elimminame the continuation savesetes that start 
with <1 D:> and the like
        #

        push(@REPORT,"ssid");
        push(@REPORT,"pssid");
        push(@REPORT,"volume");
        push(@REPORT,"client");
        push(@REPORT,"savetime");
        push(@REPORT,"level");
        push(@REPORT,"ssflags");
        push(@REPORT,"totalsize");
        push(@REPORT,"name");
        push(@REPORT,"attrs");
}

#=================================================================
# collect the data

my %VOLUMES = ();
my %CLIENTS = ();

my %SSID = ();
{
        my $query =  join(',',@QUERY);
        my $report = join(',',@REPORT);

        my $mminfoline="$Legato::mminfo -otc -q '$query' -r '$report' | ";
        my $sum = 0;

        print $mminfoline;

        open(IN,$mminfoline) || die "FATAL:cannot open '$mminfoline',$!";
        while(<IN>) {
                chop;

                s/SYSTEM STATE/SYSTEM_STATE/;
                s/SYSTEM FILES/SYSTEM_FILES/;
                s/SYSTEM DB/SYSTEM_DB/;

                my @A = split;

                # skip all non-server type groups
                next if /group:tmp_/;
                next if /group:TESTDISK/;
                next if /group:CWNL_DESKTOP/;
                next if /group:CWNL_LAPTOP/;
                next if /group:CWNL_INSTALL/;
                next if /group:CWNL_VMS_DEFAULT/;
                next if /group:A\d/;

                next if $A[4] =~ /tesys06/;

                # skip the incremental level
                next unless $A[5] =~ /full/;

                s/\s+/ /g;
                print if $VERBOSE;

                # skip the header line
                next if $A[0] =~ /ssid/;

                $VOLUMES{$A[2]} = $A[2];
                $CLIENTS{$A[3]} = $A[3];

                my $ssid = 0;
                if( /^\s*(\d+)/ ) {
                        $ssid = $1;
                }
                if( ! (defined $SSID{$ssid}) ) {
                        $sum += $A[7];
                }

                # skip if this ssid has pssid of non-zero
                next if $A[1] != 0;

                # skip the continued savesets in cloning they are automatically 
added
                next if $A[8] =~ /<\d+>/;

                # store the ssid for later processing
                if( $ssid ) {
                        $SSID{$ssid} = $ssid;
                }
        }
        close IN;

        if( $VERBOSE || (!$SILENT) ) {
                printf "TOTAL_SIZE: %.4f Gb\n" , $sum /(1000 * 1000 * 1000);
                print "CLIENTS: " , join("\n\t",sort keys %CLIENTS);
                print "VOLUMES: " , join("\n\t",sort keys %VOLUMES);
        }
}

if( $WITH_CLONEING )
{
        my $pid;

        if( $SWITCHOFF ) {
                print "CLONING SWITCHED OFF temporary: MBT";
                exit 1;
        }

         &Lock::my_lock($PROGRAM_NAME);

        my $to_pool="CWNLFULLCLONE";
        my $nsrcloneline="$Legato::nsrclone -v -s $Legato::server -b '$to_pool' 
-S " . join(' ',sort keys %SSID);
        print $nsrcloneline;
        FORK: {
                if( $pid = fork) {
                   # Parent here
                   # child process id is availible in $pid

                   print $pid;
                   wait;

                } elsif (defined $pid) { # $pid is zero here if defined
                   # CHILD CODE HERE
                   # Parent pid is availible with getppid

                   my $status = 0;

                   $status = exec $nsrcloneline;
                   exit $status;
                } elsif ($! =~ /No more processes/ ) {
                        # EAGAIN, supposedly recoverable fork error
                        sleep 5;
                        redo FORK;
                } else {
                        # weird fork error
                        &Lock::my_unlock($PROGRAM_NAME);
                        die "FATAL: cant fork, $!";
                }
        }


        &Lock::my_unlock($PROGRAM_NAME);
}

__DATA__

--
Note: To sign off this list, send a "signoff" command via email
to listserv AT listmail.temple DOT edu or visit the list's Web site at
http://listmail.temple.edu/archives/networker.html where you can
also view and post messages to the list.
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
<Prev in Thread] Current Thread [Next in Thread>