Home » RDBMS Server » Backup & Recovery » Automate Backup/Restore (Oracle 10g , AIX)
Automate Backup/Restore [message #291083] Wed, 02 January 2008 23:41 Go to next message
panchpan
Messages: 34
Registered: October 2007
Member
Hello,
On unix side, I have written below script for taking backup. But when I tried to execute it - i found some hiccups while trying to run sql commands from unix.
Please suggest
------------------------
$ more bkp.sh
#!/bin/ksh
# make sure database is shutdown cleanly
sqlplus '/ as sysdba' <<eof
{
shutdown immediate;
startup force dba pfile=$ORACLE_HOME/dbs/init.ora;
shutdown immediate;
}
exit;
eof
#Mount the database and start backup
run {
startup mount pfile=$ORACLE_HOME/dbs/init.ora;
}
# Backup datafile, controlfile and archivelogs
rman target=/ << EOF
RUN {
allocate channel ch1 type
disk format '/u00/oradata/backup/%d_DB_%u_%s_%p_%t';
backup database include current controlfile
tag = '1_daily_backup';
release channel ch1;
}
EXIT;
EOF
# Open the database
run {
alter database open;
}
# Archive all logfiles including current
run {
sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';
}
# Backup outdated archlogs and delete them
rman target=/ << EOF
RUN {
allocate channel ch1 type
disk format '/u00/oradata/backup/%d_DB_%u_%s_%p_%t';
backup archivelog
until time 'Sysdate-2' all
delete input;
release channel ch1;
}
EXIT;
EOF
# Backup remaining archlogs
rman target=/ << EOF
RUN {
allocate channel ch1 type
disk format '/u00/oradata/backup/%d_DB_%u_%s_%p_%t';
backup archivelog all;
release channel ch1;

}
EXIT;
EOF
------------------------

Thank you!
Re: Automate Backup/Restore [message #291084 is a reply to message #291083] Wed, 02 January 2008 23:44 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>i found some hiccups
The cure for hiccups is to drink a glass of water while holding your nose.
Re: Automate Backup/Restore [message #291085 is a reply to message #291084] Thu, 03 January 2008 00:01 Go to previous messageGo to next message
panchpan
Messages: 34
Registered: October 2007
Member
Thanks ... I had some water also.

Please advice - What is wrong in the piece of code? I am not able to execute sql statements from unix.

Thank you!
Re: Automate Backup/Restore [message #291088 is a reply to message #291083] Thu, 03 January 2008 00:06 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>What is wrong in the piece of code?
I give up. What is wrong in the piece of code?
You have posted NO error;only vague statement that you think something is wrong.
You have seen the results & don't know what is wrong.
We don't know what happens & yet you expect us to give you a solution when we don't know what happens when code is invoked.

You're On Your Own (YOYO)!
Re: Automate Backup/Restore [message #291094 is a reply to message #291088] Thu, 03 January 2008 00:26 Go to previous messageGo to next message
panchpan
Messages: 34
Registered: October 2007
Member
Ok - I get what was wrong in the script. I was running sql commands within run { } , i have modified and kept all sql statements within sqlplus '/ as sysdba' <<eof
{ ... } and all the rman related commands under rman target=/ << EOF
RUN { ... }

The script looks to be working fine now - Thanks. Except one below error in below piece:
sqlplus '/ as sysdba' <<eof
{
shutdown immediate;
startup mount;
}
exit;
eof

Error is:
SQL> SP2-0042: unknown command "}" - rest of line ignored.
Re: Automate Backup/Restore [message #291097 is a reply to message #291083] Thu, 03 January 2008 00:29 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Since when are "{" and/or "}" valid within SQL*Plus?
Re: Automate Backup/Restore [message #291099 is a reply to message #291083] Thu, 03 January 2008 00:33 Go to previous messageGo to next message
panchpan
Messages: 34
Registered: October 2007
Member
Thanks - The problem is resolved now and I learn that in unix script style - SQL commands dont require parenthesis and will run as below:
sqlplus '/ as sysdba' <<eof
alter database open;
ALTER SYSTEM ARCHIVE LOG CURRENT;
exit;
eof

Thank you for the hints. Could you please share the script for open database and cold/hot backup's restoration?

Thank you!
Re: Automate Backup/Restore [message #291116 is a reply to message #291099] Thu, 03 January 2008 01:18 Go to previous messageGo to next message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read and follow OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format. Use the "Preview Message" button.
Always post your Oracle version (4 decimals).

There are many scripts here in different topics, just search them.

Regards
Michel
Re: Automate Backup/Restore [message #291117 is a reply to message #291083] Thu, 03 January 2008 01:20 Go to previous message
panchpan
Messages: 34
Registered: October 2007
Member
THANK You.
Previous Topic: RMAN, how to schedule a backup of the huge table?
Next Topic: RMAN error
Goto Forum:
  


Current Time: Wed May 15 17:31:36 CDT 2024