*说明:noarchivelog模式数据库只能执行一致性的增量备份,所以备份时需要关闭数据库。archivelog模式则数据库开关都可以进行备份。
一、NOARCHIVELOG模式
介质故障时通过RMAN执行恢复,只需要执行RESTORE命令即可将数据库文件修复到正确的位置,不需要recover。
- 使用sysdba权限的账户查询数据库模式
- 进入RMAN,将数据库置于mount模式
[oracle@villainc db01]$ rman target / nocatalog
RMAN> shutdown immediate
RMAN> startup mount
- 备份整个数据库
RMAN>run{
2>allocate channel ch_1 type disk;
3>backup database
4>format '/home/oracle/work/db/datbak/oradb_%Y_%M_%D_%U.bak';
5>}
- 恢复应用场景举例(数据文件丢失)
RMAN>startup mount
RMAN>run{
2>allocate channel ch_1 type disk;
3>restore database;
4>}
- 恢复完成后打开数据库即可。
二、ARCHIVELOG模式
RESTORE和RECOVER都要使用。区别与NOARCHIVELOG模式的是,恢复时还需要将归档重做日志文件的内容应用到数据文件上。
- 同上查询数据库日志模式
- 进入RMAN执行备份
RMAN>run{
2>allocate channel ch_1 type disk;
3>allocate channel ch_2 type disk;
4>backup tablespace users
5>format '/home/oracle/work/db/datbak/users_tablespace.bak';
6>}
- 进入RMAN,启动数据库到mount,执行恢复
RMAN>run{
2>allocate channel ch_1 type disk;
3>restore tablespace users;
4>recover tablespace users;
5>}
- 最后打开数据库就行
修复指令介绍(restore)
1.restore tablespace:修复表空间
2.restore database:
3.restore datafile
4.restore controlfile to:将控制文件修复到指定的目录
5.restore archivelog all:全部的归档日志复制到指定的目录,以便后续的recover命令对数据库实施修复
恢复指令(recover)
1.recover database:恢复整个数据库
2.recover datafile
3.recover tablespace