Showing posts with label delete obsolete. Show all posts
Showing posts with label delete obsolete. Show all posts

Tuesday, May 26, 2009

New features in RMAN since Oracle9i

Oracle9i RMAN new features: Oracle9i introduced several new enhancements. Let us discuss some of the new enhancements in oracle9i.

1. Persistent Configuration:
Introduced new CONFIGURE command enable us to configure various backup, restore and recover parameters that are persistent across RMAN sessions.

CONFIGURE RETENTION POLICY TO REDUNDANCY 3;
CONFGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'D:\BK\bk%d_%s_%p'
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE DEFAULT DEVICE TYPE CLEAR;
CONFIGURE EXCLUDE FOR TABLESPACE users;
CONFIGURE EXCLUDE FOR TABLESPACE users CLEAR;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE BACKUP OPTIMIZATION ON;

2. Backup of Archivelogs:

We can use new PLUS ARCHIVELOG clause to specify that archive logs that have not been backed up are included with the data backup.

BACKUP DATAFILE 2 PLUS ARCHIVELOG;

3. Restartable Backups:

Oracle9i has added another new clause to the BACKUP statement, NOT BACKED UP [SINCE TIME….]. This clause specifies that oracle should only back up files that have not been backed up since a particular date and time.

BACKUP DATABASE NOT BACKED UP SINCE TIME ‘sysdate-7’;

We can use this clause to restart the backup process when it fails after completing a part of the backup. This clause only backs up the files that were missed by the first backup that failed. This clause enables you to reduce the time required for the backup. Otherwise, you would have to perform a full backup again. If we omit the SINCE TIME option, files that have never been backed up become candidates for backup.

Oracle9i also optimize the restoration of files from backup, files whose file header match the headers of the files in the backup sets are not restored. This keeps us from restoring files that have already been restored in the case of restore operation that fails midway.

4. Block Media Recovery – BMR:

Data blocks can be corrupted due to various reasons during normal database operations. Oracle writes information about the data block corruption into the alert log file and the user trace files. Prior to oracle9i, we had to restore and recover the entire data file by applying the redo required from the archived log files, even through just one single block was corrupted. It would be time consuming to restore and recover the entire data file just for one corrupted block.

Oracle9i introduced BMR to enable us to restore and recover just those blocks that are corrupted. We can find the corrupted block from V$BACKUP_CORRUPTION and V$COPY_CORRUPTION views. We also do not have to bring the data file offline to recover the corrupted blocks. The DB availability is greatly enhanced with BMR feature.

BLOCKRECOVER DATAFILE d1 BLOCK b1,[b2,b3,b4…]
[DATAFILE d2 BLOCK b5,[b7,b8….]]…

--recover corrupt blocks in three datafiles
RMAN> BLOCKRECOVER DATAFILE 2 BLOCK 12, 13 DATAFILE 3 BLOCK 5, 98, 99 DATAFILE 4 BLOCK 19;

5. Trail Recovery:

Trail recovery tests the backup and identifies any problem in the backup before we really use this backup for any recovery. The difference between regular recovery and trail recovery is that, in trial recovery, the data is not written to the data files and changes are only recorded in the buffers. Trail recovery writes any errors encountered into the alert log file.

Once the trail recovery is completed, all the effects of trail recovery are nullified, and it writes all the errors in alert log. The database should be mounted stage while doing regular recovery as well as trail recovery. So users can not use the database during both trail and regular recovery.

Oracle9i introduced new feature to allow number of block corruptions during the recovery. If the corrupt blocks are few, you can perform a recovery that ignores the corrupt block but recovers the rest.

RECOVER DATABASE ALLOW 2 CORRUPTION;

Miscellaneous Enhancements:

1. Oracle9i has ability to report obsolete backups that are not required to keep the database unrecoverable with in a particular window of time. Here is the example.

REPORT OBSOLETE RECOVERY WINDOW OF 7 DAYS

We can also use DELETE OBSOLETE command to delete those obsolete backups. Also we can display files that must be backed up for number of days recovery window.

REPORT NEED BACKUP RECOVERY WINDOW OF 7 DAYS

2. We can use CROSSCHECK command to check if backup sets or file copies exists.

3. List command has been enhanced. Now we can specify either BY BACKUP or BY FILE.
LIST BACKUP;
LIST BACKUP BY FILE;

4. Introduced SHOW command to display all persistent parameters.
SHOW ALL


Oracle10g RMAN new features: Oracle10g introduced several new enhancements. Let us discuss some of the new enhancements in oracle10g.

1. Incrementally updated backups:

RMAN incremental backup method back up only datafile blocks that have changed since a specified previous backup. You can make incremental backups of databases, individual tablespaces or datafiles. The goal of an incremental backup is to back up only those data blocks that have changed since a previous backup.

