Operating System - HP-UX
1754359 Members
4540 Online
108813 Solutions
New Discussion юеВ

Databse backup automated through Crontab

 
SOLVED
Go to solution
Jeena_1
Occasional Advisor

Databse backup automated through Crontab

Hi i'm new to Unix.I need to do a database backup on a daily basis.This databse backup requires user entry for data (example: database name,date of backup....).

I want to make this automated using the crontab, but i'm not sure how to create a script to run this databse backup daily through crontab.

Can someone assist me on how to create this script???

pleaseeee.
18 REPLIES 18
VEL_1
Valued Contributor

Re: Databse backup automated through Crontab


Put all your database related commands in
# crontab -e

# Will execute the
15 1 * * *
Mel Burslan
Honored Contributor

Re: Databse backup automated through Crontab

easy part of the answer is the automating the process via cron.

logged in as root, run

crontab -e

and add this line

00 02 * * * /oracle/backup_database.sh

and save and exit.

this line will let your system run the /oracle/backup_database.sh script every day at 2:00 AM in the morning.

the hard part of the question answer is what will be inside the /oracle/backup_database.sh script ?

The answer is : it all depends. Depends on what ? Well, first it depends on how your database container(s) are structured ? Is it a filesystem structure or raw disk ? Do you have any backup software to use (like veritas netbackup or HP Data Protector) ? Or you would like to use fbackup ?

If you can tell more details, I am sure you will get better tailored answers.
________________________________
UNIX because I majored in cryptology...
renarios
Trusted Contributor

Re: Databse backup automated through Crontab

Hi Jaskirat,

Can you tell us what your environment looks like (Unix version, Database software and version)?

Cheers,

Renarios
Nothing is more successfull as failure
Muthukumar_5
Honored Contributor

Re: Databse backup automated through Crontab

You can do it easily with cron tab scheduling.

Make a script to use configuration for database name, date of backup. Based on that backup, you can start executing backup script with cron tab.

First create your user configuration file that will get user entry for data. Read that configuration file from your script as,

.

in the backup script. Execute cron based on your need.

hth.
Easy to suggest when don't know about the problem!
Jeena_1
Occasional Advisor

Re: Databse backup automated through Crontab

Hi....First, thanks to all for the reply..

According to Mel's solution,yes I know that the command for crontab is crontab -e.
What I don't know is what to put in the /oracle/backup_database.sh script .

Information about my system:-
-It is a Unix server
-Oracle database
-I log in into the server
-I come to a page where I have a few options
-From the options I choose database backup
-A user prompt comes out asking me what is the database name for backup....so I key in the database name
-Another user prompt comes out asking me for table name for backup...so I key in table name
-Backup will be in process...and is stored in a directory cd /u01/backup/exp

I don't know how to create the script...

Please help...
Yogeeraj_1
Honored Contributor

Re: Databse backup automated through Crontab

hi

Since you are running Oracle Database, you should be using RMAN for backup. This is the easiest way.

see the url below on how you would go about configuring rman (if you have not already done so, of course):
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96566/toc.htm

the rest is to create the script to do the backup then schedule the script as described above.

if you need any further help, do let us know.

regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: Databse backup automated through Crontab

hi again,

a typical backup script for your full database backup would be:


#!/bin/sh
##############################################################################
#Script name: rman_full.sh
#Description: RMAN full backup script
#last Modified: Yogeeraj-10/01/2003
##############################################################################
messagelog="/backup/rman/logfiles/rman_full-`date +%d%m%y-%H%M`"
rman target xxx/xxx@mydb rcvcat rman/rman@catalog msglog $message
log </dev/null
run {
allocate channel fs1 type disk format '/backup/rman/full/fs1/df_%u_%s_$t.%p';
allocate channel fs2 type disk format '/backup/rman/full/fs2/df_%u_%s_$t.%p';

set limit channel fs1 kbytes=750000;
set limit channel fs2 kbytes=750000;

#Backup the whole database
backup
tag Whole_database_hot
database;

#Switch out of the current logfile
sql 'alter system archive log current';

#Backup the archived logs
backup
archivelog all
format '/backup/rman/full/fs1/al_%u.%p';

#Backup a copy of the controlfile that contains records for the
#other backups just made
backup
current controlfile
tag = cf1
format '/backup/rman/full/fs1/cf_%u.%p';
}
exit;
EOF
#end of script




hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: Databse backup automated through Crontab

hi again,
sorry for the corrupted output!

script attached.

let us know it it helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Jeena_1
Occasional Advisor

Re: Databse backup automated through Crontab

Hi Yogeeraj....thanks 4 your solution.I also forgot to mention that I know very basic stuff in Oracle as well...and i must admit that I never knew that RMAN can be used for backup...So, i'll have to read the link you sent me on RMAN ;) ...then I shall see how it can help in my database backup.

I am actually only doing a backup on a table in a database.So, i'm not sure if using the option "full databse" in RMAN will be a good choice....Can you let me know of that...

The script you sent me..I don't entirely understand it...is there any simpler code or something...

Thanks