martes, 22 de septiembre de 2009

RMAN Backups

Types of Files That RMAN Can Back Up
RMAN lets you back up all the files you’d need for a database recovery, such as the following:
• Datafiles
• Control files
• Archived redo logs
• Image copies of datafiles and control files, including those made by RMAN
• Backup pieces that contain RMAN backups

RMAN> backup as backupset database;

The following command shows how to specify a tape device as the backup destination
and specify that the backup be made as a backup set:

RMAN> backup as backupset device type sbt database;

To make image copies of the database, use the as copy clause instead, as shown here:

RMAN> backup as copy database;


RMAN> backup database format= '/u01/backup_%U ';

ASM

RMAN> backup
database
format '+dgroup1';

Backing Up the Control File

RMAN> configure controlfile autobackup on;

From here on out, RMAN will create a backup of the control file (as well as the server
parameter file) whenever you perform any backup with RMAN or make structural database
changes.
If you prefer not to configure automatic control file backups, you can use the backup command’s
current controlfile clause to perform a manual backup of the current control file, as
shown here:

RMAN> backup current controlfile;
You also have the option to manually include the control file with any other backup that
you make. You do that by adding the include current controlfile option to any backup command.

For example, you can back up the control file as part of a tablespace backup operation:

RMAN> backup tablespace users include current controlfile;

Backing Up the Server Parameter File

RMAN> backup spfile;

Starting backup at 22-SEP-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=2757 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=3576 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 22-SEP-09
channel ORA_DISK_1: finished piece 1 at 22-SEP-09
piece handle=/u02/app/oracle/flash_recovery_area/LETODB/backupset/2009_09_22/o1_mf_nnsnf_TAG20090922T151400_5cld0b3z_.bkp tag=TAG20090922T151400 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 22-SEP-09

Starting Control File and SPFILE Autobackup at 22-SEP-09
piece handle=/u02/backup/letodb/c-3814852239-20090922-03 comment=NONE
Finished Control File and SPFILE Autobackup at 22-SEP-09

RMAN>

Backing Up Datafiles

SQL> select file#, name from v$datafile;

RMAN> backup datafile 1,2,3,4
format '/u01/app/oracle/rman/%d_%U.bus';

RMAN> backup as copy datafile '/ora01/testdb/system01.dbf'
format '/oraback/system01.bk';

Backing Up Tablespaces

RMAN> backup tablespace users, tools;

RMAN> backup tablespace system format '/ora01/prod1/%d_%U.bus';

RMAN> backup as copy tablespace users;

RMAN> backup incremental level 1 tablespace example;

Making a Whole-Database Backup


RMAN> backup database;

RMAN> backup database;
RMAN> SQL "alter system archive log current";

RMAN> backup archivelog all;

RMAN> backup device type sbt
archivelog like '/disk%arc%'
delete all input;

RMAN> backup archivelog
from time "sysdate-15" until time "sysdate-7";

RMAN> backup archivelog sequence 99
delete input;

RMAN> backup archivelog sequence between 99 and 199 thread 1
delete input;

Backing Up Everything

RMAN> configure controlfile autobackup on;

Then you can issue the backup database plus archivelog command to back up the
database along with the archived redo logs:

RMAN> backup database plus archivelog;

RMAN> list backup by file;

RMAN> backup database
2> include current controlfile;

Backing Up Flash Recovery Files

RMAN> backup recovery area;

The previous command will back up recovery files that were created not only in the
current flash recovery area but also in all previous flash recovery area locations.
If you want to back up the recovery files located in all locations, not merely the flash
recovery area, use the following command instead after configuring a tape backup channel:

RMAN> backup recovery files;

RMAN> backup incremental level 1 datafile 5;


Performing Incremental Backups


Differential Incremental Backups
A differential incremental backup is an incremental backup of all data blocks that changed
subsequently to a level 0 or a level 1 backup. RMAN first looks for a level 1 backup and, in its
absence, looks for a level 0 backup and backs up all changes since that level 0 backup. Here’s
an example of a differential incremental level 0 backup:

RMAN> backup incremental level 0 database;

Incremental level 0 backups can be made as image copies or backup sets.
Here’s how you’d perform a level 1 differential incremental backup that backs up the data
blocks changed since the most recent level 0 or, if there’s no level 0 backup, a level 1 backup:

RMAN> backup incremental level 1 database;

Cumulative Incremental Backups
A cumulative incremental backup is an incremental backup of all data blocks that changed
subsequently to the most recent level 0 incremental backup. The following command shows
how to make a cumulative incremental backup of a database:

RMAN> backup incremental level 1 cumulative database;

RMAN> backup incremental level 1 database;


