oracle rman在线备份,Oracle的RMAN备份与恢复脚本
Oracle的RMAN備份與恢復(fù)腳本
一、備份方案:
采用多級(jí)備份是為了減少了恢復(fù)所需要的時(shí)間和減少每天備份所需要的時(shí)間,而又保證系統(tǒng)有很好的恢復(fù)性。
以下是一種建議的方案:
每半年做一個(gè)數(shù)據(jù)庫(kù)的全備份(包含只讀表空間)
每個(gè)月做一次零級(jí)備份(不包含只讀表空間)
每個(gè)星期做一次一級(jí)備份
每天做一個(gè)二級(jí)備份
任何表空間改成只讀狀態(tài)后做一個(gè)該表空間的備份。
當(dāng)需要時(shí)(如四個(gè)小時(shí)歸檔文件系統(tǒng)就要接近滿(mǎn)了)備份歸檔文件
1、數(shù)據(jù)庫(kù)全備份腳本 :
run {
allocate channel c1 type disk;
backup full? tag 'dbfull' format '/opt/backup/full_%d_%u' (database include current controlfile);
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
2、零級(jí)備份 :
run {
allocate channel c1 type disk;
backup incremental level 0 filesperset 5 tag 'dbL0' format '/opt/backup/ora_0_%d_%u' (database include current controlfile);
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
3、一級(jí)備份 :
run {
allocate channel c1 type disk;
backup incremental level 1 filesperset 5 tag 'dbL1' format '/opt/backup/ora_0_%d_%u' (database include current controlfile);
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
4、二級(jí)備份 :
run {
allocate channel c1 type disk;
backup incremental level 2 filesperset 5 tag 'dbL2' format '/opt/backup/ora_0_%d_%u' (database include current controlfile);
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
5、表空間備份 腳本(以u(píng)sers表空間為例):
run {
allocate channel c1 type disk;
backup? tag 'tsusers' format '/opt/backup/ora_0_%d_%u' tablespace users;
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
6、歸檔文件備份 腳本:
run {
allocate channel c1 type disk;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
二、RMAN恢復(fù)案例
1 、丟失全部數(shù)據(jù)文件,控制文件、日志文件必須存在
模擬介質(zhì)損壞:刪除所有dbf文件
啟動(dòng)數(shù)據(jù)庫(kù):startup mount
恢復(fù)語(yǔ)句:
run{
allocate channel c1 type disk;
restore database;
recover database;
sql 'alter database open';
release channel c1;
}
注意:Oracle永遠(yuǎn)不會(huì)備份使用臨時(shí)文件的TEMPORARY表空間,因?yàn)榕R時(shí)表空間包含的只是暫時(shí)
性的數(shù)據(jù),根本不必還原。不過(guò)在還原后數(shù)據(jù)字典中還是有臨時(shí)表空間的相關(guān)信息,你只要
簡(jiǎn)單的重建一個(gè)臨時(shí)表空間,設(shè)置其為缺省臨時(shí)表空間,再把以前的臨時(shí)表空間刪除即可。
SQL> create temporary tablespace temp2 tempfile 'd:oracleoradataoradbtemp02.dbf' size 100M;
SQL> alter database default temporary tablespace temp2;
SQL> drop tablespace temp including contents and datafiles;
2、丟失非系統(tǒng)數(shù)據(jù)文件恢復(fù)
模擬介質(zhì)損壞:刪除users01.dbf文件
啟動(dòng)數(shù)據(jù)庫(kù):startup mount
恢復(fù)語(yǔ)句:
run {
allocate channel c1 type disk;
sql 'alter tablespace users offline';
restore tablespace users;
recover tablespace users;
sql 'alter tablespace users online';
release channel c1;
}
3、 丟失全部數(shù)據(jù)文件、控制文件、日志文件恢復(fù)
注意:在備份時(shí)配置了configure controlfile autobackup on;
[oracle@Linux1 ?rman_backup]$ rman target /
RMAN>? set DBID=285819149
RMAN>? restore controlfile from autobackup(也可以:restore controlfile from ‘file name’ );
啟動(dòng)數(shù)據(jù)庫(kù):startup mount
恢復(fù)語(yǔ)句:
run{
allocate channel c1 type disk;
restore database;
recover database;
sql 'alter database open resetlogs';
release channel c1;
}
4、不完全恢復(fù)
A、基于時(shí)間點(diǎn)的不完全恢復(fù):
RUN {
ALLOCATE CHANNEL c1 TYPE DISK;
SET UNTIL TIME = '2002-12-09:11:44:00';
RESTORE DATABASE;
RECOVER DATABASE;
sql'ALTER DATABASE OPEN RESESTLOGS';
RELEASE CHANNEL 1;
}
B、基于日志序列的不完全恢復(fù):
RUN {
ALLOCATE CHANNEL c1 TYPE DISK;
SET UNTIL SEQUENCE 120 THREAD 1;
RESTORE DATABASE;
RECOVER DATABASE; # recovers through log 119
sql'ALTER DATABASE OPEN RESESTLOGS';
RELEASE CHANNEL 1;
}
C、基于SCN的不完全恢復(fù):
RUN {
ALLOCATE CHANNEL c1 TYPE DISK;
SET UNTIL SCN=100145;
RESTORE DATABASE;
RECOVER DATABASE;
sql'ALTER DATABASE OPEN RESESTLOGS';
RELEASE CHANNEL 1;
}
D、基于cancel的不完全恢復(fù):
RUN {
ALLOCATE CHANNEL c1 TYPE DISK;
RESTORE DATABASE;
RECOVER DATABASE UNTIL CANCEL;
SQL'ALTER DATABASE OPEN RESESTLOGS';
RELEASE CHANNEL 1;
}
三、維護(hù)RMAN RMAN的維護(hù)主要分為幾個(gè)方面
1、? 查看RMAN的信息
檢查現(xiàn)有備份
RMAN>list backup
列出過(guò)期備份
RMAN>report obsolete
刪除過(guò)期的備份
RMAN>allocate channel for maintenance type disk;
RMAN>change backupset id delete;
RMAN>release channel;
刪除所有過(guò)期的備份
RMAN>delete obsolete;
2、? 同步或重置RMAN
如果目標(biāo)數(shù)據(jù)庫(kù)物理對(duì)象發(fā)生了變化,如添加了一個(gè)數(shù)據(jù)文件,需要用如下命令同步:
RMAN>resync catalog;
如果目標(biāo)數(shù)據(jù)庫(kù)reset了數(shù)據(jù)庫(kù),需要用如下命令同步
RMAN>reset database;
當(dāng)手工刪除了數(shù)據(jù)庫(kù)的歸檔文件后,要執(zhí)行以下腳本同步
RMAN>allocate channel for maintenance type disk;
RMAN> change archivelog all crosscheck;
RMAN>release channel;
當(dāng)手工刪除了數(shù)據(jù)庫(kù)的RMAN備份后,要執(zhí)行以下腳本來(lái)同步
RMAN>allocate channel for maintenance type disk;
RMAN>crosscheck backup;
RMAN>delete expired backup;
RMAN>release channel;
轉(zhuǎn)載于:https://my.oschina.net/kivensoft/blog/549373
標(biāo)簽:備份,c1,Oracle,RMAN,backup,_%,channel
來(lái)源: https://blog.csdn.net/weixin_33955681/article/details/92058669
總結(jié)
以上是生活随笔為你收集整理的oracle rman在线备份,Oracle的RMAN备份与恢复脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 单片机C语言应用100例
- 下一篇: iOS AVPlayer 使用总结