Sei sulla pagina 1di 16

ORACLE 9i RMAN (10g)

(rev0.1) – August, 2007 – by Ergem PEKER


(rev1.1) – December, 2008 – by Ergem PEKER
10g enhancements and some more functionalities.

Version: Oracle Database 10.2.0.1 on Windows2003 Server


Oracle Database 9.2.0.4 on IBM pSeries AIX5L Server

Connecting to rman:

Host#> rman
Rman> connect target /
Rman> connect target dbuser as sysdba/passwd@TNS
Rman> connect catalog rman/pass@TNS
Rman> connect auxiliary dbuser/dbpass@TNS

### interactive mode


Host#> rman target / catalog rman/pass@TNS
Host#> rman target / nocatalog

### batch mode


Host#> rman target / catalog rman/rman@d cmdfile <cmd_file_name> log
<log_file_name>

Host#> rman target / @‘daily.rcv’

Rman> report schema

### creating rman catalog


1- Connect to rman catalog database with sysdba privileges
2- Create catalog user with unlimited quota and grant
recovery_catalog_owner, connect, resource
3- Start rman with recovery catalog options
4- run “create catalog” command in rman
5- register the target database with “register database” command

### creating pipe interface


Host#> rman pipe rmpipe target sys/<password>@TNS_ALIAS
ORA$RMAN_RMPIPE_IN (rman input pipe)
ORA$RMAN_RMPIPE_OUT (rman output pipe)

SQLPLUS> DBMS_PIPE.PACK
SQLPLUS> DBMS_PIPE.SEND_MESSAGE

SQLPLUS> DBMS_PIPE.RECEIVE_MESSAGE
SQLPLUS> DBMS_PIPE.UNPACK

1 | P a g e  
 
Channels:
-- %U = %u_%p_%c
- %c: copy number of the backup file
- %t: backup set timestamp
- %n: database name
- %d: database name
- %p: backup piece number

Rman>
configure device type disk|sbt parallelism 3; ### max 255
configure default device type to disk;

configure device type disk clear;


configure default device type clear;

configure channel device type disk Rate 5M;


Readrate 5M;
Format=’/disk2/backup/%U’;
Maxopenfiles=10;
Maxpiecesize=2G;

### setting disk IO rates


configure channel 1 device type disk rate 5M;
configure channel 2 device type disk rate 1M;

### rac option for backing up


configure channel 1 device type disk connect=’sys/password@node1’;
configure channel 2 device type disk connect=’sys/password@node2’;

### clearing channel settings


configure channel device type disk clear;
configure channel 1 device type disk clear;

### backing up to different disk media


configure channel 1 device type disk format ’/disk1/%U’;
configure channel 2 device type disk format ’/disk2/%U’;

Show all;
Show device type;
Show default device type;
Show channel;

### command blocks


Rman>
Run
{
Allocate channel c1 device type disk;
Backup datafile 3,4,5;
}

2 | P a g e  
 
Backup:
### backup database
Rman>
Backup database include current controlfile;
Backup database plus archivelog [delete all [input]];
Backup [device type disk|sbt] database;
Backup database tag=‘<tag_name>’;
Backup not backed up since time ‘sysdate-3’ database plus archivelog;

Backup format ‘path/%U’ database fileperset 3;


Backup full database [skip offline|readonly|inaccessible];

### incremental and differential backups


Backup incremental level 0 database;
Backup incremental level 1 database;
Backup incremental level 1 differential database;
Backup incremental level 1 cumulative database;

### overriding backup retentions


Backup database keep until time “to_date(’03.08.2007’,’DD.MM.YYYY’)”;
Backup database keep forever nologs;

### validation of backups


Backup validate database archivelog all;

### backup parameters


Backup tablespace data_ts filesperset=10 maxsetsize=20G;
Backup tablespace <ts_name>;

### backup backupsets and imagecopies


Backup backupset 12;
Backup backupset completed before ‘sysdate-7’ delete input;
Backup backupset all [delete input];
Backup copy of database delete input;

### configure backup copies


Configure datafile backup copies for device type disk to 3;
Configure archivelog backup copies for device type disk to 3;
Configure datafile backup copies for device type disk clear;

Backup device type disk copies 3 datafile 7 format=


“/temp/%U”,“/data2/backup/%U”,“?/dbs/%U”;

### backup tablespace


Backup tablespace users format=“users_%u%p%c”;

Configure exclude for tablespace <ts_name>;


