11g, Cold backup using RMAN and detached job

May 30th, 2011 | Posted in 11gR2, Blog, RMAN | 4 Comments


Introduction:
This example for Linux creates a job that performs a cold backup of the database using RMAN (Recovery Manager).
The example contains 4 scripts:

[oracle@wissem scripts]$ ls -rtl
total 16
-rwxr--r-- 1 oracle oinstall 143 May 30 19:14 main.sh
-rwxr--r-- 1 oracle oinstall 522 May 30 20:35 coldbackup.rman
-rw-r--r-- 1 oracle oinstall 642 May 30 20:40 main.sql
-rwxr--r-- 1 oracle oinstall 165 May 30 20:42 coldbackup.sh


Detached job:
You can use a detached job to run an application separately from the database. Detached job is independent of the status of the instance; The instance can be down and the detached job will run in another and independent process to the scheduler.

The example:

1- coldbackup.rman script:
it’s a script that simply invokes RMAN, shutdown the database, bring the instance to the mount state, open the wallet and perform a whole database backup plus archivelog.

You may have noticed the use of the Oracle wallet, it’s because I configured the persistent setting to use the encrypted backup. If you don’t open the wallet in this case, you will receive an error ORA-28365: wallet is not open. Remember if you want to create a password wallet you can run the following command via RMAN;

RMAN> sql 'alter system set encryption key authenticated by "wissem"';
sql statement: alter system set encryption key authenticated by "wissem"
RMAN>

You may have also noticed the use of “change archivelog all crosscheck;” command, this is to perform a cross check of the archivelog files. Missed, moved archivelog files will raise the ” RMAN-06059: expected archived log not found ” error, if you don’t cross check them.

The content of the script:

[oracle@wissem scripts]$ chmod u+x coldbackup.rman
[oracle@wissem scripts]$ cat coldbackup.rman
run {
# Shut down database for backups and put into MOUNT mode
shutdown immediate;
startup mount;
# Validate archivelog files
change archivelog all crosscheck;
#Open Wallet
sql 'alter system set encryption wallet open identified by "wissem"';
# Perform full database backup
backup database plus archivelog;
# Open database after backup
alter database open;
# Call notification routine to indicate job completed successfully
sql " BEGIN  DBMS_SCHEDULER.END_DETACHED_JOB_RUN(''sys.cold_backup_job'', 0,
  null); END; ";
}

[oracle@wissem scripts]$

2- coldbackup.sh script:
This script simply invokes RMAN, call the coldbackup.rman script and log the RMAN execution into a log file called “coldbackup.out”.

The content of the script:

[oracle@wissem scripts]$ chmod u+x coldbackup.sh
[oracle@wissem scripts]$ ls -rtl
total 4
-rwxr--r-- 1 oracle oinstall 173 May 30 18:40 coldbackup.sh
[oracle@wissem scripts]$
[oracle@wissem scripts]$ cat coldbackup.sh
#!/bin/sh
source /home/oracle/.bash_profile
$ORACLE_HOME/bin/rman TARGET / @$ORACLE_HOME/scripts/coldbackup.rman > /u01/app/oracle/backup/coldbackup.out
exit 0
[oracle@wissem scripts]$

The content of the .bash_profile file is:

[oracle@wissem ~]$ cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_BASE=/home/oracle/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export ORACLE_HOME
ORACLE_SID=ORAWISS; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

if [ $USER = "oracle" ]; then
  if [ $SHELL = "/bin/ksh" ]; then
    ulimit -p 16384
    ulimit -n 65536
  else
    ulimit -u 16384 -n 65536
  fi
fi
[oracle@wissem ~]$

3- main.sql script:
This script creates a program called “sys.cold_backup”, the type of the program is an external executable script located in /home/oracle/app/oracle/product/11.2.0/db_1/scripts/coldbackup.sh path. Inside the script we set the value “detached” as the ATTRIBUTE of the program previously created. Then, we create a scheduler job associated with the external program. the scheduler will run every day at 20H and 45 minutes. The job is created by default disabled, so we should enable it using the ENABLE procedure of the DBMS_SCHEDULER package.

The content of the scirpt is:

[oracle@wissem scripts]$ cat main.sql
SET SERVEROUTPUT ON
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM(
    program_name   => 'sys.cold_backup',
    program_type   => 'executable',
    program_action => '/home/oracle/app/oracle/product/11.2.0/db_1/scripts/coldbackup.sh',
    enabled        =>  TRUE);

  DBMS_SCHEDULER.SET_ATTRIBUTE('sys.cold_backup', 'detached', TRUE);

  DBMS_SCHEDULER.CREATE_JOB(
    job_name        => 'sys.cold_backup_job',
    program_name    => 'sys.cold_backup',
    repeat_interval => 'FREQ=DAILY;BYHOUR=20;BYMINUTE=45');

DBMS_SCHEDULER.ENABLE('sys.cold_backup_job');

EXCEPTION WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('Error main.sql '||SQLERRM);
END;
/
exit;
[oracle@wissem scripts]$ 

3- main.sh script:

This is the main script that will call main.sql.

The content of the scirpt is:

[oracle@wissem scripts]$ cat main.sh
#!/bin/sh

source /home/oracle/.bash_profile

