Professional Documents
Culture Documents
Channels:
- - %U = %u_%p_%c
- %c: copy number of t he backup f i l e
- %t : backup set t i mest amp
- %n: dat abase name
- %d: dat abase name
- %p: backup pi ece number
Rman>
conf i gur e devi ce t ype di sk| sbt par al l el i sm3; ### max 255
conf i gur e def aul t devi ce t ype t o di sk;
conf i gur e devi ce t ype di sk cl ear ;
conf i gur e def aul t devi ce t ype cl ear ;
conf i gur e channel devi ce t ype di sk Rat e 5M;
Readr at e 5M;
For mat = / di sk2/ backup/ %U ;
Maxopenf i l es=10;
Maxpi ecesi ze=2G;
### setting disk IO rates
conf i gur e channel 1 devi ce t ype di sk r at e 5M;
conf i gur e channel 2 devi ce t ype di sk r at e 1M;
### rac option for backing up
conf i gur e channel 1 devi ce t ype di sk connect = sys/ passwor d@node1 ;
conf i gur e channel 2 devi ce t ype di sk connect = sys/ passwor d@node2 ;
### clearing channel settings
conf i gur e channel devi ce t ype di sk cl ear ;
conf i gur e channel 1 devi ce t ype di sk cl ear ;
### backing up to different disk media
conf i gur e channel 1 devi ce t ype di sk f or mat / di sk1/ %U ;
conf i gur e channel 2 devi ce t ype di sk f or mat / di sk2/ %U ;
Show al l ;
Show devi ce t ype;
Show def aul t devi ce t ype;
Show channel ;
### command blocks
Rman>
Run
{
Al l ocat e channel c1 devi ce t ype di sk;
Backup dat af i l e 3, 4, 5;
}
3|P a g e
Backup:
### backup database
Rman>
Backup dat abase i ncl ude cur r ent cont r ol f i l e;
Backup dat abase pl us ar chi vel og [ del et e al l [ i nput ] ] ;
Backup [ devi ce t ype di sk| sbt ] dat abase;
Backup dat abase t ag= <t ag_name> ;
Backup not backed up si nce t i me sysdat e- 3 dat abase pl us ar chi vel og;
Backup f or mat pat h/ %U dat abase f i l eper set 3;
Backup f ul l dat abase [ ski p of f l i ne| r eadonl y| i naccessi bl e] ;
### incremental and differential backups
Backup i ncr ement al l evel 0 dat abase;
Backup i ncr ement al l evel 1 dat abase;
Backup i ncr ement al l evel 1 di f f er ent i al dat abase;
Backup i ncr ement al l evel 1 cumul at i ve dat abase;
### overriding backup retentions
Backup dat abase keep unt i l t i me t o_dat e( 03. 08. 2007 , DD. MM. YYYY ) ;
Backup dat abase keep f or ever nol ogs;
### validation of backups
Backup val i dat e dat abase ar chi vel og al l ;
### backup parameters
Backup t abl espace dat a_t s f i l esper set =10 maxset si ze=20G;
Backup t abl espace <t s_name>;
### backup backupsets and imagecopies
Backup backupset 12;
Backup backupset compl et ed bef or e sysdat e- 7 del et e i nput ;
Backup backupset al l [ del et e i nput ] ;
Backup copy of dat abase del et e i nput ;
### configure backup copies
Conf i gur e dat af i l e backup copi es f or devi ce t ype di sk t o 3;
Conf i gur e ar chi vel og backup copi es f or devi ce t ype di sk t o 3;
Conf i gur e dat af i l e backup copi es f or devi ce t ype di sk cl ear ;
Backup devi ce t ype di sk copi es 3 dat af i l e 7 f or mat =
/ t emp/ %U, / dat a2/ backup/ %U, ?/ dbs/ %U;
### backup tablespace
Backup t abl espace user s f or mat =user s_%u%p%c;
Conf i gur e excl ude f or t abl espace <t s_name>;
Backup dat abase; ### wi l l excl ude t he t abl espaces
Backup dat abase noexcl ude; ### i f you dont want t o excl ude t he t s
Conf i gur e excl ude f or t abl espace <t s_name> cl ear ;
### backup database archivelog
Backup ar chi vel og al l [ del et e [ al l ] i nput ] ;
Backup ar chi vel og f r omsequence 121 unt i l sequence 125;
Backup ar chi vel og f r omt i me sysdat e- 30 unt i l t i me sysdat e- 7 ;
### backing up controlfile and spfile
Backup ( spf i l e) ( cur r ent cont r ol f i l e) ;
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>
Rest or e val i dat e;
Rest or e dat abase val i dat e;
### recovering full db
Rest or e dat abase;
Recover dat abase;
Recover dat abase
# opt i onal l y, del et e l ogs r est or ed f or r ecover y and l i mi t di sk space used
Del et e ar chi vel og maxsi ze 100M
# opt i onal l y, ski p t he r ecover y of some t abl espaces
Ski p t abl espace hi st or y;
Recover dat abase [ del et e ar chi vel og [ maxsi ze=1G] ] ;
### incomplete recovery
r un
{
set unt i l t i me ' Nov 15 2001 09: 00: 00' ;
# you can use unt i l cl ause wi t h r est or e or r ecover commands
# r est or e unt i l sysdat e- 7 ;
# r ecover unt i l sysdat e- 7 ;
# al t er nat i vel y, you can speci f y SCN
# set unt i l scn 1000;
# al t er nat i vel y, you can speci f y l og sequence number
# set unt i l sequence 9923;
6|P a g e
r un
{
al l ocat e channel t 1 devi ce t ype sbt ;
r est or e spf i l e f r omaut obackup;
}
st ar t up f or ce nomount ;
r un
{
# manual l y al l ocat e a channel t o t he medi a manager
al l ocat e channel t 1 devi ce t ype sbt ;
# r est or e an aut obackup of t he cont r ol f i l e. t hi s exampl e assumes t hat
you have
# accept ed t he def aul t f or mat f or t he aut obackup name.
r est or e cont r ol f i l e f r omaut obackup;
# t he set unt i l command i s used i n case t he dat abase
# st r uct ur e has changed i n t he most r ecent backups, and you wi sh t o
# r ecover t o t hat poi nt - i n- t i me. n t hi s way r man r est or es
# t he dat abase t o t he same st r uct ur e t hat t he dat abase had at t he
speci f i ed t i me.
set unt i l sequence 1124 t hr ead 1;
al t er dat abase mount ;
r est or e dat abase;
r ecover dat abase;
}
al t er dat abase open r eset l ogs; # r eset t he onl i ne l ogs af t er r ecover y
compl et es
### 2
r un
{
# i f you need t o r est or e t he f i l es t o new l ocat i ons, t el l r ecover y
# manager
# t o do t hi s usi ng set newname commands:
set newname f or dat af i l e 1 t o ' / dev/ vgd_1_0/ r l vt 5_500m_1' ;
set newname f or dat af i l e 2 t o ' / dev/ vgd_1_0/ r l vt 5_500m_2' ;
set newname f or dat af i l e 3 t o ' / dev/ vgd_1_0/ r l vt 5_500m_3' ;
al l ocat e channel t 1 devi ce t ype sbt ;
r est or e cont r ol f i l e f r omaut obackup;
set unt i l sequence 124 t hr ead 1;
al t er dat abase mount ;
r est or e dat abase;
# updat e t he cont r ol f i l e wi t h new l ocat i on of t he dat af i l es.
swi t ch dat af i l e al l ;
r ecover dat abase;
}
al t er dat abase open r eset l ogs;
### blockrecover command
bl ockr ecover dat af i l e 8 bl ock 13 dat af i l e 2 bl ock 19;
# r est or e f r ombackupset
bl ockr ecover dat af i l e 8 bl ock 13 dat af i l e 2 bl ock 19 f r ombackupset ;
# r est or e f r omdat af i l e i mage copy
bl ockr ecover dat af i l e 8 bl ock 13 dat af i l e 2 bl ock 19 f r omdat af i l ecopy;
# r est or e usi ng backups made bef or e one week ago
bl ockr ecover dat af l e 8 bl ock 13 dat af l e 2 bl ock 19 r est or e unt i l
' sysdat e- 7' ;
# r est or e usi ng backups made bef or e scn 100
bl ockr ecover dat af i l e 8 bl ock 13 dat af i l e 2 bl ock 19 r est or e unt i l scn 100;
# r est or e usi ng backups made bef or e l og sequence 7024
9|P a g e
10|P a g e
Others:
SQL al t er t abl espace t ool s of f l i ne i mmedi at e ;
SQL al t er t abl espace t ool s onl i ne ;
I f usi ng Cat al og;
Cr eat e scr i pt <scr i pt _name>
{
Backup
I ncr ement al l evel 0
Tag backup_whol e_10
Fi l eper set 6
Dat abase pl us ar chi vel og;
#comment out
}
Backup as compr essed backupset t abl espace syst em, sysaux t ag=syst em_backup;
Del et e backupset t ag=syst em_backup;
Run
{
Execut e scr i pt <scr i pt _name>;
}
Sql pl us r man/ pass@cat ;
Sel ect * f r omr c_st or ed_scr i pt ;
Resync cat al og;
Al t er syst emset cont r ol f i l e_r ecor d_keep_t i me=7; #def aul t 7
Example Scripts:
Backup cont r ol f i l e
r un
{
Al l ocat e channel dev1 t ype di sk f or mat c: \ backup\ %u ;
backup cur r ent cont r ol f i l e;
}
r ecover usi ng backup cont r ol f i l e ( st ar t up mount )
r un
{
al l ocat e channel dev1 t ype di sk;
r est or e cont r ol f i l e;
al t er dat abase mount ;
r est or e dat abase;
r ecover dat abase;
sql al t er dat abase open r eset l ogs;
}
backup al l dat af i l es and cont r ol f i l e
r un
{
al l ocat e channel dev1 t ype di sk;
backup f ul l t ag = f ul l backup dat abase i ncl ude cur r ent cont r ol f i l e f or mat = c. . ;
r el ease chanel dev1;
}
r est or e because of mi ssi ng f i l e ( f i r st mount t he dat abase and r un r man)
r un
{
al l ocat e channel dev1 t ype di sk;
r est or e dat abase;
r ecover dat abase;
}
restore until time
- - set unt i l t i me must mat ch wi t h t he var i abl e NLS_DATE_FORMAT
r un
{
#sql al t er sessi on set nl s_dat e_f or mat = dd- mm- yyyy hh24: mi : ss ;
#set unt i l t i me 01- 05- 2008 08: 00: 00
set unt i l t i me May 1 2000 08: 00: 00 ;
al l ocat e channel dev1 t ype di sk;
shut down abor t ;
st ar t up mount ;
r est or e cont r ol f i l e;
al t er dat abase mount ;
r est or e dat abase;
r ecover dat abase;
sql al t er dat abase open r eset l ogs ;
}
pur ge obsol et e backups
r epor t obsol et e r edundancy 3 devi ce t ype di sk;
r epor t obsol et e or phan; / / use t hi s r epor t t o f i l l xxx bel ow
r un
{
al l ocat e channel f or mai nt enance t ype di sk;
al l ocat e channel f or del et e t ype di sk;
14|P a g e
10g enhancement s
RUN {
# Set t he def aul t channel conf i gur at i on. Not e t he use of t he
# %U di r ect i ve t o i nsur e uni que f i l e names f or t he i mage copi es
ALLOCATE CHANNEL dbkp1 DEVI CE TYPE DI SK FORMAT ' c: \ or acl e\ r manbkup\ U%' ;
# Cr eat e an i mage copy of al l dat af i l es i n t he dat abase
BACKUP AS COPY DATABASE;
}
OracleError:ORA19590:conversationalreadyactive
Cause:Youtriedtobeginabackuporrestoreconversation,butanotherconversationisalreadyactiveinthissession.
Action:Eithercontinuethecurrentconversation,orcallbackupCancelorrestoreCanceltoendthecurrentconversationbeforestartinga
newone