mercoledì 7 novembre 2012

Oracle Database: Schedule hot backups using RMAN

In this article I will schedule periodic hot backups of a running database instance using rman.

To perform hot backups using rman, first you need to check if your database is in ArchiveLog mode.

[oracle@db1 ~]$ sqlplus "/ as sysdba"

SQL> SELECT log_mode FROM v$database;

LOG_MODE
------------
NOARCHIVELOG


If not change it:

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP MOUNT;

SQL> ALTER DATABASE ARCHIVELOG;

SQL> ALTER DATABASE OPEN;

SQL> SELECT log_mode FROM v$database;

LOG_MODE
------------
ARCHIVELOG


Once it's in ArchiveLog mode create the main rman script which will be called by crontab:

[oracle@db1 ~]$ vi /u01/rman_main

ORACLE_HOSTNAME=db1
export ORACLE_HOSTNAME
ORACLE_UNQNAME=orcl
export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle
export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_HOME
ORACLE_SID=orcl
export ORACLE_SID

/u01/app/oracle/product/11.2.0/db_1/bin/rman target=/ @/u01/rman_script


Where ORACLE_HOSTNAME is your machine hostname and ORACLE_UNQNAME and ORACLE_SID is the SID of the instance you need to backup.

[oracle@db1 ~]$ chmod a+x /u01/rman_main
Then we create the rman script itself:

[oracle@db1 ~]$ vi /u01/rman_script

run {
  allocate channel ch1 type disk format '/u01/backup%d_DB_%u_%s_%p';
  backup database;
  backup archivelog all;
  release channel ch1;
}



This will backup the database creating a file under "/u01/" directory.
In the above script %d, %u, %s, %p are substitution variables for generating unique file name, if you wish to know more about these variables have a look HERE.

You could manually run rman_main to take hot backups, but if you like to run scheduled backups we need to add this to crontab:

[root@db1 ~]# crontab -e -u oracle

I will schedule backup everyday at 18:10 (6.10 PM)

10 18 * * * /u01/rman_main


The first five fields are:

minute (0-59)
hour (0-23)
day of the month(1-31)
month of the year (1-12)
day of the week (0-6 with 0 = Sunday)

For more info on crontab have a look at crontab.org

NOTE: At first I was unable to edit this file, so after a brief search I had to set EDITOR variable according to my preferred file editor.

In my case:

[root@db1 ~]# export EDITOR=nano

[root@db1 ~]# crontab -e -u oracle


That's all!!

martedì 6 novembre 2012

Oracle Database: Start EM console for multiple instances on the same server

Today I had to manually start Enterprise Manager console for an instance running on a server which has already other instances running.

The command to start EM Console is:

emctl start dbconsole

full path of the command is:

/u01/app/oracle/product/11.2.0/db_1/bin/emctl start dbconsole


This start EM for instance referred in ORACLE_SID variable.

In case of multiple instances running on same server you can start EM console by assigning ORACLE_SID variable according to the EM you need to start.

For example if we need to start EM console for "TEST1" instance we set ORACLE_SID:

[oracle@orcl ~]# ORACLE_SID=TEST1

[oracle@orcl ~]# emctl start dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.3.0
Copyright (c) 1996, 2011 Oracle Corporation.  All rights reserved.
https://orcl:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control ........................ started.
---------------------------------Logs are generated in directory /u01/app/oracle/product/11.2.0/db_1/orcl_TEST1/sysman/log


Same thing if we need to start EM for "TEST2" instance:


[oracle@orcl ~]# ORACLE_SID=TEST2

[oracle@orcl ~]# emctl start dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.3.0
Copyright (c) 1996, 2011 Oracle Corporation.  All rights reserved.
https://orcl:5500/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control ........................ started.
---------------------------------Logs are generated in directory /u01/app/oracle/product/11.2.0/db_1/orcl_TEST2/sysman/log



Thats'all!!