RMAN恢复脚本总结

2024年 3月 21日 84.8k 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';

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论