rman 备份恢复相关脚本汇总
--backup full database
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
crosscheck archivelog all;
delete noprompt expired archivelog all;
crosscheck backup;
delete noprompt expired backup;
#backup database format '/u03/backup/rmanbk/sfsdb/data/full_%d_%T_%s';
backup as compressed backupset database format '/u03/backup/rmanbk/sfsdb/data/full_%d_%T_%s';
#sql 'alter system archive log current';
backup as compressed backupset filesperset 10 format '/u03/backup/rmanbk/sfsdb/arch/arch_%d_%T_%s' archivelog all;
backup current controlfile format '/u03/backup/rmanbk/sfsdb/ctl/ctl_%d_%T_%s';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
#report obsolete;
#delete noprompt obsolete;
}
--backup archivelog
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate-7';
#sql 'alter system archive log current';
backup as compressed backupset filesperset 10 format '/u03/backup/rmanbk/sfsdb/arch/arch_%d_%T_%s' archivelog all;
backup current controlfile format '/u03/backup/rmanbk/sfsdb/ctl/ctl_%d_%T_%s';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
#report obsolete;
#delete noprompt obsolete;
}
--create standby controlfile three methods
alter database create standby controlfile as 'path'
backup current controlfile for standby format='path'
backup as copy current controlfile for standby format='path'
--backup current controlfile three methods
backup current controlfile format='path'
backup as copy current controlfile format='path'
alter database backup controlfile to trace
--recover full database
STARTUP FORCE MOUNT;
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
RESTORE DATABASE;
RECOVER DATABASE;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
ALTER DATABASE OPEN;
--recover tablespace
SQL 'ALTER TABLESPACE users OFFLINE';
RESTORE TABLESPACE users;
RECOVER TABLESPACE users;
SQL 'ALTER TABLESPACE users ONLINE;
--recover datafile
SQL 'ALTER DATABASE DATAFILE 7 OFFLINE';
RESTORE DATAFILE 7;
RECOVER DATAFILE 7;
SQL 'ALTER DATABASE DATAFILE 7 ONLINE';
--recover data block
BLOCKRECOVER CORRUPTION LIST;
BLOCKRECOVER DATAFILE 7 BLOCK 233, 235 DATAFILE 4 BLOCK 101;
--check physical corrupt block
BACKUP VALIDATE DATABASE ARCHIVELOG ALL;
--check logical corrupt block
BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL;
--check corrupt block
select * from v$database_block_corruption;
dbv file=/oradata/orcl/users.dbf blocksize=8192
--repair corrupt block
BLOCKRECOVER CORRUPTION LIST;
--skip corrupt block
BEGIN
DBMS_REPAIR.SKIP_CORRUPT_BLOCKS (
SCHEMA_NAME => 'SYS',
OBJECT_NAME => 'TB_OBJ',
OBJECT_TYPE => dbms_repair.table_object,
FLAGS => dbms_repair.skip_flag);
END;
/
--newname file
SET NEWNAME FOR DATABASE TO '/oradata1/%b'; --starting from 11.2
SET NEWNAME FOR DATABASE TO '+DATA'; --starting from 11.2
SET NEWNAME FOR DATAFILE 1 TO 'NEW';
SET NEWNAME FOR DATAFILE 1 TO '+DATA';
SWITCH DATAFILE ALL
SWITCH TEMPFILE ALL
SWITCH DATAFILE 1
SWITCH DATABASE TO COPY
SWITCH TABLESPACE NAME TO COPY
SWITCH DATAFILE 1 TO COPY
--tablespace point in time recover
recover tablespace tbs1 until time '2015-11-11 15:01:46' auxiliary destination '/u01/orabak/auxiliary'
--starting from 12c
--table or table partition point in time recover
recover table user1.EMPLOYEES
until time '2015-11-11 15:01:46'
auxiliary destination '/u01/orabak/auxiliary'
remap table 'user1'.'EMPLOYEES':'EMPLOYEES_R'
remap tablespace 'TBS01':'TBS02' ;
recover table user1.EMPLOYEES:partition1
until time '2015-11-11 15:01:46'
auxiliary destination '/u01/orabak/auxiliary'
remap table 'user1'.'EMPLOYEES':'partition1':'EMPLOYEES_R'
remap tablespace 'TBS01':'TBS02' ;
recover table tablename
until time '2015-11-11 15:01:46'
auxiliary destination '/u01/orabak/auxiliary'
datapump destination '/tmp'
dumpfile 'expdp.dmp'
notableimport ;
recover table user1.EMPLOYEES of pluggable database pdb1
until time '2015-11-11 15:01:46'
auxiliary destination '/u01/orabak/auxiliary'
remap table 'user1'.'EMPLOYEES':'EMPLOYEES_R'
remap tablespace 'TBS01':'TBS02' ;
--use rman to copy datafile from filesystem to asm
convert datafile '/u01/app/oradata/testdb/example01.dbf','/u01/app/oradata/testdb/example02.dbf'
format '+DATA';
copy datafile '/u01/app/oradata/testdb/example01.dbf' to '+DATA'
convert tablespace example format '+DATA';
--use rman to copy datafile from asm to filesystem
convert tablespace example format '/u01/app/oradata/testdb/example%U.dbf';
copy datafile '+DATA/sfsdb/datafile/soe.279.995903361' to '/tmp/soe01.dbf' ;
convert datafile '+DATA/sfsdb/datafile/soe.279.995903361' format '/tmp/soe02.dbf' ;
本文来自博客园,作者:踏雪无痕2017,转载请注明原文链接:https://www.cnblogs.com/oradba/p/14376233.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)