You can’t use an incremental backup directly during a database restore operation since it’s
only a complement to a full backup and can’t be “restored.” It’s only to provide a faster recovery
time (faster mean time to recovery, or MTTR). The following example serves to
demonstrate this point:
RMAN> run
{
restore datafile 7;
recover datafile 7;
}

Reducing Incremental Backup Time

1. First, make sure the db_create_file_dest parameter is set. If it isn’t, set it using the
alter system command, as shown in this example:
SQL> alter system set
db_create_file_dest='/u01/app/oracle/dfiles'
scope= both;

2. Enable block change tracking by using the following alter database statement:
SQL> alter database enable block change tracking;
Database altered.

If you want, you can create the block changing file in a location you specify, as shown here:

SQL> alter database enable block change tracking using file
'/u05/app/oracle/change_track.txt';
Database altered.

You can disable block change tracking by using the following command:

SQL> alter database disable block change tracking;

The V$BLOCK_CHANGE_TRACKING view shows whether change tracking is enabled as
well as other things such as the change tracking filename.
If you need to move the change tracking file, use the following procedure:

1. Determine the current location of the change tracking file with the following command:
SQL> select filename from v$block_change_tracking;

2. Shut down the database.

3. Move the change tracking file to the new location using the following command:

$ mv /u05/app/oracle/change_trck.f /u10/app/oracle/change_track.f

4. Start up the database in mount mode:

SQL> startup mount

5. Use the alter database rename file command to rename the change tracking file in
the Oracle database:

SQL> alter database rename file
'/u05/app/oracle/change_track.f' to
'/u10/app/oracle/change_track.f';

6. Open the database:

SQL> alter database open;


If you can’t shut down the database for some reason, you have to first disable change
tracking and then reenable it after you rename the change tracking file, as shown here:

SQL> alter database disable block change tracking;

SQL> alter database enable block change tracking using file
'/u10/app/oracle/change_track.f';

Creating Multiple Backup Sets


RMAN> backup
copies 2
database
format '/u01/app/oracle/backup/db_%U',
'/u02/app/oracle/backupdb_%U';

run
{
allocate channel c1 device type sbt;
parms 'env=(ob_device_1=testtape1,ob_device_2=testtape2)';
set backup copies = 2;
backup database plus archivelog;
}

RMAN> run {
allocate channel d1 type disk;
set backup copies = 2;
backup
as backupset
datafile 12
format '+BACKUP',
'+BACKUP';
release channel d1;
}

Making Copies of Backup Sets

RMAN> backup device type sbt
backupset
completed before 'sysdate-30'


Making Copies of Image Copy Backups

You want to make copies of image copy backups you’ve already made using RMAN.

RMAN> backup as copy copy of database;
RMAN> backup as backupset copy of tablespace users;
RMAN> backup as backupset copy of datafile 4;

RMAN> backup as copy
copy of datafile 2,3
from tag 'weekly_copy'
format '/backup/datafile%f_Database%d';

RMAN> backup as copy
copy of database
from tag "test";

Making Tape Copies of Disk-Based Image Copies

RMAN> backup device type sbt datafilecopy '/u05/app/oracle/system01.dbf';

RMAN> backup datafilecopy from tag whole_tag;

RMAN> backup as backupset
device type sbt_tape
tag "monthly_backup"
copy of database;

Excluding a Tablespace from a Backup

RMAN> show exclude;
RMAN configuration parameters are:
RMAN configuration has no stored or default parameters
RMAN>

RMAN> configure exclude for tablespace users;

RMAN> configure exclude for tablespace users clear;

RMAN will back
up all tablespaces, including those tablespaces that you expressly excluded from the backup
earlier with a configure exclude command. Here’s how you use the noexclude option as part
of a backup database command:

RMAN> backup database noexclude;

Skipping Read-Only,Offline, or Inaccessible Files

RMAN> backup database
skip inaccessible
skip readonly
skip offline;

Encrypting RMAN Backups

SQL> alter system set encryption key identified by "sammyy11";
System altered.

RMAN> configure encryption for database on;

RMAN> backup database;

RMAN> set encryption on identified by only;

RMAN> configure encryption for database off;

RMAN> configure encryption for tablespace example on;

RMAN> configure encryption for tablespace example off;

Making a Compressed Backup

RMAN> backup
as compressed backupset
database plus archivelog;

Parallelizing Backups

run
{
allocate channel ch1 device type sbt
parms 'env=(ob_device_1=testtape1)';
allocate channel ch2 device type sbt
parms 'env=(ob_device_2=testtape12';
backup
database channel ch1
archivelog all channel ch2;
}


run
{
allocate channel d1 device type disk format '/u01/%d_backups/%U';
allocate channel d2 device type disk format '/u02/%d_backups/%U';
allocate channel d3 device type disk format '/u03/%d_backups/%U';
allocate channel d4 device type disk format '/u04/%d_backups/%U';
backup database;
}

RMAN> configure device type disk parallelism 4;

