Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
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;
Show all;
Show device type;
Show default device type;
Show channel;
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;
3 | P a g e
Backup current controlfile tag=‘<tag_name>’;
Backup current controlfile format ‘?/oradata/%F.ctl’;
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;
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;
5 | P a g e
restore database;
recover database;
sql ‘alter database open resetlogs’;
}
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>’;
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’)”;
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;
8 | P a g e
blockrecover datafıle 8 block 13 datafıle 2 block 19 restore until sequence
7024;
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:
If using Catalog;
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
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;
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;
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)
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')";
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;
12 | P a g e
Example Scripts:
Backup controlfile
run
{
Allocate channel dev1 type disk format ‘c:\backup\%u’;
backup current controlfile;
}
run
{
allocate channel dev1 type disk;
restore controlfile;
alter database mount;
restore database;
recover database;
sql “alter database open resetlogs”;
}
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;
}
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’;
}
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;
}
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
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%';
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