创建RMAN备份 恢复目录数据库

时间:2022-04-25 10:14:20

这是前段时间给客户做的RMAN备份策略,今天有时间整理出来,希望对大家有些帮助,如有不对的地方欢迎大家给予指点,谢谢!
 
 
 
创建成恢复目录数据库

如果不是在本地配置RMAN 恢复目录,
 
在一台WINDOW2000电脑上安装ORACLE数据库,最好保证数据库版本与目标数据库的版本想同。
 
建立RMAN 数据库用户及表空间:
 
RECOVER CATALOG 表空间(cattbs):1G
系统表空间:       100M
UNDO表空间:     100M
临时表空间(TEMP):        100M
 
用以下命令创建RMAN 用户并授予权限:
 
  Create user rman  identified  rman   default tablespace cattbs  temporary tablespace temp;
 
 
授予权限:
     Grant connect, resource to rman;
     Grant recovery_catalog_owner to rman
 
 创建恢复目录:
 
进入RMN  如果恢复目录与目标数据库不在同一台机子上,用以下:
  
 
Rman catalog   rman/rman@192.168.100.144.
      
Rman> create catalog
 
C:/rman target sys/a123456@192.168.100.2 catalog rman /rman
Rman> register database;
 
 
 
如果想重新注册,查询数 据字典DB 得到DB_KEY与DB_ID  执行DBMS_RCVAT.UNREGISTERDATABASE 命令取消注册。重新注册。
 
Sql> conn rman/rman
 
Sql> select * from db;
 
   
Sql> exec dbms_rcvcat.unregisterdatabase(DB_KEY,DB_ID);
 
 
 
Rman> resync catalog;
 
每半年做一个数据库的全备份(包含只读表空间)
每个月做一次零级备份(不包含只读表空间)
每个星期做一次一级备份
每天做一个二级备份
 
 
数据库全备份脚本:
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup full  tag 'dbfull' format '/backup/ncfc/full%d_%p_%t' database ;
sql 'alter system archive log current' ;
backup format /backup/ncfc/dbL0/dbL0%d_%p_%t.arc' filesperset 5 archivelog all delete input;
release channel c1;
release channel c2;
release channel c3;
}
 
 
 
零级备份脚本(只读表空间除外)
run {
allocate channel c1 type disk maxpiecesize =20G;
allocate channel c2 type disk maxpiecesize =20G;
allocate channel c3 type disk maxpiecesize =20G;
backup incremental level 0 filesperset 10 tag 'dbL0' format '/backup/ncfc/dbL0/dbL0%u_%p_%c ' database skip readonly;
sql 'alter system archive log current' ;
backup format '/backup/ncfc/dbL0/arch%u_%p_%c.arc' filesperset 5 archivelog from time "sysdate-1" all;
release channel c1;
release channel c2;
release channel c3;
}
 
一级备份脚本
run {
allocate channel c1 type disk maxpiecesize =20G;
allocate channel c2 type disk maxpiecesize =20G;
allocate channel c3 type disk maxpiecesize =20G;
backup incremental level 1 filesperset 5 tag 'dbL1' format '/backup/ncfc/dbL1/dbL1%d_%p_%t ' ddatabase skip readonly;
sql 'alter system archive log current' ;
backup format '/backup/ncfc/dbL1/dbL1%d_%p_%t.arc' filesperset 5  archivelog from time "sysdate-1" all;
release channel c1;
release channel c2;
release channel c3;
}
 
二级备份脚本
run {
allocate channel c1 type disk maxpiecesize =20G;
allocate channel c2 type disk maxpiecesize =20G;
allocate channel c3 type disk maxpiecesize =20G;
backup incremental level 2 filesperset 5 tag 'dbL2' format '/backup/ncfc/dbL2/dbL2%u_%p_%c' ddatabase skip readonly;
sql 'alter system archive log current' ;
backup format '/backup/ncfc/dbL2/dbL2%d_%p_%t.arc' filesperset 5 archivelog from time "sysdate-1" all;
release channel c1;
release channel c2;
release channel c3;
}
 
 
归档文件备份脚本
run {
    allocate channel dev1 type disk maxpiecesize =20G;
    allocate channel dev2 type disk maxpiecesize =20G;
    allocate channel dev3 type disk maxpiecesize =20G;
    sql 'alter system archive log current' ;
    backup  format '/backup/ncfc/arc/arch%u_%p_%c ' archivelog from time "sysdate-1" all;
    release channel dev1;
    release channel dev2;
    release channel dev3;
}
 
 
表空间备份脚本(以users表空间为例)
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup  tag 'tabsp' format '/backup/ncfc/tabsp/tabsp%u_%p_%c' tablespace users;
sql 'alter system archive log current' ;
backup format 'e:\oradata\%d_%p_%t.arc' filesperset 5 archivelog all delete input;
release channel c1;
release channel c2;
release channel c3;
}
 
 
则每天所需要备份的数据量只有一天的改变量。而做恢复时最多只要恢复当月的一个零级备份+三个一级备份+6个二级备份+当天的归档文件。如果不能接受这样的恢复时间,就只能够减少零级备份之间的时间间隔(如可以每个星期做一个零级备份,这样恢复时最多只需要恢复一个星期的数据量)。
 
备份CATALOG数据库(数据库逻辑输出)
exp pafile=exp.dat
其中exp.dat如下
userid=rman/rman
file=rmanexp.dmp