Each data block in a datafile contains a system change number (SCN), which is the SCN at which the most recent change was made to the block. During an incremental backup, RMAN reads the SCN of each data block in the input file and compares it to the checkpoint SCN of the parent incremental backup. If the SCN in the input data block is greater than the checkpoint SCN of the parent, then RMAN copies the block.

Incremental backups can be either level 0 or level 1. A level 0 incremental backup, which is the base for subsequent incremental backups, copies all blocks containing data, backing the datafile up into a backup set just as a full backup would. The only difference between a level 0 incremental backup and a full backup is that a full backup is never included in an incremental strategy.

RMAN> backup incremental level 0 tablespace system;
RMAN> backup incremental level 1 database;

A level 1 incremental backup can be either of the following types:

1. A differential backup, which backs up all blocks changed after the most recent incremental backup at level 1 or 0

2. A cumulative backup, which backs up all blocks changed after the most recent incremental backup at level 0

2. Fast Incremental backup

During the incremental backup, oracle scans the whole data file and compare the SCN between the blocks in the data file and backup set files. It will be a time consuming tasks. Oracle introduced change tracking file to track the physical location of all database changes. During an incremental backup, RMAN uses the change tracking file to quickly identify only the blocks that have changed, avoiding the time consuming task of reading the entire data file to determine which blocks have changed. This is called Fast incremental backup. The new background process CTWR(Change tracking writer) is also required when using fast incremental backups.

SQL> alter database enable block change tracking using file
2 'C:/changetracking/chg01.dbf';

Database altered.
SQL>

The dynamic performance view V$BLOCK_CHANGE_TRACKING shows where block change tacking file is stored, whether it is enabled, and how large it is.

Please click the below link to read more about incremental backup in oracle10g. Click here

3. Dropping database through RMAN

We can drop the database through RMAN, it has additional benefits of dropping all backup copies and archived log files for the database if you include the INCLUDING BACKUPS clause.

RMAN> drop database including backups;

4. Automatic Channel Failover

If we are using multiple channels during an RMAN backup to either tape or disk and one of the channels fails, the backup job continues on the remaining channels. Any errors including channel errors are reported in the dynamic performance view V$RMAN_OUTPUT after the backup job is completed.

5. Duration, Throttling and Partial Backup Options

BACKUP......DURATION is a maximum duration or time frame for a backup operation, we can minimize the impact of the backup operation in a 24/7 environment. The new DURATION option, which replace RATE and READRATE in previous version of RMAN. For example, to spread out the backup of the USERS tablespace over a maximum of two hours, use the following command.

RMAN> BACKUP DURATION 2:00 TABLESPACE users;

By default, the backup will complete as fast as possible within the two-hour time frame.

BACKUP.....DURATION.....PARTIAL adding PARTIAL to the BACKUP command prevents an error message from being issued by RMAN in case the backup does not finish the operation in the specified amount of time. Any complete backup sets are available for recovery operations, and any partial or incomplete backup operations will have to be restarted.

RMAN> backup duration 2:00 partial
2> tablespace users
3> filesperset 1;

BACKUP.....DURATION.....MINIMIZE LOAD The MINIMIZE LOAD clause, used with disk backups only, automatically adjusts the throughput of the backup operation to complete the backup in the estimated completion time specified by DUATION.

RMAN> BACKUP DURATION 4:00 PARTIAL
2> MINIMIZE LOAD
3> DATABASE FILESPERSET 1;

BACKUP....DURATION....MINIMIZE TIME The MINIMIZE TIME clause, will complete the backup in the shortest possible time.

RMAN> backup duration 2:00 minimize time
2> tablespace users;

6. Creating Image copies

Oracle10g introduced new feature to create image copy of the data files. It is equivalent to conventional copy of oracle data files. Image copy is a bit-for-bit duplicate of a database file, identical to a copy made with an operating system command. When we take conventional backup, we need to put the tablespace in BEGIN BACKUP mode. But when we create image copy, it is not required. Another thing, when we take conventional backup, it will not be registered in RMAN catalog database. But RMAN image copy backup will be registered in catalog database.

What is the advantage of image copies? To answer this question, it would be useful for migrating the database to ASM. We can also use them to recover the database in non RMAN environment.

We have BACKUP AS COPY command in RMAN, which can copy entire database, multiple tablespaces, datafiles, archived log files.

RMAN> backup as copy database;
RMAN> backup as copy tablespace system, sysaux;
RMAN> backup as copy datafile 1;

RMAN automatically determines which datafiles belong to each tablespace and performs the image copy for each. In addition, the image copies generated by RMAN can be used directly in a recovery operation without using RMAN to extract a data file from previous backup set.