Backup database; ### will exclude the tablespaces
Backup database noexclude; ### if you dont want to exclude the ts
Configure exclude for tablespace <ts_name> clear;

### backup database archivelog


Backup archivelog all [delete [all] input];
Backup archivelog from sequence 121 until sequence 125;
Backup archivelog from time ‘sysdate-30’ until time ‘sysdate-7’;

### backing up controlfile and spfile


Backup (spfile) (current controlfile);

3 | P a g e  
 
Backup current controlfile tag=‘<tag_name>’;
Backup current controlfile format ‘?/oradata/%F.ctl’;

Backup controlfilecopy '/tmp/control01.ctl';

### automatically backup controlfile


Configure controlfile autobackup on | off;

Backup current controlfile tag=’controlfile_27072007’;


Configure controlfile autobackup format [for device type disk] to
'?/oradata/%F.ctl';

### backup datafile


Backup datafile ‘system.dbf’;
Backup datafile 48;
Backup device type disk datafilecopy ‘/data2/backup/online/system_02.dbf’;
Backup datafilecopy ‘/tmp/data01.dbf’;

### copying database files


Copy [current] controlfile to ‘/tmp/control01.ctl’;
Copy datafile 1 to ‘/tmp/1.dbf’;

Copy datafile 1 to ‘/tmp/1.dbf’,


2 to ‘/tmp/2.dbf’,
3 to ‘/tmp/3.dbf’;

Copy datafile 1 to ‘/data2/backup/datafile.dbf’;

### reporting backups


List backup;
List backup of database [summary];
List backup of datafile 48,49,50;
List backup of datafile ‘<datafile_full_path/name>’;
List backup of tablespace users;
List backup of controlfile;
List backup of archivelog all;
List backup of archivelog [summary];
List backup of archivelog from sequence 1000 until sequence 1050;
List copy;
List copy of tablespace <ts_name>;
List copy of archivelog from time=‘sysdate-7’;

### compressed backups


RMAN> Backup as compressed backupset format ‘/oradata/backup/%d_%u.dbf’
database;
RMAN> Sql ‘alter database archive log current’;
RMAN> Backup as compressed backupset format ‘..’ archivelog all delete all
input;

### image copies and backupsets


RMAN> Backup as backupset format ‘../data_06.bus’ datafile 6;
RMAN> Backup as backupset datafile 6;
RMAN> Backup as copy database;

### incremental restore to imagecopies


RMAN> backup as copy incremental level 0 database tag db_whole_copy;
RMAN> backup incremental level 1 for recover of copy with tag db_whole_copy
database tag db_copy_upd;
RMAN> recover copy of database with tag db_whole_copy;
RMAN> delete backupset tag db_copy_upd;

4 | P a g e  
 
Restore & Recover:
### Preparing Recovery

SQL>
Select Status from v$instance;

SQL>
Select
file#,
status,
error,
recover,
tablespace_name,
name
from
v$datafile_header;
SQL>
Select
r.file# as df#,
d.name as df_name,
t.name as tbsp_name,
d.status,
r.error,
r.change#,
r.time
from
v$recover_file r,
v$datafile d,
v$tablespace t
where
t.ts# = d.ts# and
d.file# = r.file#;
### validating backed up database files
Rman>
Restore validate;
Restore database validate;

### recovering full db


Restore database;
Recover database;

Recover database
# optionally, delete logs restored for recovery and limit disk space used
Delete archivelog maxsize 100M
# optionally, skip the recovery of some tablespaces
Skip tablespace history;

Recover database [delete archivelog [maxsize=1G]];

### incomplete recovery


run
{
set until time 'Nov 15 2001 09:00:00';
# you can use until clause with restore or recover commands
# restore until ‘sysdate-7’;
# recover until ‘sysdate-7’;
# alternatively, you can specify SCN
# set until scn 1000;
# alternatively, you can specify log sequence number
# set until sequence 9923;

5 | P a g e  
 
restore database;
recover database;
sql ‘alter database open resetlogs’;
}

### recovering partial db


sql 'alter tablespace <ts_name> offline immediate';
restore tablespace <ts_name>;
recover tablespace <ts_name>;
sql 'alter tablespace <ts_name> online;

### recovering spfile


Rman>
Startup force nomount; # force because spfile is lost
Restore spfile; # if you are using a catalog
Restore spfile from autobackup; # if in NOCATALOG mode
Restore spfile to ‘/tmp/spfile<SID>.ora’ [from autobackup];
Restore spfile to pfile ‘/tmp/spfile<SID>.ora’ [from autobackup];

