进入 rman 工具
rman target /
查看 rman 配置
rman> show all;
修改rman 配置
数据库全备
rman> run {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level 0 database format '/home/oracle/backup/full_%d_%s_%t.bak';
sql 'alter system archive log current';
crosscheck archivelog all;
backup archivelog all format '/home/oracle/backup/archlog_%d_%s_%t.bak' delete input;
backup spfile format '/home/oracle/backup/spfile_%d_%s_%t.bak';
backup current controlfile format '/home/oracle/backup/controlfile_%d_%s_%t.bak';
delete noprompt expired backup;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
数据库增量备份
rman> run {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level 1 database format '/home/oracle/backup/db_incre_%d_%s_%t.bak';
sql 'alter system archive log current';
crosscheck archivelog all;
backup archivelog all format '/home/oracle/backup/archlog_incre_%d_%s_%t.bak' delete input;
backup spfile format '/home/oracle/backup/spfile_%d_%s_%t.bak';
backup current controlfile format '/home/oracle/backup/controlfile_%d_%s_%t.bak';
delete noprompt expired backup;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
RMAN数据库恢复
1. 数据文件丢失恢复
-
找到丢失文件的数据文件号
- 根据文件号查找数据备份列表 rman> list backup of datafile 4;
- 将数据文件离线 rman> sql 'alter database datafile 4 offline'
- 从备份文件将数据文件拷贝回来 rman> restore datafile 4;
- 数据文件恢复到最新 rman> recover datafile 4;
- 将数据文件上线rman> sql 'alter database datafile 4 online';
全部脚本如下:
rman> run {
sql 'alter database datafile 4 offline';
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online'
}
2. 全部数据文件丢失恢复
sql>shutdown immediate;
sql>startup mount;
rman> run {
restore database;
recover database;
sql 'alter database open';
}
3. 控制文件、数据文件丢失恢复
- sql> startup nomount
- 恢复控制文件rman> restore controlfile from '/home/oracle/backup/c_ORCL_*_*'
- 恢复数据文件rman> restore database;
- 介质恢复rman> run {
set until sequenct 63; //这里的63是存在的归档日志的最大的序列号
recover database;
}
5. 打开数据库,resetlogs会将redo日志序列号恢复从0开始,这样会导致之前的所有备份不再可用 ,可把之前的备份删除 rman> sql ‘alter database open resetlogs';
6. 把之前的备份删除 rman> delete backup;
7. 再给数据库做全备,参考上面RMAN数据库全备脚本
4. 数据库坏块恢复
- 通过rman检查数据库上是否有坏块 rman> backup check logical validate database;
- 查看数据库存在多少坏块 sql> select * from v$database_block_corruption;
- 恢复一个坏块 rman> blockrecover datafile 4 block 20635;
- 如果有多个坏块 rman> blockrecover corruption list;