Sie sind auf Seite 1von 9

*************************

CRON
*************************

SC-1:~ # crontab -l|grep -i dosnap


0 23 * * 0 /opt/backup/scripts/dosnap.pl -opco 1

*************************
Script
*************************

SC-1:~ # cat /opt/backup/scripts/dosnap.pl


#!/usr/bin/perl
#
# <emxver><ln>Backup doclone.sh
Script</ln><vl>__EMX_EMBEDDED_VERSION_LABEL__</vl><iv>__EMX_EMBEDDED_INTERNAL_VERSI
ON__</iv></emxver>
# COPYRIGHT (c) Ericsson Communications Inc. Canada (LMC), 2008.
# All Rights Reserved.
#
# The copyright to the computer program(s) herein is the property
# of Ericsson Communications Inc. Canada (LMC). The program(s) may
# be used and/or copied only with the written permission from
# Ericsson Communications Inc. Canada (LMC) or in accordance with
# the terms and conditions stipulated in the agreement/contract
# under which the program(s) have been supplied.
# ----------------------------------------------------------------
# Title: dosnap.pl
# Description: This script is intend for snap creation of a specific operator's
volumes on a EMC NAS
# Copyright: Copyright(c)
# Company: Ericsson
#
# History
# Date Description
# 2009-09-24 Initial Creation
# 2012-07-24 Added support for long names(24). Removed _replica from backup
list
# 2012-09-20 Added a "clear" procedure.

$SIG{INT}=\&interceptCtrlC;

my $script_dirname = `/usr/bin/dirname $0`; chomp($script_dirname);


my $script_basename = `/bin/basename $0`; chomp($script_basename);
my $pwd = `/bin/pwd`; chomp($pwd);
my $fullDirName = "";
if ( $script_dirname =~ m/^\.\// ) {
$fullDirName = $pwd.$script_dirname;
} else {
$fullDirName = $script_dirname;
}

my $LOGFILE = "/var/log/dosnap.log";
print "Logs will be written to $LOGFILE\n\n";
my $todayDate = localtime time;

glob @DI = ();


glob $DI0 = "di-00-o";
glob $DI1 = "di-01-o";
glob $CS = "nasadmin\@cs-00-o";

open(STDOUT, "| /usr/bin/tee -a $LOGFILE STDOUT");


print
"\n***********************************************************************\n";
print "$todayDate\n";
print
"***********************************************************************\n\n";

###################################################################################
#########
# Usage
###################################################################################
#########
my $Usage = "";

$Usage= "\nUsage:\n";
$Usage.=" $0 [options]\n\n";
$Usage.="Options available:\n";
$Usage.=" -opco <n> Opco number to create a snap on. Accepted values
are between 1 and 16.\n";
$Usage.=" -all This will create snaps on all Opcos.\n";
$Usage.=" -db This will create snaps on all databases' file
systems only.\n";
$Usage.=" -noclean This will prevent previous snaps from being deleted
(this may affect performance).\n";
$Usage.=" -clear This will clear all snaps for the specified opco
(no new snap taken).\n";
$Usage.="\n\n";

###################################################################################
#########
# Parsing options
###################################################################################
#########
my $OPCONUM = "";
my $NOCLEAN = 0;
my $CLEAR = 0;
glob $DBONLY = 0;
while ( defined $ARGV[0] ) {
if ( $ARGV[0] =~ /-opco/ ) {
shift;
$OPCONUM = $ARGV[0];
} elsif ( $ARGV[0] =~ /-all/ ) {
$OPCONUM = "ALL";
} elsif ( $ARGV[0] =~ /-noclean/ ) {
$NOCLEAN = 1;
} elsif ( $ARGV[0] =~ /-db/ ) {
$DBONLY = 1;
} elsif ( $ARGV[0] =~ /-clear/ ) {
$CLEAR = 1;
} else {
print STDERR "*** ERROR: Option $ARGV[0] not recognized.\n";
die $Usage;
}
shift;
}
if ( $OPCONUM eq "" ) {
print $Usage;
exit 1;
}