### restoring controlfile from auto backup


Rman>
Restore controlfile from auto backup; --can be run in nomount mode

### restoring controlfile and a database


Rman>
# open with no controlfile
Startup nomount;
# if you dont use recovery catalog or you have more than one database with
# the same dbname
set dbid <select dbid from v$database>
# specify a nondefault autobackup format only if required
Set controlfile autobackup format for device type disk to ‘?/tmp/%F.ctl’;
Restore controlfile [from autobackup] [maxdays 180];
# mount database
Alter database mount;
# restore database
Restore database;
Recover database;
# open withy resetlogs bease controlfile is from backup
Alter database open resetlogs;
# dont forget to add temp files
SQL ‘alter tablespace temp add tempfile “?/oradata/dbname/temp01.dbf”
reuse’;

# backup the database


Shutdown immediate;
Startup mount;
Backup database;
Alter database open;

### restoring to a new location


### restoring datafiles to a new location
run
{
sql 'alter tablespace users offline immediate';
sql 'alter tablespace tools offline immediate';
# restore the datafile to a new location
set newname for datafile '?/trgt/users01.dbf' to '/tmp/users01.dbf';
set newname for datafile '?/trgt/tools01.dbf' to '/tmp/tools01.dbf';
restore tablespace users, tools;

6 | P a g e  
 
# point control file to new filenames
switch datafile all;
recover tablespace users, tools;
sql 'alter tablespace users online;
sql 'alter tablespace tools online;
}

Rman>
Set newname for datafile ‘?/oradata/dbn/tools01.dbf’ to ‘/tmp/tools01.dbf’;
Restore datafile ‘?/oradata/dbname/tools01.dbf’;

Rman>
Switch datafile ‘/tmp/tools01.dbf’ to datafilecopy ‘<new dbf name>’;

### restoring controlfile to a new location


run
{
# to restore a control file created before a certain date, issue the
# following
# set command using a valid date for 'date_string'. you can also specify
# an scn or log sequence number.
# set until time = 'date_string';
restore controlfile to '/tmp/control01.ctl'; # restore to new location
# replicate the control file manually to control_files locations
restore controlfile from '/tmp/control01.ctl';
startup mount;
}

### restoring archivelogs to a new location


run
{
set archivelog destination to '/oracle/temp_restore';
restore archivelog all;
# restore and recover datafiles as needed
}

run
{
# set a new location for logs 1 through 10.
set archivelog destination to '/tmp';
restore archivelog from sequence 1 until sequence 10;
# set a new location for logs 11 through 20.
set archivelog destination to '?/oradata';
restore archivelog from sequence 11 until sequence 20;
# set a new location for logs 21 through 30.
set archivelog destination to '?/dbs';
restore archivelog from sequence 21 until sequence 30;
restore archivelog from time 'sysdate-20' until time 'sysdate-19';
restore archivelog from time “to_date(’20.02.2008’,’DD.MM.YYYY HH24:MI:SS’)”
until time “to_date(’22.02.2008’,’DD.MM.YYYY HH24:MI:SS’)”;

# restore and recover datafiles as needed


}

### performing disaster recovery


### 1
# Start RMAN and connect to the target database
% rman TARGET SYS/oracle@trgt

# set the DBID for the target database


set dbid 676549873;
startup force nomount; # rman starts instance with dummy parameter file

7 | P a g e  
 
run
{
allocate channel t1 device type sbt;
restore spfile from autobackup;
}
startup force nomount;

run
{
# manually allocate a channel to the media manager
allocate channel t1 device type sbt;
# restore an autobackup of the control file. this example assumes that
you have
# accepted the default format for the autobackup name.
restore controlfile from autobackup;
# the set until command is used in case the database
# structure has changed in the most recent backups, and you wish to
# recover to that point-in-time. ın this way rman restores
# the database to the same structure that the database had at the
specified time.
set until sequence 1124 thread 1;
alter database mount;
restore database;
recover database;
}
alter database open resetlogs; # reset the online logs after recovery
completes

### 2
run
{
# if you need to restore the files to new locations, tell recovery
# manager
# to do this using set newname commands:
set newname for datafile 1 to '/dev/vgd_1_0/rlvt5_500m_1';
set newname for datafile 2 to '/dev/vgd_1_0/rlvt5_500m_2';
set newname for datafile 3 to '/dev/vgd_1_0/rlvt5_500m_3';
allocate channel t1 device type sbt;
restore controlfile from autobackup;
set until sequence 124 thread 1;
alter database mount;
restore database;
# update the control file with new location of the datafiles.
switch datafile all;
recover database;
}
alter database open resetlogs;