7. Full databaes backup

We may want to back up a previous backup to tape, rather than create a direct backup to tape, so as not to impact a database that is up and running. In RMAN, we can use the following command to backup a previous copy of the entire database to the default tape device.

RMAN> backup copy of database;

8. Compressed backup

This feature allows RMAN to perform binary compression of backupsets. The resulting backupsets do not need to be uncompressed during recovery. It is most useful in the following circumstances.

1. You are performing disk-based backup with limited disk space
2. You are performing backups across a network where network bandwidth is limiting
3. You are performing backups to tape, CD or DVD where hardware compression is not available

RMAN>BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;
RMAN>BACKUP AS COMPRESSED BACKUPSET DATAFILE 1,5;

Compression requires additional CPU cycles which may affect the performance of the database. For this reason it should not be used for tape backups where hardware compression is available.

I have discussed some of the other topics which are related to this thread. Please go through below links in case if you are interested....

How do we enable archivelog in oracle? Click here

How do we set up RMAN in oracle? Click here

What is difference between traditional backup and RMAN backup? Click here

Different type of recovery scenario in RMAN? Click here

Wednesday, May 20, 2009

Steps to Setup RMAN

This article is tested in oracle10gR2. How do we setup the RMAN in oracle? There are couple of ways, we can setup the RMAN. We can use control file to store backup catalog info or we can have seperate database to store catalog info. Here i am using seperate database to store backup catalog information.

You might ask a question yourself, why would we need RMAN backup? Why do we need to setup RMAN, since my traditional backups are already running fine.... I already discussed this in another thread.. Please see this link to answer your question. Click

I am using windows OS. Please remember, the directories and folder might change based on the operating system and environment. But the below steps are pretty much same for any environmnet.

Here i am using ORCL as primary database and CATDB as catalog database.

Step1 Enable the archive log in ORCL database. I already discussed this in another thread. Please refer this link to enable the database to archive log mode.

Step2 Create the tablespace and user in catalog database to hold backup information.

SQL> CONNECT sys/password@catdb AS SYSDBA
Connected.

SQL> CREATE TABLESPACE RMAN
2 DATAFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\CATDB\RMAN01.DBF' SIZE 6208K REUSE
3 AUTOEXTEND ON NEXT 64K MAXSIZE 32767M
4 EXTENT MANAGEMENT LOCAL
5 SEGMENT SPACE MANAGEMENT AUTO;

Tablespace created.

SQL> CREATE USER rman IDENTIFIED BY rman
2 TEMPORARY TABLESPACE temp
3 DEFAULT TABLESPACE rman
4 QUOTA UNLIMITED ON rman;

User created.

SQL> GRANT connect, resource, recovery_catalog_owner TO rman;

Grant succeeded.

SQL>

Step3 Create the recovery catalog in catalog database.

C:\>rman catalog=rman/rman@catdb

Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 09:59:26 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to recovery catalog database

RMAN> create catalog tablespace "RMAN";

recovery catalog created

RMAN> exit

Recovery Manager complete.

C:\>

Step4 Register the database with Catalog database. Each database should be registered to catalog database to run RMAN backup.

C:\>rman catalog=rman/rman@catdb target=sys/password@orcl

Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 10:02:01 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: ORCL (DBID=1215124933)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN> exit

Recovery Manager complete.

C:\>

Step5 Configure the persistent parameters.

C:\>rman catalog=rman/rman@catdb target=sys/password@orcl

Recovery Manager: Release 10.2.0.1.0 - Production on Tue May 19 18:46:40 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: ORCL (DBID=1215054467)
connected to recovery catalog database

RMAN> configure retention policy to recovery window of 2 days;

new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> configure default device type to disk;

new RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> configure controlfile autobackup on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> configure channel device type disk format 'C:\rmanbackup\Backup%d_DB_%U_%S
_%P';

new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'C:\rmanbackup\Backup%d_DB_%U_%S_%P'
;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN>

Step 6 Take database full backup. The full database backup should be taken first time. Afterwards, archivelog backup will be taken.

C:\>rman catalog=rman/rman@catdb target=sys/password@orcl

Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 10:16:09 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: ORCL (DBID=1215124933)
connected to recovery catalog database

RMAN> run{
2> backup database plus archivelog;
3> delete noprompt obsolete;
4> }

starting full resync of recovery catalog
full resync complete

Starting backup at 21-MAY-09
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=2 recid=1 stamp=687435222
input archive log thread=1 sequence=3 recid=2 stamp=687435237
input archive log thread=1 sequence=4 recid=3 stamp=687435270
input archive log thread=1 sequence=5 recid=4 stamp=687435279
input archive log thread=1 sequence=6 recid=5 stamp=687435420
channel ORA_DISK_1: starting piece 1 at 21-MAY-09
channel ORA_DISK_1: finished piece 1 at 21-MAY-09
piece handle=C:\RMANBACKUP\BACKUPORCL_DB_01KFIRKU_1_1_%S_%P tag=TAG20090521T1017
01 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16
Finished backup at 21-MAY-09

