we do have daily oracle database backups and i need to generate report of each database start point and end point
we are using netapp snapshot(filer level) for backups.
all backups logs will be come in one directory
/u01/app/oracle/backup/hostname/log/*
here hostname=usadc*
for each host we have n number of databases
suppose i have hostname usadc01 and i have 5 databases residing in this and i take any one database say test
/u01/app/oracle/backup/usadc01/log/ in this path i will get 2 files for this database test.begin and test.end in these 2 files i will get database backup bagin time(test.begin) and database end time(test.end) here i need to parse these 2 files to take timestamp and need to direct to some file
and we have 40 servers and 300 databases
all servers will start from usadc in the path /u01/app/oracle/backup/
so in a loop i need to go one by one directory and for each server i need to go the path /u01/app/oracle/backup/usadc01/log/ here there will be n no of databases and for each database there will be 2 log files (*.begin and *.end) and i need to take the timestamp of these 2 files and need to direct to some file
find /u01/app/oracle/backup -type f -name "*.begin" |where read file
do
begin=$file
end=${file%.*}.end
# parse these 2 files to take timestamp and need to direct to some file
done
---------------------------------------------------------------------------
11/10/10-02:47:44 --- testdb --- Running: Alter database begin backup.
---------------------------------------------------------------------------
Database altered.
6 files out of 6 are in backup mode.
oracle >more testdb.end
---------------------------------------------------------------------------
11/10/10-03:15:29 --- testdb --- Finishing hot backup...
---------------------------------------------------------------------------
---------------------------------------------------------------------------
11/10/10-03:15:32 --- testdb --- Running: Alter database end backup.
---------------------------------------------------------------------------
Database altered.
0 files out of 6 are in backup mode.
Backing up control file to trace...
admindir = /u01/app/oracle/admin
udumpdir = /u01/app/oracle/admin/testdb/udump
Database altered.
a /u01/app/oracle/admin/testdb/udump/testdb_lgwr_11077.trc 6K
a /u01/app/oracle/admin/testdb/udump/testdb_ora_19457.trc 2K
a /u01/app/oracle/admin/testdb/udump/testdb_ora_27106.trc 4K
Switching logfile...
System altered.
Copying logs to arch_hold...
Cleaning up old logs in arch_hold
Attempting to tar files created during the hot backup ...
oracle >pwd
/u01/app/oracle/backup/usadc-0001/log
bold marked timestamp i need to capture
appreciated your help
Thanks
Prakash
---------- Post updated at 11:41 PM ---------- Previous update was at 11:40 PM ----------
#!/bin/sh
i=1
for i in {1..40}
do
j=$i
if [ $j -lt 10 ]; then j="0"$i; fi
cd /u01/app/oracle/backup/usadc"$j" && cd log
k=1
ls *.* | sort | grep "\(begin\|end\)$" | while read file
do
p=$(expr $k % 2)
if [ $p == 0 ]; then
res=$(perl -nle 'if(/(\d+\/\d+\/\d+-\d+:\d+:\d+).*(Beginning|Finishing)/) {print $1;}' $file1 $file)
new_file=$(echo $file1 | awk -F"." '{print $1}')
echo "$res" > $new_file".NEW"
else
file1=$file
fi
k=$(expr $k + 1)
done
done
For an all-Perl solution, you could do something like this -
#!/usr/bin/perl -w
use File::Find;
sub wanted {
if (/begin$/){
# Read "begin" file
$file = $File::Find::name;
open (F, "<", $file) or die "Can't open $file for reading: $!";
while (<F>){if(/^([0-9\/:-]+).*Beginning.*$/){$times = "$1\n"; last}}
close(F) or die "Can't close $file: $!";
# Read "end" file
$file =~ s/begin$/end/;
open (F, "<", $file) or die "Can't open $file for reading: $!";
while (<F>){if (/^([0-9\/:-]+).*Finishing.*$/){$times .= "$1\n"; last}}
close(F) or die "Can't close $file: $!";
# Write to "times" file
$file =~ s/end$/times/;
open (F, ">", $file) or die "Can't open $file for writing: $!";
print F $times;
close(F) or die "Can't close $file: $!";
}
}
$backupdir = "/u01/app/oracle/backup";
find (\&wanted, $backupdir);
Since you haven't mentioned the location of this (third) file, I've assumed it's the same as that of "begin" and "end" files for each database.