###################################################################################
#########
#
# clearckpt
#
# Description: Deletes the checkpoint filesystem
# Inputs: opco
# Outputs: none
#
###################################################################################
#########
sub clearckpt($)
{

my $thisOpco = shift;

if ( $DBONLY == 1 ) {
$FSList=&remoteSshExec($CS, "/opt/ericsson/NASTools/nascmd nas_fs -info -all
| awk '\$1==\"name\" {printf \$3\"\\n\"}' | grep \"opco$thisOpco\"|grep \"[m|d][c|
i][d|1|2]\" | grep \"_ckp\" | grep -v _replica ");
@FSList=split("\n",$FSList);
}
else {
$FSList=&remoteSshExec($CS, "/opt/ericsson/NASTools/nascmd nas_fs -info -all
| awk '\$1==\"name\" {printf \$3\"\\n\"}' | egrep \"config_common\|opco$thisOpco\"
| grep \"_ckp\" | grep -v _replica ");
@FSList=split("\n",$FSList);
}

# delete existing snaps


foreach $thisCkpt ( @FSList ) {
chomp($thisCkpt);
my ($thisID, $thisCkptName, $thisSnap, $thisStatus, $thisPercentUse,
$thisSnapPct, $thisSnapUse) = split(/\s+/, $thisCkpt);
print "\t-> Deleting snap: $thisCkpt \n";
$rc=&remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd nas_fs -delete $thisCkpt
-option umount=yes");
if ( $rc =~ m/Error/ ) {
print "\t===> ERROR: Failed to delete snap $thisCkptName!\n";
}
}

