perl script for generates a report for backup times

Hi all,

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

i think this can be achived by perl it seems

is anybody there to advice me how i can go ahead.

appreciated a lot for help

thanks

Post your input files (*.begin and *.end) and desire output.

You don't need perl for this. You could use a for loop to go through the files and use stat(1) to get the timestamp.

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

Hi,

oracle >more testdb.begin
---------------------------------------------------------------------------
11/10/10-02:47:30 --- testdb --- Beginning hot backup...
---------------------------------------------------------------------------
/mounts/testdb_data/oradata/testdb/dbfiles/system01.dbf
/mounts/testdb_data/oradata/testdb/dbfiles/sysaux01.dbf
/mounts/testdb_data/oradata/testdb/dbfiles/undotbs01.dbf
/mounts/testdb_data/oradata/testdb/dbfiles/users.dbf
/mounts/testdb_data/oradata/testdb/dbfiles/tools.dbf
/mounts/testdb_data/oradata/testdb/dbfiles/mpidata01.dbf
/mounts/testdb_data/oradata/testdb/dbfiles/redo01.log
/mounts/testdb_data/oradata/testdb/dbfiles/redo02.log
/mounts/testdb_data/oradata/testdb/dbfiles/redo03.log
/mounts/testdb_data/oradata/testdb/dbfiles/control01.ctl
/mounts/testdb_temp/oradata/testdb/tmpfiles/temp01.dbf
GROUP# THREAD# SEQUENCE# MEMBERS STATUS
---------- ---------- ---------- ---------- ----------------
1 1 601 1 INACTIVE
2 1 602 1 INACTIVE
3 1 603 1 CURRENT
Switching logfile...
System altered.

---------------------------------------------------------------------------
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 ----------

any sample script for this please

Hi,

Try this

#!/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

Hi,

i got this error

oracle >sh test.sh
test.sh: syntax error at line 12: `p=$' unexpected

can you help me further please

Thanks
Prakash

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.

tyler_durden