OCM备考 三. Managing Database Availability 之RMAN日常操作
10 OCM考試大綱關于RMAN的考點:
三 Managing Database Availability?
﹡ Create a recovery catalog database?
﹡ Configure Recovery Manager?
﹡ Use Recovery Manager to perform database backups?
﹡ Use Recover Manager to perform complete database restore and recovery operations
?
整理rman日常操作如下:
?
1 備份
1.1 指定backup piece的大小
將較大的backupset分解為多個bakcup piece。
Rman> run {
Allocate channel c1 device type disk maxpiecesize 500m;
Backup database format ‘$ORACLE_BASE/backup’;
}
1.2 使用command file
將多條rman命令包含在command file中,批量執(zhí)行,常用于數(shù)據(jù)庫例行備份。
Cat > rman.csv
run {
??backup datafile 1 format '$ORACLE_BASE/backup/system_%U.bpk';
??backup datafile 2 format '$ORACLE_BASE/backup/sysaux_%U.bpk';
}
執(zhí)行備份:
$ rman target / cmdfile=rman.rcv log=rman.log
1.3 備份時排除表空間
1.3.1 排除指定的表空間
設置備份時要排除的表空間:
Rman> configure exclude for tablespace users;
?
永久取消排除:
Rman> configure exclude for tablespace users clear ;??-
臨時取消排除:
Rman> backup database noexclude;
1.3.2 排除只讀表空間和離線表空間
Rman> backup database skip readonly skip offline;
1.4 并行備份
1.4.1 永久配置PARALLELISM
Rman> CONFIGURE DEVICE TYPE DISK PARALLELISM 5 BACKUP TYPE TO BACKUPSET;
執(zhí)行備份時,自動開5個channel進行備份,備到同一目錄下。
通過配置channel可以備份到不同目錄下:
Rman> CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
Rman> CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT???'/u01/app/oracle/backup/%d_%s_%p.bpk';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT???'/u01/app/oracle/backup2/%d_%s_%p.bpk';
1.4.1 臨時配置PARALLELISM
通過allocate channel分配多個通道。
Rman> run {
Allocate channel c1 device type disk;
Allocate channel c2 device type disk;
Backup database format ‘$ORACLE_BASE/backup/db_%U.bpk’
??(datafile 1,2,3 channel c1)
??(datafile 4,5,6 channel c2);
}
1.5 copy備份
1.5.1 copy備份的方式
可以采取下面兩種方式:
1、backup as copy
Rman> backup as copy datafile 4 format ‘$ORACLE_BASE/backup/users.dbf’;
2、copy
Rman> copy datafile 1 to ‘$ORACLE_BASE/backup/users.dbf’;
1.5.2 刪除copy
Rman> delete datafilecopy 30;
刪除key=30的copy。
1.6 備份的高級功能
1.6.1 filesperset
指定一個backupset中最多包含幾個數(shù)據(jù)文件。
Rman> backup database filesperset 2;
每個備份集中最多只包含兩個數(shù)據(jù)文件。
1.6.2 set maxcorrupt
設置備份時能跳過多少個壞塊,默認為0,即一發(fā)現(xiàn)壞塊,備份任務會報錯退出。
Rman> run {
???Set maxcorrupt for datafile 4 to 5;??#允許5個壞塊
???Backup check logical datafile 4;
}
1.6.3 開啟塊改變跟蹤
Sql> alter database enable block change tracking using file ‘tracking.f’ reuse;
2 恢復
2.1 將數(shù)據(jù)文件恢復到新的位置
出現(xiàn)硬件損壞時,需要將數(shù)據(jù)文件恢復到新的目錄下。
Run {
Sql ‘a(chǎn)lter tablespace users offline immediate’;
Set newname for datafile 4 to ‘/newpath/user.dbf’;
Restore datafile 4;
Swith datafile 4;
Recover datafile 4;
Sql ‘a(chǎn)lter tablespace users online’;
}
2.2 基于SQL的不完全恢復
2.2.1 基于time恢復
將數(shù)據(jù)庫恢復到過去一個時間點。
Sql> startup mount
Sql> recover database until time ‘2011-07-08 10:05:00’;
Sql> alter database open resetlogs;
?
下面是兩個關于scn和time轉(zhuǎn)換的函數(shù)。
注:通過時間得到scn
select timestamp_to_scn(to_timestamp('2011-07-05 10:30:00','yyyy-mm-dd hh24:mi:ss')) from dual;
通過scn得到時間:
select scn_to_timestamp(1418437) from dual;
2.2.2 基于scn恢復
將數(shù)據(jù)庫恢復到過去的一個scn。
Sql> startup mount
Sql> recover database until scn 1418437;
Sql> alter database open resetlogs;
2.2.3 基于cancel恢復
當archivelog或onlinelog損壞,將數(shù)據(jù)庫盡可能地恢復,最大限度地減少數(shù)據(jù)丟失。
Sql> startup mount
Sql> recover database until cancel; #可能需要選擇online log,進行恢復
ORA-00279: change 1426537 generated at 07/06/2011 20:59:43 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive/1_44_754155512.dbf
ORA-00280: change 1426537 for thread 1 is in sequence #44
?
?Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+DGROUPB/dg1/onlinelog/redo5.log #選擇恢復需要的日志文件
?
Sql> alter database open resetlogs;
2.2.4 基于sequence恢復
根據(jù)online log sequence進行恢復,
Sql> startup mount
Sql> recover database until sequence 128; 將數(shù)據(jù)庫恢復到log sequence 127
Sql> alter database open resetlogs;
2.2.5 通過備份控制文件恢復
1)備份控制文件
Sql> alter database backup controlfile to trace;
將控制文件創(chuàng)建語句寫入user trace文件?;蛘?/span>
Sql> alter database backup controlfile to ‘/backup/control01.ctl’;
將控制文件備份。
?
2)恢復
Sql> startup nomount;
重建控制文件,從user trace找到創(chuàng)建控制文件的語句,執(zhí)行:
Sql> recover database using backup controlfile;
ORA-00279: change 1426537 generated at 07/06/2011 20:59:43 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive/1_44_754155512.dbf
ORA-00280: change 1426537 for thread 1 is in sequence #44
?
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
由于是重建控制文件,找不到當前recover需要應用的日志,需要指定log文件:
+DGROUPB/dg1/onlinelog/redo5.log
Log applied.
Media recovery complete.
?
Resetlogs方式打開數(shù)據(jù)庫:
Sql> alter database open resetlogs;
通過備份控制文件恢復數(shù)據(jù)庫,tempfile不會自動產(chǎn)生,需通過手工創(chuàng)建:
Sql> alter tablespace temp add tempfile '+dgroupb/dg1/datafile/temp01.dbf';
2.3 基于rman的不完全恢復
2.3.1 基于time的恢復
Sql> startup mount;
Run {
Set until time = ‘2011-07-08 11:30:30’;
Restore database;
Recover database;
Alter database open resetlogs;
}
2.3.2 基于sequence的恢復
Sql> startup mount;
Run {
Set until sequence 128 thread 1;
Restore database;
Recover database;
Alter database open resetlogs;
}
2.3.3 基于scn的恢復
Sql> startup mount;
Run {
Set until scn 1418437;
Restore database;
Recover database;
Alter database open resetlogs;
}
2.3.4 基于還原點的恢復
Sql> create restore point p1
Rman> restore database;
Rman> recover database until restore point p1;
2.3.5 通過備份控制文件進行不完全恢復
1)控制文件備份
Rman> CONFIGURE CONTROLFILE AUTOBACKUP on;
或
Rman> backup current confile format ‘/backup/control%.bpk’;
或
Rman> backup database including current controlfile;
2)從備份控制文件恢復數(shù)據(jù)庫
Sql> startup nomount;
Rman> restore controlfile to ‘/control01.ctl’??from autobackup; 或
Rman> restore controlfile from ‘備份集名稱’;
Rman> run {
Alter database mount;
Restore database;
Recover database;
Alter database open resetlogs;
}
?
總結(jié)
以上是生活随笔為你收集整理的OCM备考 三. Managing Database Availability 之RMAN日常操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OCM备考 三. Managing Da
- 下一篇: OCM备考 三. Managing Da