###################################################################################
#########
#
# createSnap
#
# Description: createSnap for a specific filesystem
# Inputs: filesystem name
# Outputs: none
#
###################################################################################
#########
sub createSnap($)
{
my $thisFS = shift;
my $existCkpt = 0;

# Verify if there is a snap on this FS


my $SnapList = &remoteSshExec($CS, "/opt/ericsson/NASTools/nascmd fs_ckpt
$thisFS -list | grep $thisFS");
my @SnapList = split("\n",$SnapList);
if ( $#SnapList >= 0 ) {
if ( $NOCLEAN ) {
$existCkpt = 1;
} else {
# delete all existing snaps
foreach $thisCkpt ( @SnapList ) {
chomp($thisCkpt);
my ($thisID, $thisCkptName, $thisSnap, $thisStatus,
$thisPercentUse, $thisSnapPct, $thisSnapUse) = split(/\s+/, $thisCkpt);
print "\t-> Deleting snap: $thisCkptName \n";
$rc=&remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd nas_fs
-delete $thisCkptName -option umount=yes");
if ( $rc =~ m/Error/ ) {
print "\t===> ERROR: Failed to delete snap $thisCkptName!\n";
}
}
}

}
# Verify if there are enough space for a new snap
# Create Snap
if ( $existCkpt ) {
print "\t-> Creating snap on $thisFS\n";
my $nbsnap = &remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd fs_ckpt
$thisFS -list | wc -l");
my $thisSnap = &remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd fs_ckpt
$thisFS -Create");
my $nbaddsnap = &remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd fs_ckpt
$thisFS -list | wc -l");

chomp($nbsnap);
chomp($nbaddsnap);
#print "nbsnap=$nbsnap nbaddsnap=$nbaddsnap\n";
if ( $nbsnap >= $nbaddsnap ) {
print " ERROR: Failed to create snap on filesystem [$thisFS]!\n";
}

} elsif ( $CLEAR eq 0 ) {
# define backup pool based on current pool
my $thisBackupPool = "backup"; # default pool
my $thisPool = &remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd nas_fs
-info $thisFS | grep pool | awk '{print \$3}'");
chomp($thisPool);
if ( $thisPool =~ m/oam/ ) {
$thisBackupPool = "oam_backup";
}

# create one using backup pool


print "\t-> Creating snap on $thisFS\n";
my $nbsnap = &remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd fs_ckpt
$thisFS -list | wc -l");
my $thisSnap = &remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd fs_ckpt
$thisFS -Create pool=$thisBackupPool");
my $nbaddsnap = &remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd fs_ckpt
$thisFS -list | wc -l");

chomp($nbsnap); chomp($nbaddsnap);
#print "nbsnap=$nbsnap nbaddsnap=$nbaddsnap\n";
if ( $nbsnap >= $nbaddsnap ) {
print " ERROR: Failed to create snap on filesystem [$thisFS]!\n";
}
}
}

###################################################################################
#########
#
# getFilesystemList
#
# Description: probe EMC NAS for the list of filesystems associated to a specific
opco
# Inputs: opco number
# Outputs: none
#
###################################################################################
#########
sub getFilesystemList($)
{
my $thisOpco = shift;

if ( $DBONLY == 1 ) {
$FSList=&remoteSshExec($CS, "/opt/ericsson/NASTools/nascmd nas_fs -info
-all | awk '\$1==\"name\" {printf \$3\"\\n\"}' | grep \"opco$thisOpco\"| grep
-v \"_ckp\" | grep \"[m|d][c|i][d|1|2]\" | grep -v \"di[1|2]_opco${thisOpco}_05\" |
grep -v _replica ");
@FSList=split("\n",$FSList);
$DBONLY=2;
} elsif ( $DBONLY == 2 ) {
$FSList=&remoteSshExec($CS, "/opt/ericsson/NASTools/nascmd nas_fs -info
-all | awk '\$1==\"name\" {printf \$3\"\\n\"}' | grep \"opco$thisOpco\"| grep
-v \"_ckp\" | grep \"di[1|2]_opco${thisOpco}_05\" | grep -v _replica ");
@FSList=split("\n",$FSList);
} else {
$FSList=&remoteSshExec($CS, "/opt/ericsson/NASTools/nascmd nas_fs -info
-all | awk '\$1==\"name\" {printf \$3\"\\n\"}' | egrep \"config_common\|
opco$thisOpco\"| grep -v \"_ckp\" | grep -v \"di[1|2]_opco${thisOpco}_05\" | grep
-v _replica ");
@FSList=split("\n",$FSList);
$DBONLY=2;
}
foreach my $thisFS (reverse sort @FSList) {
chomp($thisFS);
print "\nopco$thisOpco : Create/Delete SnapShot of filesystem [$thisFS]\n";
createSnap($thisFS);

}
}
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
## Remote exec using ssh. Remote need to have the rsa_pub keys setup
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sub remoteSshExec() {
$dest=shift;
$cmd=shift;

print "\tRemote exec : ssh $dest [$cmd]\n";


$out=`ssh -o StrictHostKeyChecking=no $dest -q $cmd`;
# print "RESULT=[$out]";
return($out);
}

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
## Validate Access to di/cs
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sub ValidateAccess() {

print "Validate Remote system Access\n";


my $out=&remoteSshExec($CS, "id");
die("ERROR : Could not access $CS") if ( $out !~ m/uid/ );

my $out=&remoteSshExec($DI0, "id");
if ( $out !~ m/uid/ ) {
die("ERROR : Could not access $DI0")
} else {
push(@DI,$DI0);
}

my $out=&remoteSshExec($DI1, "id");
if ( $out !~ m/uid/ ) {
print("WARNING : Could not access $DI1, Skipping this node")
} else {
push(@DI,$DI1);
}

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Intercept the Ctrl-C
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sub interceptCtrlC {
open (STDOUT, ">&STDERR");
print "ERROR : caught $SIG{INT} CTRL-C pressed recovering the database BACKUP
MODE\n";
if ( $OPCONUM =~ /ALL/ ) {
for ( $thisOpco=1; $thisOpco<=$MAXOPCO; $thisOpco++) {
foreach $DINODE (@DI) {
$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/oraendbuWrap.sh
oracle$thisOpco");
print $out;
}
}
} else {
foreach $DINODE (@DI) {
$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/oraendbuWrap.sh
oracle$OPCONUM");
print STDERR $out;
}
}
die ("ERROR : CTRL-C pressed");
}

###################################################################################
#########
# Main procedure
###################################################################################
#########
my $MAXOPCO = 16;

# Veryfing if backup pools exists

ValidateAccess();

my $OrigDBonly = $DBONLY;
print "\nLooking for nas pool\n";
my @BackupPool = ( "backup", "oam_backup" );
my $NASPool=&remoteSshExec($CS,"/opt/ericsson/NASTools/nascmd nas_pool -list | awk
'{print \$4}'");
my @NASPool=split("\n",$NASPool);

foreach my $bkupPool ( @BackupPool ) {


my $thisPoolExists = 0;
foreach my $allPool ( @NASPool ) {
chomp($allPool);
if ( $allPool eq $bkupPool ) {
$thisPoolExists = 1;
}
}
if ( $thisPoolExists == 0 ) {
print "ERROR: Backup pool $bkupPool is missing ... exiting\n";
exit 1;
}
}

if ( ( $OPCONUM =~ /ALL/ ) && ( $CLEAR eq 0 ) ) {


print "\n\nRequesting snaps for all existing operators\n";
for ( $thisOpco=1; $thisOpco<=$MAXOPCO; $thisOpco++) {
print "Backing up operator opco$thisOpco\n";

foreach $DINODE (@DI) {

$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/orabeginbuWrap.sh
oracle$thisOpco");

if ( $out =~ m/already in backup/ ) {


print("\tWARNING : oracle$thisOpco Already in BACKUP
MODE\n\tTrying to recover by ending the BACKUP MODE\n");

$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/oraendbuWrap.sh
oracle$thisOpco");

$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/orabeginbuWrap.sh
oracle$thisOpco");
die ("\tERROR : Could not recover BACKUP MODE") if ( $out
=~ m/already in backup/ );
}
@out=split("\n",$out);
print "\t$_\n" foreach (@out);
}

getFilesystemList($thisOpco);

foreach $DINODE (@DI) {


$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/oraendbuWrap.sh
oracle$thisOpco");
@out=split("\n",$out);
print "\t$_\n" foreach (@out);
}
getFilesystemList($thisOpco);
$DBONLY = $OrigDBonly;

}
}
elsif ( ( $OPCONUM >= 1 ) && ( $OPCONUM <= $MAXOPCO ) && ( $CLEAR eq 0 ) ) {
print "\n\nBacking up operator opco$OPCONUM\n";

foreach $DINODE (@DI) {

$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/orabeginbuWrap.sh
oracle$OPCONUM");

if ( $out =~ m/already in backup/ ) {


print("\tWARNING : oracle$OPCONU Already in BACKUP
MODE\n\tTrying to recover by ending the BACKUP MODE\n");

$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/oraendbuWrap.sh
oracle$OPCONUM");

$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/orabeginbuWrap.sh
oracle$OPCONUM");
die ("\tERROR : Could not recover BACKUP MODE") if ( $out
=~ m/already in backup/ );
}

@out=split("\n",$out);
print "\t$_\n" foreach (@out);
}

getFilesystemList($OPCONUM);

foreach $DINODE (@DI) {


$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/oraendbuWrap.sh
oracle$OPCONUM");
@out=split("\n",$out);
print "\t$_\n" foreach (@out);
}

getFilesystemList($OPCONUM);
}
elsif ( $CLEAR eq 1) {
if ( $OPCONUM =~ /ALL/ ) {
print "\n\nClearing all snapshots\n";
for ( $thisOpco=1; $thisOpco<=$MAXOPCO; $thisOpco++) {
clearckpt($thisOpco);
}
}
elsif ( ( $OPCONUM >= 1 ) && ( $OPCONUM <= $MAXOPCO ) ) {
print "\n\nClearing snapshot for opco$OPCONUM\n";
clearckpt($OPCONUM);
}
}
else {
close(STDOUT);
system("rm STDOUT");
print $Usage;
exit 1;
}

print
"\n***********************************************************************\n";
print "$todayDate\n";
print
"***********************************************************************\n\n";
close(STDOUT);
system("rm STDOUT");
exit 0;

Das könnte Ihnen auch gefallen