Beruflich Dokumente
Kultur Dokumente
CRON
*************************
*************************
Script
*************************
$SIG{INT}=\&interceptCtrlC;
my $LOGFILE = "/var/log/dosnap.log";
print "Logs will be written to $LOGFILE\n\n";
my $todayDate = localtime time;
###################################################################################
#########
# 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);
}
###################################################################################
#########
#
# createSnap
#
# Description: createSnap for a specific filesystem
# Inputs: filesystem name
# Outputs: none
#
###################################################################################
#########
sub createSnap($)
{
my $thisFS = shift;
my $existCkpt = 0;
}
# 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";
}
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;
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
## Validate Access to di/cs
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sub ValidateAccess() {
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;
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);
$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/orabeginbuWrap.sh
oracle$thisOpco");
$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);
}
}
elsif ( ( $OPCONUM >= 1 ) && ( $OPCONUM <= $MAXOPCO ) && ( $CLEAR eq 0 ) ) {
print "\n\nBacking up operator opco$OPCONUM\n";
$out=&remoteSshExec("$DINODE","/opt/dbtool/backup/orabeginbuWrap.sh
oracle$OPCONUM");
$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);
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;