Starting backup at 21-MAY-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF

input datafile fno=00003 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF

input datafile fno=00004 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
input datafile fno=00002 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DB
F
channel ORA_DISK_1: starting piece 1 at 21-MAY-09
channel ORA_DISK_1: finished piece 1 at 21-MAY-09
piece handle=C:\RMANBACKUP\BACKUPORCL_DB_02KFIRLF_1_1_%S_%P tag=TAG20090521T1017
19 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:06
Finished backup at 21-MAY-09

Starting backup at 21-MAY-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=7 recid=6 stamp=687435506
channel ORA_DISK_1: starting piece 1 at 21-MAY-09
channel ORA_DISK_1: finished piece 1 at 21-MAY-09
piece handle=C:\RMANBACKUP\BACKUPORCL_DB_03KFIRNJ_1_1_%S_%P tag=TAG20090521T1018
27 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 21-MAY-09

Starting Control File and SPFILE Autobackup at 21-MAY-09
piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215124933-20090521-00 com
ment=NONE
Finished Control File and SPFILE Autobackup at 21-MAY-09

RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 2 days
using channel ORA_DISK_1
no obsolete backups found

RMAN> exit

Recovery Manager complete.

C:\>

Now the RMAN setup is completed successfully. Here are the info about RMAN.

Primary DB = ORCL
Catalog DB = CATDB
RMAN Backup location = c:\rmanbackup.

Now the full backup is taken. Every day, the below script should run and backup the new archive log files.

C:\>rman catalog=rman/rman@catdb target=sys/password@orcl

Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 10:25:40 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: ORCL (DBID=1215124933)
connected to recovery catalog database

RMAN> run{
2> delete noprompt obsolete;
3> backup archivelog all;
4> }

RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 2 days
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=133 devtype=DISK
no obsolete backups found

Starting backup at 21-MAY-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=2 recid=1 stamp=687435222
input archive log thread=1 sequence=3 recid=2 stamp=687435237
input archive log thread=1 sequence=4 recid=3 stamp=687435270
input archive log thread=1 sequence=5 recid=4 stamp=687435279
input archive log thread=1 sequence=6 recid=5 stamp=687435420
input archive log thread=1 sequence=7 recid=6 stamp=687435506
input archive log thread=1 sequence=8 recid=7 stamp=687435975
channel ORA_DISK_1: starting piece 1 at 21-MAY-09
channel ORA_DISK_1: finished piece 1 at 21-MAY-09
piece handle=C:\RMANBACKUP\BACKUPORCL_DB_05KFIS68_1_1_%S_%P tag=TAG20090521T1026
15 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16
Finished backup at 21-MAY-09

Starting Control File and SPFILE Autobackup at 21-MAY-09
piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215124933-20090521-01 com
ment=NONE
Finished Control File and SPFILE Autobackup at 21-MAY-09

RMAN> exit

Recovery Manager complete.

C:\>

How do we schedule the daily backup in Windows OS?

We need to write two script, one is batch file(named as daily_backup.bat) which should contain the following command.

rman catalog=rman/rman@catdb target=sys/password@orcl cmdfile daily_backup.sql

Another one is text file(named as daily_backup.sql) which should contain the following code.

run
{
backup archivelog all;
delete noprompt obsolete;
}

The batch file(daily_backup.bat) can be run manually, by double-clicking on it, or scheduled using the Scheduled Tasks Wizard (Start > Programs > Accessories > System Tools > Scheduled Tasks). The above two windows scripts are tested in windows environment and works well.

How do we schedule the daily backup in Unix?

Here we need to write shell script and schedule the shell script in unix scheduler(crontab).

The shell script content should be like this....... Please remember, the below shell script is not tested in unix environment. Please do test yourself in unix environment.... This is sample shell script...

export ORACLE_HOME=/usr/app/oracle/product/10.2.0
export ORACLE_SID=orcl
export ALIAS=orcl
cd =/usr/app/oracle/product/10.2.0/bin
rman catalog=rman/rman@catdb target=sys/password@orcl <<
run
{
backup archivelog all;
delete noprompt obsolete;
}
exit
EOF

The above shell script can be scheduled in crontab. To learn more about crontab, see this link.

If you want to read more on RMAN, Please click this link....

I have discussed some of the other topics which are related to this thread. Please go through below links in case if you are interested....

What are the new features in RMAN since Oracle9i? Click here

Different type of recovery scenario in RMAN? Click here