### blockrecover command


blockrecover datafile 8 block 13 datafile 2 block 19;
# restore from backupset
blockrecover datafile 8 block 13 datafile 2 block 19 from backupset;
# restore from datafile image copy
blockrecover datafile 8 block 13 datafile 2 block 19 from datafilecopy;
# restore using backups made before one week ago
blockrecover datafıle 8 block 13 datafıle 2 block 19 restore until
'sysdate-7';
# restore using backups made before scn 100
blockrecover datafile 8 block 13 datafile 2 block 19 restore until scn 100;
# restore using backups made before log sequence 7024

8 | P a g e  
 
blockrecover datafıle 8 block 13 datafıle 2 block 19 restore until sequence
7024;

# recover the records in v$database_block_corruption


blockrecover corruption list
from backupset
restore until time 'sysdate-10';

the v$database_block_corruption view indicates which blocks in a datafile were marked 
corrupt since the most recent backup, backup ... validate, or copy command was run. after a 
corrupt block is repaired, the row identifying this block is deleted from the view. 

a historical record of block corruptions in rman backups and copies is kept in 
v$backup_corruption and v$copy_corruption. 
 

9 | P a g e  
 
Others:

SQL ‘alter tablespace tools offline immediate’;


SQL ‘alter tablespace tools online’;

If using Catalog;

Create script <script_name>


{
Backup
Incremental level 0
Tag backup_whole_10
Fileperset 6
Database plus archivelog;
#comment out
}

Backup as compressed backupset tablespace system, sysaux tag=system_backup;


Delete backupset tag=system_backup;

Run
{
Execute script <script_name>;
}

Sqlplus rman/pass@cat;
Select * from rc_stored_script;

Resync catalog;
Alter system set controlfile_record_keep_time=7; #default 7
 
Configure retention policy to recovery window of 7 days;
Configure retention policy to redundancy 2;
Configure retention policy to none; ### no settings
Configure retention policy clear; ### to default settings

Show retention policy;

Crosscheck backup;
Crosscheck backup of database;
Crosscheck copy [of database|tablespace|datafile];

Report obsolete;
Report obsolete redundancy 2;
Delete obsolete;
Delete expired;
Delete force;

Delete backupset 4;
Delete archivelog all backed up 2 times to device type disk;
Delete copy of datafile 6 tag file6_extra;

Catalog datafilecopy ‘<path_to_the copied_datafile>’;

Change backupset 231 nokeep | keep;

10 | P a g e  
 
Change backupset 231 available | unavailable;
Change backupset 231 nologs;
Change backupset tag <tag_name> nokeep;
Change backupset 231 uncatalog | catalog;

### system views


V$backup_files;
V$backup_set;
V$backup_spfile;
V$rman_configuration;
V$backup_datafile;
V$backup_corruption;
V$copy_corruption;
V$backup_device;

V$database_block_corruption;
V$backupset;
v$archived_log
v$backup_redolog
v$backup_piece

large pool
backup restore operations
I/O server processes
Session memory fro shared users
Large_pool_size (approximately 2gb)

Rman
dbwr_io_slaves (integer)
backup_tape_io_slaves (true|false) 

### snapshot controlfile


Show snapshot controlfile name;
Configure snapshot controlfile name to ‘/tmp/controlfile_snapshot.ctl’;
Configure snapshot controlfile name clear; 

### validating backups and backupsets


restore controlfile validate;
restore tablespace system validate;
restore archivelog all validate;

list backupset;
list copy;
list backup of controlfile;
list backup of archivelog
from time "to_date('16.01.2008','DD.MM.YYYY')"
until time "to_date('17.01.2008','DD.MM.YYYY')";

validate backupset 1121;

configure backup optimization on|off;


show backup optimization;
show datafile backup copies;

report schema;
report need backup; --files need backup
report unrecoverable;
report need backup incremental 3 [database];

11 | P a g e  
 
report need backup days 3;
report need backup days 3 [tablespace ‘<ts_name>’];
report need backup redundancy 3;

change datafilecopy ‘...’ unavailable;


change backup of controlfile unavailable | available;
change copy of archivelog sequence between 230 and 240 unavailable;

change ... keep | nokeep;

change backupset 123 keep forever nologs;


change datafile copy ‘...’ keep until ‘sysdate + 60’;

