Operating System - HP-UX
1832095 Members
3066 Online
110038 Solutions
New Discussion

Re: Automate database backup procedure

 
ajk_5
Frequent Advisor

Automate database backup procedure

Dear all,

I want to automate the database backup procedure which auto run the backup script (Attached in the email) in the evening (I guess put it in the crontab). However, I concern that some problems may occur during the backup procedure:

- forget to put backup tape in DD3 tape drive
- Backup tape error
- Backup tape full
- Tape drive error
- System error

I am just a beginner writing unix script. Could you tell me how I can keep the different problems to different logs in the backup script and how can I know the problem occur immediately when I am at home? (For like Mobile phone, SMS, etc)

Also, the Day-end process has another script (For like startup databases after Database backup, etc) after the Database backup script, how can I handle the backup script if any problem happens?

Please give me some ideas. Thanks a lot.



Best Regards
Ajk
7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: Automate database backup procedure

Key scripting concept.

Check the success of an operation right after you do it.


rc=$?

if [ $rc gt 0 ] then
mailx -s "Tape write failed...."
exit $rc
fi

Run your job in cron as follows:

at 10:05 p.m. monday thru fruday
5 20 * * * 1-5 su - oracle -c "backup command" 2>&1 | mailx -s "Oracle nightly backup" yourname@yourdomain.com

The key factor is to check for errors and take appropriate action. I can help you with the script. I work for points.

I even work in real time for bucks, but honestly I think you can handle it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
ajk_5
Frequent Advisor

Re: Automate database backup procedure

Here is the backup script.

Thanks.

Best Regards
Ajk
malay boy
Trusted Contributor

Re: Automate database backup procedure

Hi,
There are various techique expert people do the check the tape.Simple guy like me I used simpler method :

mt -t /dev/rmt/0mn rew

to check whether the tape are loaded or not.

or simple check on whether tape are ok or not ,try to write something to tape :

fbackup ....

and check whether the command are successful with $?.

I agree with SEP , you can do it..

regards
mB
There are three person in my team-Me ,myself and I.
Con O'Kelly
Honored Contributor

Re: Automate database backup procedure

Hi Ajk

I haven't noticed Michael Tully on the forums today, so I'll attach a link where he provides a backup script that may give you a few ideas!

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x1d550ea029a2d711abdc0090277a778c,00.html

SEP & Twang have given you some good ideas. My advice for writing scripts is to keep everything seperated in functions as far as is possible.

For example you could have seperate functions to

1. Check the Tape (eg check its in the drive & writeable)
2. Check Oracle is down or in Hot backup prior to backup.
3. Perform the backup.
4. Check the logs after backup.

Cheers
Con
twang
Honored Contributor

Re: Automate database backup procedure

In my own experience, we have 3 Oracle instances(no 24x7) runing on same machine, we shutdown all the instances and take a closed-database backup every night. What I am doing now is to schedule a cronjob via crontab at mid night. The script will schedule other scripts to shutdown all the 3 instances via "at" instead of "crontab". If any problem occurs, script will exit without schedule the next task. So I can check the cause of the problem at the next morning. For "less important" instances(they are for data warehouse purpose), it allows me to performs the backup in such style.
ajk_5
Frequent Advisor

Re: Automate database backup procedure

Thanks Steven E Protter! I appreciate your help. I think I can do it. :)



Best Regards
Ajk
RAJESH GANGADHARAN
Regular Advisor

Re: Automate database backup procedure

Hi You can use the following lines for checking tape drive status
STAT=`mt -f /dev/rmt/0m stat |awk '$4 == "online" {print 1}'`
if [ STAT -eq 1 ]
then
you can add the lines for backup
fi


for checking whether the backup was successfull
use the following
if [ $? -eq 0 ]
then
echo "backup completed " |tee -a $LOG_FILE
echo "Ejecting the media....."
sleep 10
mt -f $DEV offl #for ejecting media.
else
echo "Error during backup.."| tee -a $LOG_FILE
fi

You can send all the logs to a log file and then send that file as a mail.
make sure that sendmail is configured and running in your system.

-Rajesh

Let the choices you make today be the choices you can live with tomorrow.