某保 Oracle 数据库备份恢复测试

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 一、备份原库,将备份的文件拷贝到单实例的相同目录backup as compressed backupset database plus archivelog format '/u01/app/oracle/backup_db/full_%d_%s_%p_%u.
一、备份原库,将备份的文件拷贝到单实例的相同目录
backup as compressed backupset database plus archivelog format '/u01/app/oracle/backup_db/full_%d_%s_%p_%u.%T';
run{
    allocate channel d1 type disk maxpiecesize=20G;
allocate channel d2 type disk maxpiecesize=20G;
allocate channel d3 type disk maxpiecesize=20G;
allocate channel d4 type disk maxpiecesize=20G;
backup database format '/u01/app/dump/qmcb_bak/db_%U_%T' include current controlfile;
sql 'alter system archive log current';
backup archivelog like '/u01/app/archive_log/%' format  '/u01/app/dump/qmcb_bak/arch_%U_%T';
backup spfile format '/u01/app/dump/qmcb_bak/spfile_%U_%T';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
select sid,spid,client_info from v$process p,v$session s where p.addr=s.paddr and client_info like '%rman%';
-- delete input 从 log_archive_Dest_n 位置删除日志
-- delete input 备份后只删除用于备份的归档日志文件的那个复制的输入对象
scp * oracle@192.168.93.222:/u01/app/oracle/backup_db/

二、修改单实例的参数文件
create pfile='/u01/app/oracle/backup_db/initorcl.ora' from spfile;
vi initorcl.ora
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.dbf','/u01/app/oracle/oradata/orcl/control02.dbf'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=1000
*.log_archive_dest_1='location=/u01/app/archive_log'
*.log_archive_format='%t_%s_%r.dbf'
*.max_dump_file_size='200m'
*.open_cursors=300
*.pga_aggregate_target=2147483648
*.processes=1000
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_limit=TRUE
*.sessions=1250
*.sga_target=3221225472
*.timed_statistics=TRUE
*.undo_tablespace='UNDOTBS2'
scp initorcl.ora oracle@192.168.100.199:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/ 
用传过来的pfile生成spfile文件
SQL> create spfile from pfile='/u01/app/oracle/backup_db/initorcl1.ora';
SQL> startup nomount;

三、恢复控制文件
rman target /
restore controlfile from '/u01/app/dump/qmcb_bak/control_c-1365404862-20191226-00.BKU';
alter database mount;
检查并标记控制文件中存在但是实际已经不存在的备份文件。
RMAN>crosscheck backup;
清理控制文件中存在但是实际已经不存在的备份文件。
RMAN>delete noprompt expired backup;
将备份注册到rman,如果备份及路径一致则不需要注册。
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/ORCL_125_1_3tt920g8.20180727';
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/ORCL_127_1_3vt920i4.20180727';
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/db_ORCL_129_1_41t9224q.20180727';
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/44t923ek_1_1';
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/c-1510034848-20180727-03';

catalog backuppiece '/u01/app/dump/qmcb_bak/arch_q4ukcv45_1_1_20191226';

四、还原数据文件,需要指定scn号,可以list backup查看,需要写到你能恢复到的那个时间点,SCN 为最新的SCN号。
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/ssd/oradata/orcl/system01.dbf
/u01/ssd/oradata/orcl/sysaux01.dbf
/u01/ssd/oradata/orcl/zabbix01.dbf
/u01/ssd/oradata/orcl/users01.dbf
/u01/ssd/oradata/orcl/data01.dbf
/u01/ssd/oradata/orcl/data02.dbf
/u01/photo/oradata/UNDOTBS2.dbf
/u01/ssd/oradata/orcl/RKXX_PHOTO01.dbf
/u01/ssd/oradata/orcl/users11.dbf
/u01/ssd/oradata/orcl/users12.dbf
/u01/ssd/oradata/orcl/users02.dbf
/u01/ssd/oradata/orcl/users03.dbf
/u01/ssd/oradata/orcl/users13.dbf
/u01/ssd/oradata/orcl/users14.dbf
/u01/ssd/oradata/orcl/users15.dbf
/u01/ssd/oradata/orcl/users04.dbf
/u01/ssd/oradata/orcl/users05.dbf
/u01/ssd/oradata/orcl/users16.dbf
/u01/ssd/oradata/orcl/users17.dbf
/u01/ssd/oradata/orcl/users18.dbf
/u01/photo/oradata/data03.dbf
/u01/photo/oradata/data04.dbf
/u01/photo/oradata/data05.dbf
/u01/photo/oradata/data06.dbf
/u01/photo/oradata/data07.dbf
/u01/photo/oradata/data08.dbf
/u01/ssd/oradata/orcl/users06.dbf
/u01/ssd/oradata/orcl/users07dbf
/u01/ssd/oradata/orcl/users08dbf
/u01/ssd/oradata/orcl/users09.dbf
/u01/ssd/oradata/orcl/users10.dbf

RMAN> list backup of archivelog all;
根据备份信息,恢复数据文件及数据库并同步控制文件信息
RUN { 
    allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
set until scn 16708288579293;
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/system01.dbf' to '/u01/app/oracle/oradata/orcl/system01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/sysaux01.dbf' to '/u01/app/oracle/oradata/orcl/sysaux01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/zabbix01.dbf' to '/u01/app/oracle/oradata/orcl/zabbix01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users01.dbf' to '/u01/app/oracle/oradata/orcl/users01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/data01.dbf' to '/u01/app/oracle/oradata/orcl/data01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/data02.dbf' to '/u01/app/oracle/oradata/orcl/data02.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/UNDOTBS2.dbf' to '/u01/app/oracle/oradata/orcl/UNDOTBS2.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/RKXX_PHOTO01.dbf' to '/u01/app/oracle/oradata/orcl/RKXX_PHOTO01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users11.dbf' to '/u01/app/oracle/oradata/orcl/users11.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users12.dbf' to '/u01/app/oracle/oradata/orcl/users12.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users02.dbf' to '/u01/app/oracle/oradata/orcl/users02.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users03.dbf' to '/u01/app/oracle/oradata/orcl/users03.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users13.dbf' to '/u01/app/oracle/oradata/orcl/users13.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users14.dbf' to '/u01/app/oracle/oradata/orcl/users14.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users15.dbf' to '/u01/app/oracle/oradata/orcl/users15.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users04.dbf' to '/u01/app/oracle/oradata/orcl/users04.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users05.dbf' to '/u01/app/oracle/oradata/orcl/users05.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users16.dbf' to '/u01/app/oracle/oradata/orcl/users16.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users17.dbf' to '/u01/app/oracle/oradata/orcl/users17.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users18.dbf' to '/u01/app/oracle/oradata/orcl/users18.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data03.dbf' to '/u01/app/oracle/oradata/orcl/data03.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data04.dbf' to '/u01/app/oracle/oradata/orcl/data04.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data05.dbf' to '/u01/app/oracle/oradata/orcl/data05.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data06.dbf' to '/u01/app/oracle/oradata/orcl/data06.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data07.dbf' to '/u01/app/oracle/oradata/orcl/data07.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data08.dbf' to '/u01/app/oracle/oradata/orcl/data08.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users06.dbf' to '/u01/app/oracle/oradata/orcl/users06.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users07dbf' to '/u01/app/oracle/oradata/orcl/users07.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users08dbf' to '/u01/app/oracle/oradata/orcl/users08.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users09.dbf' to '/u01/app/oracle/oradata/orcl/users09.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users10.dbf' to '/u01/app/oracle/oradata/orcl/users10.dbf'; 
RESTORE DATABASE; 
SWITCH DATAFILE ALL;
recover database;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 110875 and starting SCN of 16708288579684
recover database until scn 16708288579684;

五、查看日志文件修改日志文件的路径
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/ssd/oradata/orcl/redo03.log
/u01/ssd/oradata/orcl/redo02.log
/u01/ssd/oradata/orcl/redo01.log

alter database rename file '/u01/ssd/oradata/orcl/redo03.log' to '/u01/app/oracle/oradata/orcl/redo03.log';
alter database rename file '/u01/ssd/oradata/orcl/redo02.log' to '/u01/app/oracle/oradata/orcl/redo02.log';
alter database rename file '/u01/ssd/oradata/orcl/redo01.log' to '/u01/app/oracle/oradata/orcl/redo01.log';

六、打开数据库,完成续操作
alter database open resetlogs;
查看redo log 信息,并删除无效日志组
select THREAD#, STATUS, ENABLED from v$thread;
   THREAD# STATUS             ENABLED
---------- ------------------ ------------------------
         1 OPEN               PUBLIC
         2 CLOSED             PUBLIC
select group# from v$log where THREAD#=2;    
    GROUP#
----------
         4
         5
         6
SQL> alter database disable thread 2;
SQL> alter database drop logfile group 4;
SQL> alter database drop logfile group 5;
SQL> alter database drop logfile group 6;

SQL> select THREAD#, STATUS, ENABLED from v$thread;
   THREAD# STATUS ENABLED
---------- ------ --------
         1 OPEN   PUBLIC
 
查看undo表空间,并删除节点2(在此不使用)的undo表空间
SQL> show parameter undo;
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS1

SQL> select tablespace_name from dba_tablespaces where contents='UNDO';
TABLESPACE_NAME
------------------------------
UNDOTBS1
UNDOTBS2
SQL> drop tablespace UNDOTBS2 including contents and datafiles;

SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/ORCL/datafile/o1_mf_temp_cr602c5z_.tmp

SQL> select tablespace_name from dba_tablespaces where contents='TEMPORARY';
TABLESPACE_NAME
------------------------------
TEMP
SQL> create temporary tablespace TEMP1 tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf' size 10G autoextend on maxsize unlimited;
SQL> alter database default temporary tablespace TEMP1;
SQL> drop tablespace TEMP including contents and datafiles;

查看监听状态并配置,编辑tnsname.ora文件。

创建密码文件,注意密码文件的位置
$ orapwd file=orapworcl password=oracle123456 entries=5 force=y

目录
相关文章
|
1月前
|
存储 Oracle 关系型数据库
Oracle数据库的应用场景有哪些?
【10月更文挑战第15天】Oracle数据库的应用场景有哪些?
162 64
|
22天前
|
SQL Oracle 关系型数据库
Oracle数据库优化方法
【10月更文挑战第25天】Oracle数据库优化方法
29 7
|
22天前
|
Oracle 关系型数据库 数据库
oracle数据库技巧
【10月更文挑战第25天】oracle数据库技巧
25 6
|
22天前
|
存储 Oracle 关系型数据库
Oracle数据库优化策略
【10月更文挑战第25天】Oracle数据库优化策略
20 5
|
29天前
|
存储 Oracle 关系型数据库
数据库数据恢复—Oracle ASM磁盘组故障数据恢复案例
Oracle数据库数据恢复环境&故障: Oracle ASM磁盘组由4块磁盘组成。Oracle ASM磁盘组掉线 ,ASM实例不能mount。 Oracle数据库故障分析&恢复方案: 数据库数据恢复工程师对组成ASM磁盘组的磁盘进行分析。对ASM元数据进行分析发现ASM存储元数据损坏,导致磁盘组无法挂载。
|
1月前
|
监控 Oracle 关系型数据库
Oracle数据库性能优化
【10月更文挑战第16天】Oracle数据库性能优化是
30 1
|
1月前
|
存储 Oracle 关系型数据库
【数据库-Oracle】《Oracle 数据库探秘:基础知识点全攻略》
《Oracle 数据库探秘:基础知识点全攻略》深入介绍 Oracle 数据库的基础知识点,包括数据类型、表结构、查询语句等。通过详细讲解、代码示例和流程图,帮助读者快速掌握 Oracle 数据库的基本操作,为数据库开发和管理打下坚实基础。
38 0
|
3月前
|
监控 Oracle 关系型数据库
"深度剖析:Oracle SGA大小调整策略——从组件解析到动态优化,打造高效数据库性能"
【8月更文挑战第9天】在Oracle数据库性能优化中,系统全局区(SGA)的大小调整至关重要。SGA作为一组共享内存区域,直接影响数据库处理能力和响应速度。本文通过问答形式介绍SGA调整策略:包括SGA的组成(如数据缓冲区、共享池等),如何根据负载与物理内存确定初始大小,手动调整SGA的方法(如使用`ALTER SYSTEM`命令),以及利用自动内存管理(AMM)特性实现智能调整。调整过程中需注意监控与测试,确保稳定性和性能。
301 2
|
4月前
|
存储 缓存 Oracle
Oracle数据库可扩展性和性能
【7月更文挑战第6天】
85 7
|
存储 SQL 负载均衡
达梦数据库与Oracle数据库:功能、性能和适用场景对比
数据库在现代信息技术领域中扮演着至关重要的角色。在企业级应用中,选择正确的数据库管理系统对于数据存储、处理和查询效率至关重要。本文将对比两个备受关注的数据库管理系统——达梦数据库和Oracle数据库,从功能、性能和适用场景等方面进行深入探讨,以帮助读者在选择合适数据库时做出明智的决策。
2807 1

推荐镜像

更多
下一篇
无影云桌面