### environment variables and instance parameters


#export nls_date_format=dd-mm-yy hh24:mi:ss
#export NLS_LANG=american_america.we8iso8859p9
SQLPLUS> show parameter control_file_record_keep_time
SQLPLUS> show parameter db_recovery_file_dest
SQLPLUS> show parameter db_recovery_file_dest_size

### minimize load | time


RMAN> Backup as compressed backupset format ‘/oradata/backup/%d_%u.dbf’
duration 8:00 minimize [time | load] fileperset 1 database;

### enabling block change tracking


SQL> Alter database enable block change tracking using file
‘/oradata/backup/change_tracking.dbf’;
SQL> select * from v$block_change_tracking;

12 | P a g e  
 
Example Scripts:

Backup controlfile

run
{
Allocate channel dev1 type disk format ‘c:\backup\%u’;
backup current controlfile;
}

recover using backup controlfile (startup mount)

run
{
allocate channel dev1 type disk;
restore controlfile;
alter database mount;
restore database;
recover database;
sql “alter database open resetlogs”;
}

backup all datafiles and controlfile

run
{
allocate channel dev1 type disk;
backup full tag = ‘full backup’ database include current controlfile format = ‘c..’;
release chanel dev1;
}

restore because of missing file (first mount the database and run rman)

run
{
allocate channel dev1 type disk;
restore database;
recover database;
}

restore until time


--‘set until time’ must match with the variable NLS_DATE_FORMAT

run
{
#sql “alter session set nls_date_format=’’dd-mm-yyyy hh24:mi:ss’’”;
#set until time “01-05-2008 08:00:00”
set until time ‘May 1 2000 08:00:00’;
allocate channel dev1 type disk;
shutdown abort;
startup mount;
restore controlfile;
alter database mount;
restore database;
recover database;
sql ‘alter database open resetlogs’;
}

purge obsolete backups

report obsolete redundancy 3 device type disk;


report obsolete orphan; //use this report to fill xxx below

run
{
allocate channel for maintenance type disk;
allocate channel for delete type disk;

13 | P a g e  
 
change backuppiece ‘c:\backup\xxx’ delete;
release channel;
}

backup all archive logs

run
{
allocate channel dev1 type disk format ‘c\backup\%u’;
backup archivelog all [delete input | skip inaccessible];
}

parallelization

run
{
allocate channel c1 type sbt;
allocate channel c2 type sbt;
allocate channel c3 type sbt;
backup
incremental level 0
format ‘...’
(datafile 1,4,5 channel c1 tag=DF1)
(datafile 2,3,9 channel c1 tag=DF2)
(datafile 6,7,8 channel c1 tag=DF3);
alter system archive log current;
};

***
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
set until time = ‘2000-12-09:11:44:00’;
restore database;
recover database;
alter database open resetlogs;
}

run
{
set until sequence 120 thread 1;
alter database mount;
restore database;
recover database; //recovers through log 119
alter database open resetlogs;
}

Run
{
Allocate channel t1 type sbt_tape;
Allocate channel t2 type sbt_tape;
Backup copy of database delete input;
Backup archivelog all delete all input;
Release channel t1;
Release channel t2;
Allocate channel d1 type disk;
Allocate channel d2 type disk;
Backup as copy database;
Release channel d1;
Release channel d2;
}

select * from v$backup_piece where trunc(start_time)=trunc(ysdate-1)

select
t1.file#, t2.name, t1.incremental_level, t1.datafile_blocks, t1.blocks, t1.block_size,
t1.completion_time

14 | P a g e  
 
from v$backup_datafile t1 LEFT JOIN v$datafile t2 ON (t1.file# = t2.file#) where
trunc(t1.completion_time)=trunc(sysdate-1)
select count(*) from v$datafile

15 | P a g e  
 
10g enhancements

RUN {
# Set the default channel configuration. Note the use of the
# %U directive to insure unique file names for the image copies
ALLOCATE CHANNEL dbkp1 DEVICE TYPE DISK FORMAT 'c:\oracle\rmanbkup\U%';

# Create an image copy of all datafiles in the database


BACKUP AS COPY DATABASE;
}

Oracle Error : ORA‐19590: conversation already active  
 
Cause: You tried to begin a backup or restore conversation, but another conversation is already active in this session. 
 
Action: Either continue the current conversation, or call backupCancel or restoreCancel to end the current conversation before starting a 
new one 

16 | P a g e  
 

Potrebbero piacerti anche