Saturday, September 02, 2006

Table restore from complete RMAN backup

Scenario:
Nisha works at premier bank headquarters in Virginia.They have databases primarily running with versions 8i(8.1.7.4) and 9i (9.2.0.6).Full backups are scheduled to run every Sunday using rman. Archivelog backups are taken every two hours. On Tuesday night at 8pm Nisha receives call from management team that, one of application person had dropped a SALES table from "SALE" database.

Nisha is engaged on a conference call to gather more details. Soon she realizes that, she may be out of options other than doing full restore/recovery of database and that will take long time. At this point of time she plans to consult with other DBA team members from branch office. Brian came up with alternate plan which will allow to perform table restore up to point in time in past using RMAN backups.


Plan of action:

Brian lays out complete Process and scripts and explain details to Nisha,

1] Find out last full successful backup.
2] Pickup date and time of restore and calculate duration between last full backup and restore time.
3] Find archivelogs required to roll forward from last full backup till restore time.
4] Now find out tablespace in which table was created.
5] Identify datafiles in that tablespace.
6] Calculate space required for datafiles and other required files. Lets assume SALES_DATA tablespace had 4 datafiles each of 2G, so total of 8G then we have system tablespace of 300M and 2 redo log groups with 2 members each of 100M that will be total of 400M. Finally total archivelogs required are 24 and hence space for archivelog required for recovery will be 2.4G.
Total space will be 8G (datafiles )+ 2.4G (archive) + 400M( redo) + 300M(system) + 200M (control files and other scripts)
is 11.3G.
7] Find out oracle home which have binaries installed and running with same version
8] If you don't want to perform restore/recovery on production server and you have available test server with similar configuration, you can add space on TEST server and NFS mount to prod server to avoid redirected restore and recovery effort.
In this case, test server has similar version and patchset available and hence we will use TEST server to run restore/recovery.

We had temp space /u_stage of 15G which we mounted on TEST server and then NFS mounted to PROD server which will allow us to perform restore operation. Once restore is complete, we will remove nfs mount and perform recovery.

9] run restore of datafiles with system and 4 datafiles

run{

allocate channel t1 type 'SBT_TAPE' parms
'ENV=;

set until time "to_date('

Thursday, August 24, 2006

Sending email from Unix with attachment and your name as "reply to" person

Challenges/Requirements:
One afternoon received phone call from customer.They wanted to run a report on daily basis to look for obsolete records in database and have them mail out report for those obsolete records. This report was also going to be viewed by higher management and hence required better arrangement in email.

Thinking:
1 We all know mailx commmand by now, which will help us to send emails from unix server to get information/reports on regular basis when put in a script and scheduled via CRON.
2 Since this email report was going to be viewed by higher management, proper text layout and viewing arrangement was necessary. So this time I decided to add attachment to email along with the body Which is different than sending regular mail.
3 One major drawback I have seen since so many years is that, we always send email out via mailx command where recepient receives that email from "unix user" who is running mailx command. In most of database accounts user name is oracle, so we get sender as "oracle@'hostname.domain.com' ". If /etc/passwd file has owner as physical person, then we may see alias to above email sender as " 'account owner name' oracle@'hostname.domain.com' "
4 Also, when recepient do "reply to all", they will need editing in sender list, else it will bring "mailer daemon" to replyer of that email since unix host will not receive any emails.
5 Finally, If I am not around to reply in repsonse to any issues in that report, we needed my manager to be CC'ed so that, he can allocate resource to take care of any work.
6 Creating report was easy part of all. So finally decided to create a quick script before I leave home for the day.


Implementation/scripts/outputs :
1 created a regular shell script and scheduled via CRON
2 "-r" in mailx command is "reply to" option. If we provide "my_name" along with -r option then, it will be replied back to me.
3 Attachment to mailx command is simple. We need to pipe "body of email" to file then pipe that to uuencode command to make an attachment and than pipe it again to mailx

--Script details
LOGFILE=/home/oracle/1.log
DATA=/home/oracle/1.data
.
..
... {rest of script to spool data via sqlplus in to file named LOGFILE }
....
echo "Please find attached file.\n Thanks,\n Sandeep " >${DATA}|uuencode ${LOGFILE} Obsolete_data.txt|cat ${DATA} -|mailx -s "Obsolete data from ${ORACLE_SID} database" -c " 'my_manager'@domain.com, 'my_name'@domain.com" -r " 'my_name'@domain.com"
" 'client_1'@customer.domain.com,'client_2'@Customer.domain.com"
.....


4 In mailx command
mailx -s "Obsolete data from ${ORACLE_SID} database" -c " 'my_manager'@domain.com, 'my_name'@domain.com" -r "@domain.com" " 'client_1'@customer.domain.com, 'client_2'@Customer.domain.com"

-c will perform Carbon Copy to my manager
-r will "reply to" person described after that option
-s is subject of email
5 In uunecode command
uuencode ${LOGFILE} Obsolete_data.txt|cat ${DATA}

${LOGFILE} is file spooled by sqlplus which has all report of obsolete record. Remember to view this file in "wordpad" when received in email as an attachment to see proper format.
Followed by attachment is name you want to provide to attached file
${DATA} contains body of email.

Conclusion:
We have successfully created email from unix host with an attachment which not only provides security to sensitive data,but also improves readability of emails by keeping required information in attached files. Customer was very pleased to receive daily report with proper format along with management contacts from my side.

Introduction...

Hello folks,

I have just created this blog for posting out rman/backup and recovery techniques and discuss new/unpublished features along with with tips which will help us supporting Oracle databases.

Stay tuned for upcoming post.

Sandeep.