Showing posts with label RMAN. Show all posts
Showing posts with label RMAN. Show all posts

Wednesday, 30 November 2011

RMAN backup types and Usage

Here I'm descrbing RMAN backups Types,Commands and Usage in Brief in Oracle 11g Database.Hope it will help one and all.


RMAN BACKUPS:
----------------


1)RMAN HOT BACKUP =>database up & running
2)RMAN COLD BACKUP =>database is not up(shutdown =>mount(now take backup).


1)RMAN HOT BACKUP: OPEN STATE (ARCHIVE_LOG MODE)
2)RMAN COLD BACKUP:MOUNT STATE (NO ARCHIVE LOG MODE)


INCREMENTAL BACKUP:
1)DIFFERENTIAL BACKUP =>BY DEFAULT INCREMENTAL BACKUP IS DIFFERENTIAL.
=>BACKUP FROM SAME OR LOWER LEVEL.
=>LEVEL 0,LEVEL 1,LEVEL 2.....
2)CUMMULATIVE BACKUP =>BACKUP FROM LEVEL 0(LOWEST LEVEL)
=>LEVEL 0,LEVEL 1,LEVEL 2.....

WHERE:
LEVEL 0=FULL BACKUP
LEVEL 1=CHANGE DATA FROM LEVEL 0
LEVEL 2=CHANGE DATA FROM LEVEL 1...


BACKUP STRATERGY:
--------------------

SUNDAY =LEVEL 0 =>INCREMENTAL (DIFFERENTIAL)=>BACKUP LEVEL 0(LOWEST LEVEL)
MONDAY =LEVEL 1 =>INCREMENTAL
TUESDAY=LEVEL 2 =>INCREMENTAL
WED =LEVEL 0 =>INCREMENTAL (CUMMULATIVE) =>BACKUP LEVEL 0(LOWEST LEVEL)
THUR =LEVEL 1 =>INCREMENTAL
FRI =LEVEL 2 =>INCREMENTAL
SAT= =LEVEL 1 =>CUMMULATIVE =>BACKUP LEVEL 1(CHANGE DATA FROM LEVEL 0)


TIMESTAMP SYMBOLS:
-------------------


%U=UNIQUE BACKUPSET NAME
%T= TIMESTAMP OF TIME OF BACKUPSET

RMAN COMMANDS:
----------------


INCREMENTAL BACKUP:
---------------------


1)DIFFERENTIAL BACKUP
2)CUMULATIVE BACKUP


1)DIFFERENTIAL BACKUP:
-- INCREMENTAL LEVEL 0
run{
Allocate channel ch1 type disk format 'D:\RMAN_BACKUP\ORCL_data_BACKUP2_%T_%U';
Backup incremental level=0 database tag='complete_backup';
Release channel ch1;
allocate channel c1 type disk;
copy current controlfile to 'D:\RMAN_BACKUP\ORCL_ctrl_BACKUP2_%U_%T';
Release channel c1;
}

-- INCREMENTAL LEVEL 1
run{
Allocate channel ch1 type disk format 'D:\RMAN_BACKUP\ORCL_data_BACKUP2_%T_%U';
Backup incremental level=1 database tag='complete_backup';
Release channel ch1;
allocate channel c1 type disk;
copy current controlfile to 'D:\RMAN_BACKUP\ORCL_ctrl_BACKUP2_%U_%T';
Release channel c1;
}

-- INCREMENTAL LEVEL 2
run{
Allocate channel ch1 type disk format 'D:\RMAN_BACKUP\ORCL_data_BACKUP2_%T_%U';
Backup incremental level=2 database tag='complete_backup';
Release channel ch1;
allocate channel c1 type disk;
copy current controlfile to 'D:\RMAN_BACKUP\ORCL_ctrl_BACKUP2_%U_%T';
Release channel c1;
}

2)CUMULATIVE BACKUP:
----------------------