RMAN> configure device type sbt parallelism 3;

RMAN> configure device type sbt clear;

Making Faster Backups of Large Files


$ rman target sys/@target_db

{allocate channel c1 device type sbt
parms 'env=(ob_device_1=testtape1)';
allocate channel c1 device type sbt
parms 'env=(ob_device_2=testtape2)';
allocate channel c1 device type sbt
parms 'env=(ob_device_3=testtape3)';

RMAN> backup
section size 150m
tablespace system;

RMAN> exit

The section_size column in both the V$BACKUP_DATAFILE and RC_BACKUP_DATAFILE
views shows the number of blocks in each section of a multisection backup. If you haven’t
performed any multisection backups, the section_size column would have a zero value. The
V$BACKUP_SET and RC_BACKUP_SET views tell you which backups or multisection backups.
The following example shows a query on the V$BACKUP_DATAFILE view:

SQL> select pieces, multi_section from V$BACKUP_SET;
PIECES MUL
------ --------
1 NO
2 YES
7 YES
4 NO

Specifying Backup Windows

RMAN> backup duration 6:00
database;

You can use the duration clause along with other clauses to control what happens when a
backup fails to complete within the specified time interval. By default, RMAN reports an error
when the backup is interrupted because of the end of the backup interval. If your backup command
is part of a run block, that run block will also terminate immediately. By using the
optional clause partial, you can suppress the RMAN error reports and instead have RMAN
merely report which datafiles it couldn’t back up because of a lack of time. Here’s an example:

RMAN> backup duration 6:00 partial
database

In addition to not issuing any error messages, the partial clause also lets the other commands
within a run block continue to execute after the termination of a backup when the
window of time for backups expires. You can also use the duration clause along with one of
two other options to control the speed of the backup. To perform the backup in the shortest
time possible, specify the minimize time option, as shown here:


RMAN> backup
duration 6:00 partial
minimize time
database
filesperset 1;

On the other hand, if you think that the backup may not go over the backup window,
you can reduce the overhead imposed by the backup with the minimize load option with the
duration clause, as shown here:

RMAN> backup
duration 6:00 partial
minimize load
database
filesperset 1 ;

Reusing RMAN Backup Files

You can use the reuse option with your backup commands to enable RMAN to overwrite existing
backups, as shown in the following example:

RMAN> backup reuse database;

Retaining Backups for a Long Time

Use the keep option with the backup command to retain backups beyond what’s mandated by
the retention polices that you’ve configured. In the following example, the keep until time
clause tells RMAN to retain the backup for a period of six months:

run
{
backup database
tag quarterly
keep until time 'sysdate+180'
restore point 2007Q1;
}

You may sometimes need to retain a given backup forever. As long as you’re using a recovery
catalog, you can simply use the keep forever option during a backup command to exempt
a backup copy from any retention policies:

run
{
backup database
tag quarterly
keep forever
restore point Y2007Q1;
}

One of the common uses of archival backups is to use them for creating a test database on
a different server. Since you won’t need the backups after you create the test database from the
backups, you can set the keep parameter to sysdate+1, meaning that the backup will become
obsolete a day after the backup is made, regardless of your backup retention policy. Here’s an
example:



run
{
backup database
tag quarterly
keep until time 'sysdate+1';
restore point Y2007Q1
}

RMAN> backup database keep forever tag 'semi_annual_bkp';
RMAN> change backup tag 'semi_annual_bkp' unavailable;

Backing Up Only Those Files Previously Not Backed Up

RMAN> backup database not backed up;


Restarting Backups After a Crash

Problem

The RMAN backup process fails midway through a database backup, say, because of a database

instance crash or because of the unavailability of some datafiles. You want to resume the
backup but save time by backing up only those parts of the database that failed to be backed
up the first time.

Solution
Use the restartable backup feature to back up only those files that failed to be backed up the
first time around. Use the not backed up since time clause of the backup command to restart a backup after it partially completes. If the time you specify for the since time clause is a more
recent time than the backup completion time, RMAN backs up the database file.
Here’s an example that shows how to restart an RMAN backup that failed midway through
a nightly backup. You discover the backup failure in the morning and decide to back up only
those parts of the database that weren’t backed up by RMAN before the backup failed. Simply
run the following backup command to achieve your goal.

RMAN> backup not backed up since time 'sysdate-1'
database plus archivelog;

Updating Image Copies

You want to update image copies to keep them current without having to perform lengthy
image copy backups of entire datafiles.

run {
recover copy of database
with tag 'incr_update';
backup
incremental level 1 for recover of copy with tag 'incr_update'
database;
}


RMAN> run
2> {
3> recover copy of database
4> with tag 'incr_update';
5> backup
6> incremental level 1
7> for recover of copy with tag 'incr_update'
8> database;
9> }