1.Create catalog
a)Createt tablespace to store catalog’s object ;
{ echo $ORACLE_SID (dgdemo)
create tablespace tbs_rman datafile ‘/u01/oradata/dgdemo/tbs_rman.dbs’ size 300m;
}
-------------如果表空间存在,就执行删除:
Drop tablespace tbs_rman including contents and datafiles;
b)Create rman user & grant privilege to it
{ create user rmanuser identified by rman default tablespace tbs_rman temporary tablespace temp;
grant recovery_catalog_owner to rmanuser; ――查看方法:select * from session_roles;
alter user rmanuser quota unlimited on tbs_rman;—增加 用户 tbs_rman 表空间操作权限;
}
补充: lsnrctl service; 查看目前监听的结果
c)Create catalog on rman
{ rman catalog rmanuser/rman
create catalog tablespace tbs_rman; 创建 catalog表空间
}
2.Register database
$ rman catalog rmanuser/rman
----------只有连接到catalog才可以registerdatabase
RMAN> connect target sys/oracle;
RMAN> register database;
RMAN> List incarnation;
RMAN> report schema;
RMAN> list backup;
RMAN> list copy;
此时才能 Connect target sys/oracle@dgdemo ――连接到target必须用sys用户
3.Backup database using catalog option
备份解说【Full backup;
Incremental backup (0级,1级别,2级) ――增量备份
每种级别均分为Differential (差级增量)& cumulative( 累积增量)
Backup tablespace;
Backup datafile
Backup controlfile & spfile;
Backup archivelog file;
Backup as copy;
】
a)全库备份脚本:
Run{
Allocate channel d1 device type disk; —指定为磁盘备份
Backup as compressed backupset ――指定为压缩备份
Format=’/u01/rmanbk/full_%d_%U’
Tag=’fullbak’
Channel=d1
Database plus archivelog delete input; ―删除已经原备份日志
}
如果出现如下错误:
ORA-19625: error identifying file
/u01/oradata/arch/1_21_656602295.dbf
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
需要进行如下操作:
RMAN> crosscheck copy;
删除备份:
Delete expired copy;
b)全库增量备份(level 0 备份):
Run{
Allocate channel d1 device type disk; —指定为磁盘备份
Backup as compressed backupset ――指定为压缩备份
Incremental level=0
Format=’/u01/rmanbk/inc0_%d_%U’
Tag=’inc0’
Channel=d1
Database;
release channel d1;
}
查看备份情况:
RMAN> list backupset summary;
c)在级别为0的基础上做全库级别为1的差分备份
Run{
Allocate channel d1 device type disk; —指定为磁盘备份
Backup as compressed backupset ――指定为压缩备份
Incremental level=1
–如果再加上cumulative 就是累积备份 不写就是默认为Differential (差级增量)
Format=’/u01/rmanbk/inc1_%d_%U’
Tag=’inc1’
Channel=d1
Database;
release channel d1;
}
RMAN> list backup by file; ――――很好
d)在级别为0的基础上做全库级别为1的累积备份
Run{
Allocate channel d1 device type disk; —指定为磁盘备份
Backup as compressed backupset ――指定为压缩备份
Incremental level=1 cumulative
–如果再加上cumulative 就是累积备份 不写就是默认为Differential (差级增量)
Format=’/u01/rmanbk/cum1_%d_%U’
Tag=’cum1’
Channel=d1
Database;
release channel d1;
}
e)单独表空间备份:
Run{
Allocate channel d1 device type disk; —指定为磁盘备份
Backup as compressed backupset ――指定为压缩备份
Format=’/u01/rmanbk/tbs_%d_%U’
Tag=’tbs’
Channel=d1
Tablespace users,system;
release channel d1;
}
f)单独数据文件备份:
Run{
Allocate channel d1 device type disk;
Backup as compressed backupset
Format=’/u01/rmanbk/df_%d_%U’
Tag=‘datafile’
Channel=d1
datafile 1; ―――1的解释?系统表空间
release channel d1; }
RMAN> list backupset tag=‘DATAFILE’; -----很好
g)Archivelog file 备份:
RMAN> crosscheck copy of archivelog all;
RMAN> crosscheck archivelog all;
RMAN> sql “alter system switch logfile”;------使目标库归档
RMAN> crosscheck copy of archivelog all; —再查看归档日志
脚本:
Run{
Allocate channel d1 device type disk;
Backup as compressed backupset
Format=’/u01/rmanbk/arlog_%d_%U’
Tag=‘archlog’
Channel=d1
archivelog from scn 572185; ----scn号解释见下面
release channel d1; }
scn解释:(数据文件和archivelog关联字段??)
备份archivelog是有原则的,什么样的是需要的,什么样是不需要的,在做系统还原的时候,数据文件被还原了,需要archivelog ,这就需要决定需要那些archivelog?
使用LIST BACKUPSET ; 可以看到每个备份级别的 Ckp SCN如下:
Piece Name: /u01/rmanbk/cum1_DGDEMO_0bjiu4e8_1_1
File LV Type Ckp SCN Ckp Time Name
1 1 Incr 572185 14-JUN-08 /u01/
备份完archivelog后再来通过LIST BACKUPSET ; 看archivelog的 Low SCN 和 Next SCN
Piece Name: /u01/rmanbk/arlog_DGDEMO_0hjiu79m_1_1
List of Archived Logs in backup set 729
Thrd Seq Low SCN Low Time Next SCN Next Time
1 35 566876 14-JUN-08 573357 14-JUN-08
1 36 573357 14-JUN-08 573887 14-JUN-08
h)Backup as copy 原始的
Run{
Allocate channel d1 device type disk;
Backup as copy
Format=’/u01/rmanbk/arlog_%d_%U’
Tag=‘copybak’
Channel=d1
Database;
-------备份整个库(一个文件一个文件的copy),如果是datafile 1,2 只备份指定的数据文件
release channel d1; }
4.Maintenance catalog
环境:
Target db sid =clonedb
Catalog db sid=digoal
Target db sid =clonedb
Catalog db sid=dgdemo
5.RMAN常用命令
List backupset summary;
List backupset by file;;
List backupset ;
Crosscheck backupset;
Crosscheck copy;
delete expired backupset;
change backupset (available, comma, crosscheck, delete……) 修改备份的状态;
valicate backupset key(号) check logical; 检验备份文件是否可用,比crosscheck慢
RMAN 恢复系列:
Uniread rman catalog rmanuser/rman@