-- CUMMULATIVE BACKUP
RMAN> run{
2> Allocate channel ch1 type disk format 'D:\RMAN_BACKUP\ORCL_data_BACKUP2_%T_%U';
3> Backup incremental level=0 CUMULATIVE database tag='complete_backup';
4> Release channel ch1;
5> allocate channel c1 type disk;
6> copy current controlfile to 'D:\RMAN_BACKUP\ORCL_ctrl_BACKUP2_%U_%T';
7> Release channel c1;
8> }

released channel: ORA_DISK_1
allocated channel: ch1
channel ch1: SID=73 device type=DISK

Starting backup at 24-JUL-11
channel ch1: starting incremental level 0 datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00004 name=D:\APP\RAFIALVI\ORADATA\ORCL\USERS01.DBF
channel ch1: starting piece 1 at 24-JUL-11
channel ch1: finished piece 1 at 24-JUL-11
piece handle=D:\RMAN_BACKUP\ORCL_DATA_BACKUP2_20110724_1HMI7EPO_1_1 tag=COMPLETE_BACKUP comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
channel ch1: starting incremental level 0 datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00001 name=D:\APP\RAFIALVI\ORADATA\ORCL\SYSTEM01.DBF
input datafile file number=00002 name=D:\APP\RAFIALVI\ORADATA\ORCL\SYSAUX01.DBF
input datafile file number=00003 name=D:\APP\RAFIALVI\ORADATA\ORCL\UNDOTBS01.DBF
input datafile file number=00005 name=D:\APP\RAFIALVI\ORADATA\ORCL\EXAMPLE01.DBF
channel ch1: starting piece 1 at 24-JUL-11
channel ch1: finished piece 1 at 24-JUL-11
piece handle=D:\RMAN_BACKUP\ORCL_DATA_BACKUP2_20110724_1IMI7EPP_1_1 tag=COMPLETE_BACKUP comment=NONE
channel ch1: backup set complete, elapsed time: 00:01:15
channel ch1: starting incremental level 0 datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ch1: starting piece 1 at 24-JUL-11
channel ch1: finished piece 1 at 24-JUL-11
piece handle=D:\RMAN_BACKUP\ORCL_DATA_BACKUP2_20110724_1JMI7ES5_1_1 tag=COMPLETE_BACKUP comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-JUL-11

released channel: ch1

-- CUMULATIVE BACKUP LEVEL LOWEST(0)
run{
Allocate channel ch1 type disk format 'D:\RMAN_BACKUP\ORCL_data_BACKUP2_%T_%U';
BACKUP INCREMENTAL LEVEL=0 CUMULATIVE DATABASE FILESPERSET 4 tag='cumulative';
tag='complete_cummulative_backup';
Release channel ch1;
allocate channel c1 type disk;
copy current controlfile to 'D:\RMAN_BACKUP\ORCL_ctrl_BACKUP2_%U_%T';
Release channel c1;
}


-- CUMULATIVE BACKUP LEVEL LOWEST(1)
run{
Allocate channel ch1 type disk format 'D:\RMAN_BACKUP\ORCL_data_BACKUP2_%T_%U';
BACKUP INCREMENTAL LEVEL=1 CUMULATIVE DATABASE tag='cumulative_LEVEL1';
Release channel ch1;
allocate channel c1 type disk;
copy current controlfile to 'D:\RMAN_BACKUP\ORCL_ctrl_BACKUP2_%U_%T';
Release channel c1;
}

RMAN> run{
2> Allocate channel ch1 type disk format 'D:\RMAN_BACKUP\ORCL_data_BACKUP2_%T_%U';
3> BACKUP INCREMENTAL LEVEL=1 CUMULATIVE DATABASE tag='cumulative_LEVEL1';
4> Release channel ch1;
5> allocate channel c1 type disk;
6> copy current controlfile to 'D:\RMAN_BACKUP\ORCL_ctrl_BACKUP2_%U_%T';
7> Release channel c1;
8> }

