RMAN恢复脚本总结

2024年 3月 21日 33.3k 0

注册备份集或者目录
catalog backuppiece '绝对路径文件';
catalog start with '''

run
{
set newname for datafile 1 to '新位置';
set newname for datafile 2 to '新位置';
set newname for datafile 3 to '新位置';
set newname for datafile 4 to '新位置';
set newname for datafile 5 to '新位置';
set newname for datafile 6 to '新位置';
RESOTRE DATABASE;
SWITCH DATAFILE ALL;
RECOVER DATABASE;}

设置控制文件
set controlfile autobackup format for device type disk to 'f:/backup/%f';

块恢复
blockrecover datafile 6 block 33;

rman target /
startup nomount;
restore controlfile from autobackup;
alter database mount;
restore database;
exit
sqlplus / as sysdba
alter system set "_ALLOW_RESETLOGS_CORRUPTION"=true scope=spfile;
alter system set "_ALLOW_RESETLOGS_CORRUPTION"=true scope=spfile;---允许错误
shutdown immediate;
startup mount;
recover database;
出现错误不用管它
alter database open resetlogs;
---redo 全部丢失

--set until
run
{
sql 'alter session set nls_date_format= "YYYY-MM-DD HH24:MI:SS"';
set until time '2012-11-19 15:40:40';
restore database;
recover database;
}
run
{
sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';
set until time '2007-08-21 23:59:59';
}
run
{
SET UNTIL TIME="TO_DATE('2007-05-21 15:08:01','yyyy-mm-dd hh24:mi:ss')";
}
run
{
SET UNTIL TIME "TO_DATE('2007-05-21 15:08:01','yyyy-mm-dd hh24:mi:ss')";
}

run
{
allocate channel c1 ;
recover tablespace user01 until time "to_timestamp('2012-10-8 18:44:00','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/oracle/';
release channel c1;
}
recover tablespace user01 until time "to_timestamp('2012-10-8 20:17:02','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/oracle';---tstprt

基于时间点的恢复:
run{
set until time "to_date(07/01/02 15:00:00','mm/dd/yy hh24:mi:ss')";
restore database;
recover database;
alter database open resetlogs;
}
sql 'alter session set nls_date_format= "YYYY-MM-DD HH24:MI:SS"';
ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
1.startup mount
2.restore database until time "to_date('2012-11-19 16:12:00','YYYY-MM-DD HH24:MI:SS')";
3.recover database until time "to_date('2012-10-8 16:12:00','YYYY-MM-DD HH24:MI:SS')";
4.alter database open resetlogs;

如果有open resetlogs,都是不完整恢复.

基于 SCN的恢复:
1.startup mount;
2.restore database until scn 10000;
3.recover database until scn 10000;
4.alter database open resetlogs;

基于日志序列的恢复:
1.startup mount;
2.restore database until SEQUENCE 100 thread 1; //100是日志序列
3.recover database until SEQUENCE 100 thread 1;
4.alter database open resetlogs;

日志序列查看命令: SQL>select * from v$log 其中有一个sequence字段.resetlogs就会把sequence 置为1
--不完全恢复

set controlfile autobackup format for device type disk to 'f:/backup/%f';--设置控制文件恢复地址
Restore controlfile from autobackup until time "to_date('2010-6-27 13:25:00','yyyy-mm-dd hh24:mi:ss')";
恢复控制文件到较早的文件

restore database until time '2012-11-19 15:40:40';

表空间点对点恢复
run
{
allocate channel c1 ;
recover tablespace user01 until time "to_timestamp('2012-10-8 18:44:00','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/oracle/';
release channel c1;
}

recover tablespace user01 until time "to_timestamp('2012-10-8 20:17:02','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/oracle';

本地盘迁移到ASM
sql ‘alter tablespace xff offline’;
backup device type disk as copy datafile 6 format '+DG2';
switch tablepspace xff to copy;
sql 'alter tablespace xff online';

相关文章

pt-kill工具的使用
pt-ioprofile工具包的使用
数据库管理-第216期 Oracle的高可用-01(20240703)
DBMS_REPAIR EXAMPLE SCRIPT WITH PARTITION
数据库事务的四大特性: ACID 
使用BBED修复损坏的SYSTEM文件头

发布评论