Cribbage Game - By my brother Craig.
Moving Redo Logs - Mark Hessel
Key Words: System move, moving redo logs, moving undo logs, moving database change logs
I divised the following to move change logs from one system to another in this case an SAP system with an oracle database.
perl script
# Mark Hessel 20070317
# this process assumes that
ssh is setup between the source system and the destination system.
#
varibles to change for each system
# the last file *.dbf file will have to be
moved manually
$redo_log_path =
"/oracle/SID/saparch_DCC/";
# source system
$redo_log_destination =
"sidadm\@sid_name.xyz.com:/oracle/SIS/sapdata1/"; # destination system
scp style
# gzip directory
$gzip_dir =
"/usr/contrib/bin/";
# turn off moving of unzipped files; 1 send both files,
0 send just gzipped files
$send_non_gzipped =
0;
#notification
$adm_email =
"mark_hessel\@somecompany.com";
$pager_email =
"5419171194\@archwireless.net";
#process files
$status_file =
$redo_log_path."redo_process_status";
# this file must initially exist (with 0) for process to work
$error_file =
$redo_log_path."error.log";
# errors during transfer (should initally exist)
$skipped_process_file =
$redo_log_path."skipped_processing.log"; # file notes time of
skipped processing because busy
$process_history =
$redo_log_path."process_history.log";
# date|ls entry|transfer time seconds
$stdout =
$redo_log_path."stdout";
# stdout for system commands
$errout =
$redo_log_path."errout";
# errout for
system commands
# check if another redo_log process is running.
#
open file processing if 1 is 0
if not.
if (open(INPUT, "<$status_file")){}else{`mailx
-s"$status_file doesn't exist!" $adm_email <
/dev/null`; exit;}
while (<INPUT>)
{
# strip
leading and ending whitespace
$_ =~ s/^\s+//;
$_
=
~ s/\s+$//;
# if process file is 0, continue to
process
if (! $_)
{
last;
}
else
# log date and time in skipped_processing, if status file is over 1 hour old,
page me and exit
{
if
(open(OUTPUT, ">>$skipped_process_file")){}else{`mailx
-s"$skipped_process_file problem!" $adm_email < /dev/null`;
exit;}
$date =
`date`;
print OUTPUT
$date;
close
OUTPUT;
close
INPUT;
# now check if the status file is over
1 hour, if true page me
if (-M $status_file
> 1/24)
{
`mailx -s"$process_file
over 1 hour old!" $pager_email <
/dev/null`;
}
exit;
}
}
close INPUT;
#begin processing put 1 in the status file.
if
(open(OUTPUT, "> $status_file")){}else{`mailx -s"problem writing to
$status_file!" $adm_email < /dev/null`; exit;}
print OUTPUT "1";
close OUTPUT;
# do ls -ltr into array, move oldest files and leave
the newest - just to make sure newest file is not created when process to
move
# is
being done
chdir ($redo_log_path);
@files_to_move = (); # initialize
@files_to_move
= `ls -ltr *.dbf`; # get output of newest to oldest files
into array
#
$#files_to_move = 1 less then items in array
$process_to = $#files_to_move;
$i=
0;
$file_transmission_error = 0;
$gzip_error = 0;
foreach $record (@files_to_move)
{
if ($i ==
$process_to){next;} # skip processing of
newest file
#
***********************************************************************************************
# ******************* this is where all the work is being done
**********************************
#
***********************************************************************************************
($permissions, $access_num, $owner, $group, $size, $month,
$day, $time, $file) = split(/[ \t\n]+/, $record); #split on
white space
$i++; # processed on file, error or not
if ($send_non_gzipped)
{
$start_time =
time;
# copy the file
$error = system"(scp -pq $file
$redo_log_destination$file > $stdout) 2>
$errout";
# if the copy fails, skip
write to error_file
if ($error) # system
returns non 0 for error
{
$file_transmission_error =
1;
if (open(ERR, ">>
$error_file")){}else{`mailx -s"problem writing to $error_file!" $adm_email <
/dev/null`; exit;}
$date
= `date`;
print ERR
$date;
print ERR
$record;
`cat $errout
>> $error_file`;
close
ERR;
next;
}
$end_time =
time;
$current_run_time = $end_time -
$start_time;
# system"rm -f $file";
if (open(LOG, ">>
$process_history")){}else{`mailx -s"problem writing to $process_history!"
$adm_email < /dev/null`; exit;}
chop
$record;
$date =
`date`;
chop $date;
print LOG
"$date|$record|$current_run_time\n";
close
LOG;
} #
if ($send_non_gzipped)
# **************** send gzipped files
*********************
$gzfile = $file.".gz";
$gzip_exe =
$gzip_dir."gzip";
$error = system "($gzip_exe $file
> $stdout) 2> $errout";
if ($error) # system returns non
0 for error
{
$gzip_error =
1;
if (open(ERR, ">>
$error_file")){}else{`mailx -s"problem writing to $error_file!" $adm_email <
/dev/null`; exit;}
$date =
`date`;
print ERR
$date;
print ERR
$gzfile;
`cat $errout >>
$error_file`;
close ERR;
next;
}
$start_time = time;
$error = system"(scp -pq
$gzfile $redo_log_destination$gzfile > $stdout) 2>
$errout";
# if the copy fails, skip write to
error_file
if ($error) # system returns non 0 for error
{
$file_transmission_error =
1;
if (open(ERR, ">>
$error_file")){}else{`mailx -s"problem writing to $error_file!" $adm_email <
/dev/null`; exit;}
$date =
`date`;
print ERR
$date;
print ERR
$record;
`cat $errout >>
$error_file`;
close ERR;
next;
}
$end_time = time;
$current_run_time = $end_time
- $start_time;
$record = `ll $gzfile`;
system"rm
-f $gzfile";
if (open(LOG, ">>
$process_history")){}else{`mailx -s"problem writing to $process_history!"
$adm_email < /dev/null`; exit;}
chop $record;
$date = `date`;
chop $date;
print LOG "$date|$record|$current_run_time\n";
close LOG;
#
**************** test sending gzipped files *********************
} # foreach record in list of files
to send
if ($file_transmission_error) # this just emails
the error type. Look at the logs for errors
{
`mailx
-s"problem scping file!" $adm_email < /dev/null`;
}
if
($gzip_error)
# this just emails the error type. Look at the logs for
errors
{
`mailx -s"problem gzipping file!" $adm_email <
/dev/null`;
}
# done processing put 0 in the status file.
if
(open(OUTPUT, "> $status_file")){}else{`mailx -s"problem writing to
$status_file!" $adm_email < /dev/null`; exit;}
print OUTPUT "0";
close OUTPUT;
# history report daily