released channel: ORA_DISK_1
allocated channel: ch1
channel ch1: SID=73 device type=DISK

Starting backup at 24-JUL-11
channel ch1: starting incremental level 1 datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00004 name=D:\APP\RAFIALVI\ORADATA\ORCL\USERS01.DBF
channel ch1: starting piece 1 at 24-JUL-11
channel ch1: finished piece 1 at 24-JUL-11
piece handle=D:\RMAN_BACKUP\ORCL_DATA_BACKUP2_20110724_1NMI7F9M_1_1 tag=CUMULATIVE_LEVEL1 comment=NONE
channel ch1: backup set complete, elapsed time: 00:01:25
channel ch1: starting incremental level 1 datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00001 name=D:\APP\RAFIALVI\ORADATA\ORCL\SYSTEM01.DBF
input datafile file number=00002 name=D:\APP\RAFIALVI\ORADATA\ORCL\SYSAUX01.DBF
input datafile file number=00003 name=D:\APP\RAFIALVI\ORADATA\ORCL\UNDOTBS01.DBF
input datafile file number=00005 name=D:\APP\RAFIALVI\ORADATA\ORCL\EXAMPLE01.DBF
channel ch1: starting piece 1 at 24-JUL-11
channel ch1: finished piece 1 at 24-JUL-11
piece handle=D:\RMAN_BACKUP\ORCL_DATA_BACKUP2_20110724_1OMI7FCC_1_1 tag=CUMULATIVE_LEVEL1 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:35
channel ch1: starting incremental level 1 datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ch1: starting piece 1 at 24-JUL-11
channel ch1: finished piece 1 at 24-JUL-11
piece handle=D:\RMAN_BACKUP\ORCL_DATA_BACKUP2_20110724_1PMI7FDF_1_1 tag=CUMULATIVE_LEVEL1 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-JUL-11

released channel: ch1

allocated channel: c1
channel c1: SID=73 device type=DISK

Starting backup at 24-JUL-11
channel c1: starting datafile copy
copying current control file
output file name=D:\RMAN_BACKUP\ORCL_CTRL_BACKUP2_CF_D-ORCL_ID-1280115002_1QMI7FDK_20110724 tag=TAG20110724T055044 R
D=31 STAMP=757317045
channel c1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 24-JUL-11

released channel: c1


ARCHIVE LOG DELETION POLICY FOR A DATABASE:
----------------------------------------------


run {
allocate channel for maintenance device type disk;
delete archivelog until time 'sysdate -5';
}

I do backups from the primary database to a local drive and have been puzzled
how to delete the standby archive logs after they ship.
The ‘obvious’ solution is the documented feature in RMAN:

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;


COMPRESSION LEVEL ORACLE 11g:
----------------------------------


basic =DEFAULT
none =Not recomended
medium = license
high =license


Drawbacks:
------------


medium =>consume hight system resource
high =>consume high system resource

II)RMAN COLD BACKUP:
----------------------


=>NOARCHIVE LOG MODE
=>MOUNT STATE
=> DEVELOPMENT => MUCH DISK SPACE IS NOT THERE
=>DOWNTIME TOLERABLE..


run_orcl.txt:
-----------------------------------------------------


*SNAPSHOT CONTROLFILE:RMAN USES FOR BACKUP OF CONTROL FILE.

Configure setting in RMAN :
----------------------------
We can use configure command to change any setting in RMAN.I would definetly like to outside my script like below.

$rman target / catalog rman/rman@catdb
RMAN>CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'D:\RMAN_BACKUP\snapcf_orcl.f';

rman_cold.txt:
--------------


run{
shutdown immediate;
startup mount;
allocate channel ch1 device type disk format 'D:\RMAN_BACKUP\orcl_BK_SET1_%U_%T' maxpiecesize 5G;
allocate channel ch2 device type disk format 'D:\RMAN_BACKUP\orcl_BK_SET2_%U_%T';
backup database TAG='ORCL_BACKUP_WEEKLY';
allocate channel c1 type disk;
copy current controlfile to 'D:\RMAN_BACKUP\TESTDB_ctrl_%U_%T';
Release channel c1;
configure retention policy to recovery window of 7 days;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'D:\RMAN_BACKUP\snapcf_orcl.f';
CROSSCHECK BACKUP;
release channel ch1;
release channel ch2;
alter database open;
}