sqlplus sys/wissem as sysdba @/home/oracle/app/oracle/product/11.2.0/db_1/scripts/main.sql
exit;
[oracle@wissem scripts]$

Run the example:

We first run main.sh script. We will have the following output;


SQL> exec DBMS_SCHEDULER.STOP_JOB('SYS.COLD_BACKUP_JOB');

PL/SQL procedure successfully completed.

SQL> exec DBMS_SCHEDULER.DROP_JOB('sys.cold_backup_job');

PL/SQL procedure successfully completed.

SQL> exec dbms_scheduler.drop_program('SYS.COLD_BACKUP');

PL/SQL procedure successfully completed.

SQL>   exit
[oracle@wissem scripts]$ ./main.sh 

SQL*Plus: Release 11.2.0.1.0 Production on Mon May 30 20:40:16 2011
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
PL/SQL procedure successfully completed.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@wissem scripts]$

You can run the following query to see if the scheduler job was successfully created or not;

select * from dba_scheduler_jobs where JOB_NAME='COLD_BACKUP_JOB';

At 20H45, the detached job is running,
I queried the status of the database and it is in mount state;

SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
SQL>

Also, using the command;

[wissem@wissem ~]$ ps -edf | grep rman
oracle   13195 11942  0 20:45 pts/0    00:00:01 rman target /
wissem   13264 13249  0 20:45 pts/1    00:00:00 grep --color=auto rman

Another method to see what is happening is to view the last few lines of the alert log file, using adrci utility like showing below;
(Contents from alert log file have been truncated to show only the necessary events)

[oracle@wissem backup]$ adrci

ADRCI: Release 11.2.0.1.0 - Production on Mon May 30 20:06:20 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

ADR base = "/home/oracle/app/oracle"
adrci> show alert

Choose the alert log from the following homes to view:

1: diag/rdbms/orawiss/ORAWISS
2: diag/tnslsnr/meka/listener
3: diag/tnslsnr/wissem/istener_orawiss
4: diag/tnslsnr/wissem/listener
5: diag/tnslsnr/wissem/listener_orawiss
Q: to quit

Please select option: 1

...............

Successful mount of redo thread 1, with mount id 3190464559
Database mounted in Exclusive Mode
Lost write protection disabled
Completed: alter database mount
2011-05-30 20:45:43.989000 +02:00
alter system set encryption wallet open identified by *
Completed Successfully
   alter system set encryption wallet open identified by *
2011-05-30 20:47:08.279000 +02:00
alter database open
...............

Finally, you can list the content of the flash recovery area and you will find the backup files;

[oracle@wissem scripts]$ ls /home/oracle/backups/fra/ORAWISS/backupset/2011_05_30/
o1_mf_annnn_TAG20110530T204544_6y7sgrox_.bkp  o1_mf_nnndf_TAG20110530T204548_6y7sgwxm_.bkp
o1_mf_annnn_TAG20110530T204544_6y7sgrt6_.bkp  o1_mf_nnndf_TAG20110530T204548_6y7sgxgm_.bkp
[oracle@wissem scripts]$

Hope it helps,

Wissem

Scridb filter


4 Comments to “11g, Cold backup using RMAN and detached job”

  1. Sravan says:

    It’s Superb………

    Thanks a lot.

  2. admin says:

    you are welcome :)

  3. rmanbackup says:

    Thanks for sharing , Great information

  4. nate says:

    thanks for sharing, I needed an alternative scheduler for a small windows db and found this info useful.


Leave a Comment





Subscribe


Polls

which oracle topic interests you most?

View Results

Loading ... Loading ...


Oracle Class Tweets


Recent Posts


Recent Comments

  • Ravi: Hi, As above, I want to add a new column in to my production database (11g) that has millions of records but...
  • DACCorp: Thanks bro, it worked! XD
  • accutane: Hello there, just became alert to your blog through Google, and found that it is truly informative. I am...
  • Ayman Mohamed: Thanks for your nice article, it is very helpful
  • Moon: Thanks man you solved my problem. i was facing this error: ORA-19625: error identifying file while rman...
  • James: “To solve the issue, After fixing the /etc/hosts file, origin of this issue. I have deleted HAS, using...
  • Darrell Hanning: Awesome information, and very well presented! Stopped thinking I had screwed up in my migration, and...
  • Osama mustafa: Thanks for sharing, you need to confrim with Oracle Support about modify Hidden Parameter as you know...
  • Jaspreet: Brilliant explanation.
  • Yousuf: Very Nice… Just wanted to check you have done all patching at Node 1 only.. is there any thing need to...
  • Yousuf: Very Nice.. Thanks for sharing.. Once question.. You have executed all commands on Node 1 only.. Is there any...
  • Emir: Thanks… Great article
  • borse firmate: Thank you for another informative blog. The place else may just I am getting that kind of information...
  • leandro: why this parameter is systemwide? could you read from a asm instance from one failure group and from the...
  • Mohammad: paul, we create pfile from target database to source database and later we change database name, and...
  • Muhammad Ikram: Thanks Brother for sharing pearls of knowledge. May ALLAH reward you for this both here and...
  • rgrover: Thanks for the POST. I recently encounter similar issue. Your POST helped.
  • gopalredy: really its very use full to dbas
  • Vivian: This is awesome! Thank you so much!
  • henry zhong: CDB=DB, and PDB=SCHEMA but in a sub dictionary?