rman_orcl.bat:
---------------


-- orcl DB RMAN COLD BACKUP
set ORACLE_SID=orcl
set ORACLE_HOME=D:\app\RafiAlvi\product\11.2.0\dbhome_1
set ORACLE_BASE=D:\app\RafiAlvi\
rman target sys/orcldba @D:\RMAN_BACKUP_SCRIPTS\run_ORCL.txt log=D:\RMAN_BACKUP_SCRIPTS\LOGS\rman_cold_orcl_24july_cum.log

Note: In Unix environment use export for setting the enviromnmet and Write shell script 'rman_orcl.sh',rest all script is almost same and can fit as per our path in Unix environment.

RMAN BACKUP DETAILS Views:
---------------------------------


We can use Dictionary Views for checking the status of rman backups.

1)USE AFTER SCHEDULING RMAN BACKUP:
SELECT START_TIME||' '||END_TIME||' '||STATUS FROM V$RMAN_BACKUP_JOB_DETAILS;

2)USE TO CHECK BYYES PROCESSED IN RMAN BACKUP:
SELECT SID||' '||STATUS||' '||MBYTES_PROCESSED||' '||START_TIME||' '||END_TIME
FROM V$RMAN_STATUS;

3)USE TO CHECK SESSION AND RMAN BACKUP OUTPUT:
SELECT SID||' '||RECID||' '||OUTPUT||' '||SESSION_STAMP
FROM V$RMAN_OUTPUT;

Note:On Unix terminal,It will be very much useful to check the process in order to check the status by using 'ps' command.
$ps -eaf|grep rman

Hope it helps...

Enjoy Oracle learning.

Best regards,

Nag

RMAN COMMANDS

We use RMAN COMMANDS for doing lot of tasks like backup,cloning,conversion of filesystems from NON-ASM to ASM and vice-versa.The commands of RMAN are many so I decided to make a note of few crucial ones,hope it can be useful.

There are two types of RMAN commands:
1)Stand-alone:Executed at the RMAN prompt and are generally self-contained. CHANGE, CONNECT,CREATE CATALOG, RESYNC CATALOG. CREATE SCRIPT, DELETE SCRIPT, REPLACE SCRIPT etc.
2)JOB:These are usually grouped and RMAN executes this commands inside of RUN command block sequentially. If any command fails, RMAN ceases processing, no further commands within the block are executed.

•THE CONFIGURE COMMAND :
 CONFIGURE AUTOMATIC CHANNEL :
RMAN > CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT ‘/db01/backup/%U’;

 IMPLEMENT RETENTION POLICY BY SPECIFYING RECOVERY WINDOW :
RMAN >CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 days ;
- Recovery window: a period of time that begins with the current time and extends backward in time to the point of recoverability. In above example, the command ensures that for each data file, one back up that is older than the point of recoverability (7 days) must be retained.

 IMPLEMENT RETENTION POLICY BY SPECIFYING REDUNDANCY:
RMAN >CONFIGURE REDUNDANCY POLICY TO REDUNDANCY 2;
- Redundancy value indicates that any number of backups or copies beyond a specified number need not be retained. The default is 1 day.

 CONFIGURE DUPLEXED BACKUP SETS:
RMAN >CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE disk TO 2;

- We can create up to 4 copies (in above example 2) of each back up piece in a backup set for all backup commands that use automatic channels. This applies only for datafiles and archived redo log files.

 CONFIGURE BACKUP OPTIMIZATION:
RMAN >CONFIGURE BACKUP OPTIMIZATION ON;
- With this setting on, the BACKUP command does not backup files to a device type if the identical file has already been backed up to the device type. For two files to be identical, there contents must be exactly the same. Default value is off.

 USE THE CLEAR OPTION TO RETURN TO THE DEFAULT VALUE:
RMAN >CONFIGURE RETENTION POLICY CLEAR;
RMAN >CONFIGURE CHANNEL DEVICE TYPE sbt CLEAR;

•THE SHOW COMMAND :
- This command displays persistent configuration settings.
 AUTOMATIC CHANNEL CONFIGURATION SETTINGS:
RMAN>SHOW CHANNEL;
RMAN>SHOW DEVICE TYPE;
RMAN>SHOW DEFAULT DEVICE TYPE;

 RMAN RETENTION POLICY CONFIGURATION SETTINGS:
RMAN>SHOW RETENTION POLICY;

 NUMBER OF BACKUP COPIES:
SHOW DATAFILE BACKUP COPIES;

 MAXIMUM SIZE OF BACKUP SETS:
SHOW MAXSETSIZE;

 TABLESPACES EXCLUDED FROM WHOLE DATABASE BACKUP:
SHOW EXCLUDE;

 STATUS OF BACKUP OPTIMIZATON:
SHOW BACKUP OPTIMIZATION;

•LIST COMMAND:
- LIST command is used to produce a detailed report listing all information for the following.

 LIST BACKUPS OF ALL FILES IN THE DATABASE:
RMAN >LIST BACKUP OF DATABASE;

 LIST ALL BACKUP SETS CONTAINING THE uses1.dbf DATAFILE:
RMAN >LIST BACKUP OF DATAFILE ”/db1/oradata/u03/users1.dbf”;

 LIST ALL COPIES OF DATAFILES IN THE SYSTEM TABLESPACE:
RMAN >LIST COPY OF TABLESPACE “SYSTEM”;

•THE REPORT COMMAND:
- This command helps to analyze information in the RMAN repository in more detail.

 WHAT IS THE STRUCTURE OF THE DATABASE?
RMAN >REPORT SCHEMA;

 WHICH FILES NEED TO BE BACKED UP?
RMAN >REPORT NEED BACKUP …;

WHICH BACKUPS CAN BE DELETED?
RMAN >REPORT OBSOLETE;

 WHICH FILES ARE NOT RECOVERABLE B’COS OF UNRECOVERABLE OPERATIONS:
RMAN >REPORT UNRECOVERABLE …;

•THE REPORT NEED BACKUP COMMAND :
- This command is used to identify all data files that need a backup. There are three options with this command.

 INCREMENTAL: An integer specifies the maximum number of incremental backups that should be restored during recovery. If this number or more is required then the data file needs a new full backup.

RMAN >REPORT NEED BACKUP incremental 3 database;
This example will report files needing three or more incremental backups for recovery.

 DAYS: An integer specifies max. number of days since the last full or incremental backup of file. The file needs a backup if the most recent backup is equal to or greater than this number.
RMAN >REPORT NEED BACKUP days 3 tablespace system;
To report what system files have not been backed up for three days, use above command.

 REDUNDANCY: An integer specifies the min. level of redundancy considered necessary. For example, redundancy level two requires a backup if there are not two or more backups.
RMAN >REPORT NEED BACKUP redundancy 3;

•RECOVERY MANAGER PACKAGES:
- Two packages named DBMS_RCVCAT AND DBMS_RCVMAN are used by RMAN to perform its tasks.
-DBMS_RCVMAN is created in target database. It queries the control file or recovery catalog.
-DBMS_RCVCAT is used by recovery manager to maintain the information in the recovery catalog.
-DBMS_BACKUP_RESTORE package is created by dbmsbkrs.sql and prvtbkrs.plb script called by catproc.sql. it is used to interface with oracle and os to create,restore and recover bkups of datafiles and archived redo log files.

Hope it helps...I will increase this thread continously as Oracle 11g has lot of new commands.

Happy Oracle learning...