缺少控制文件备份时如何还原数据库 (Doc ID 1438776.1)

How to restore database when controlfile backup missing (Doc ID 1438776.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 9.2.0.1 and later
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Information in this document applies to any platform.
***Checked for relevance on 16-NOV-2015***

GOAL

This article will help in the case when customer have all backup pieces of database except controlfile backup which is mandatory to mount the database and start restore.

当客户拥有数据库的所有备份集(控制文件备份除外)时,本文将有帮助。控制文件备份是安装数据库和开始还原所必需的。

SOLUTION

Here we are giving one test case where we have current database structure and simulate the customer environment where he/she missing controlfile backup

在这里,我们给出一个测试用例,其中我们拥有当前的数据库结构并模拟客户环境中缺少控制文件备份的客户

1. See the current database structure  查看当前的数据库结构

RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema

List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 510 SYSTEM *** +DATA/ora102/datafile/system.257.775126603
2 595 UNDOTBS1 *** +DATA/ora102/datafile/undotbs1.256.775126561
3 250 SYSAUX *** +DATA/ora102/datafile/sysaux.258.775126637
4 28 USERS *** +DATA/ora102/datafile/users.259.775126653
5 50 USERS *** +DATA/ora102/datafile/users.262.776000421

List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 29 TEMP 32767 /u01/app/oracle/oradata/ora102/ORA102/datafile/o1_mf_temp_7lqq1qko_.tmp

RMAN> exit

Recovery Manager complete.

2. Create a dummy instance/ can use existing database to extract datafile 1 from backup piece and restore datafile 1 from backup piece

创建一个虚拟实例/可以使用现有数据库从备份文件中提取数据文件1并从备份文件中恢复数据文件1

SQL> DECLARE
  devtype varchar2(256);
  done boolean;
  BEGIN
  devtype := dbms_backup_restore.DeviceAllocate(type=>null, ident=>‘d1‘);
  dbms_backup_restore.RestoreSetDatafile;
  dbms_backup_restore.RestoreDatafileTo(dfnumber => 1,toname => ‘/u03/datafile1.dbf‘);
  dbms_backup_restore.RestoreBackupPiece(done => done,handle =>‘/u03/backup/2cn5blrn_1_1‘, params => null);
  dbms_backup_restore.DeviceDeallocate;
 END;
/

3. Create controlfile with datafile 1   使用数据文件1创建控制文件

SQL>!cat /u03/1.ctl
CREATE CONTROLFILE REUSE DATABASE "ORA102" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘/u01/app/oracle/oradata/ora102/ORA102/onlinelog/o1_mf_1_7lqq1m62_.log‘ SIZE 50M,
GROUP 2 ‘/u01/app/oracle/oradata/ora102/ORA102/onlinelog/o1_mf_2_7lqq1myr_.log‘ SIZE 50M,
GROUP 3 ‘/u01/app/oracle/oradata/ora102/ORA102/onlinelog/o1_mf_3_7lqq1nr0_.log‘ SIZE 50M
DATAFILE
‘/u03/datafile1.dbf‘
CHARACTER SET WE8ISO8859P1
;
SQL> @/u03/1.ctl

Control file created.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u03/datafile1.dbf

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

4. Catalog all the backup piece Catalog所有备份集

[[email protected] ~]$ rman target /

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 8 11:55:58 2012

Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database: ORA102 (DBID=396070408, not open)

RMAN> catalog start with ‘/u03/backup/‘ noprompt;

using target database control file instead of recovery catalog
searching for all files that match the pattern /u03/backup/

List of Files Unknown to the Database
=====================================
File Name: /u03/backup/28n5bki6_1_1
File Name: /u03/backup/ORA1122-backup-080312.log
File Name: /u03/backup/2dn5blsq_1_1
File Name: /u03/backup/2cn5blrn_1_1
File Name: /u03/backup/ora102-080312.log
File Name: /u03/backup/27n5bkd0_1_1
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u03/backup/2dn5blsq_1_1
File Name: /u03/backup/2cn5blrn_1_1

List of Files Which Where Not Cataloged
=======================================
File Name: /u03/backup/28n5bki6_1_1
RMAN-07518: Reason: Foreign database file DBID: 2353175563 Database Name: ORA1122
File Name: /u03/backup/ORA1122-backup-080312.log
RMAN-07517: Reason: The file header is corrupted
File Name: /u03/backup/ora102-080312.log
RMAN-07517: Reason: The file header is corrupted
File Name: /u03/backup/27n5bkd0_1_1
RMAN-07518: Reason: Foreign database file DBID: 2353175563 Database Name: ORA1122

RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 1.05M DISK 00:00:00 08-MAR-12
BP Key: 1 Status: AVAILABLE Compressed: YES Tag: TAG20120308T101415
Piece Name: /u03/backup/2dn5blsq_1_1
Control File Included: Ckp SCN: 1320981 Ckp time: 08-MAR-12
SPFILE Included: Modification time: 08-MAR-12

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2 Full 107.40M DISK 00:00:00 08-MAR-12
BP Key: 2 Status: AVAILABLE Compressed: YES Tag: TAG20120308T101415
Piece Name: /u03/backup/2cn5blrn_1_1
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1320981 08-MAR-12 +DATA/ora102/datafile/system.257.775126603
2 Full 1320981 08-MAR-12
3 Full 1320981 08-MAR-12
4 Full 1320981 08-MAR-12
5 Full 1320981 08-MAR-12

RMAN>

5. Now restore the datafiles using DBMS_BACKUP_RESTORE package . Please note name of datafiles are not important here we can give any unique name to restore the datafiles

现在,使用 DBMS_BACKUP_RESTORE 包还原数据文件。请注意,数据文件的名称并不重要,我们可以使用任何唯一的名称来恢复数据文件

SQL>  -- use script

DECLARE
  devtype varchar2(256);
  done boolean;
BEGIN
  devtype := dbms_backup_restore.DeviceAllocate(type=>null, ident=>‘d1‘);
  dbms_backup_restore.RestoreSetDatafile;
  dbms_backup_restore.RestoreDatafileTo(dfnumber => 4,toname => ‘/u03/datafile4.dbf‘);
  dbms_backup_restore.RestoreDatafileTo(dfnumber => 2,toname => ‘/u03/datafile2.dbf‘);
  dbms_backup_restore.RestoreDatafileTo(dfnumber => 3,toname => ‘/u03/datafile3.dbf‘);
  dbms_backup_restore.RestoreDatafileTo(dfnumber => 5,toname => ‘/u03/datafile5.dbf‘);
  dbms_backup_restore.RestoreDatafileTo(dfnumber => 1,toname => ‘/u03/datafile1.dbf‘);
  dbms_backup_restore.RestoreBackupPiece(done => done,handle =>‘/u03/backup/2cn5blrn_1_1‘, params => null);
  dbms_backup_restore.DeviceDeallocate;
END;
/

PL/SQL procedure successfully completed.

Metadata will show only datafile 1 . We need to re-create control file with all  relevant restored dataifiles

元数据将仅显示数据文件1。我们需要使用所有相关的已还原数据重新创建控制文件

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/ora102/datafile/system.257.775126603

SQL> shutdown immediate; ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.

Total System Global Area 209715200 bytes
Fixed Size 1272864 bytes
Variable Size 142607328 bytes
Database Buffers 58720256 bytes
Redo Buffers 7114752 bytes
SQL>!cat /u03/1.ctl
CREATE CONTROLFILE REUSE DATABASE "ORA102" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘/u01/app/oracle/oradata/ora102/ORA102/onlinelog/o1_mf_1_7lqq1m62_.log‘ SIZE 50M,
GROUP 2 ‘/u01/app/oracle/oradata/ora102/ORA102/onlinelog/o1_mf_2_7lqq1myr_.log‘ SIZE 50M,
GROUP 3 ‘/u01/app/oracle/oradata/ora102/ORA102/onlinelog/o1_mf_3_7lqq1nr0_.log‘ SIZE 50M
DATAFILE
‘/u03/datafile1.dbf‘,
‘/u03/datafile4.dbf‘,
‘/u03/datafile2.dbf‘,
‘/u03/datafile3.dbf‘,
‘/u03/datafile5.dbf‘
CHARACTER SET WE8ISO8859P1
;

SQL> @/u03/1.ctl

Control file created.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u03/datafile1.dbf
/u03/datafile2.dbf
/u03/datafile3.dbf
/u03/datafile4.dbf
/u03/datafile5.dbf

6. If the backup what we restored is not the cold backup then we need to recover the database,hence, we can catalog the backup pieces which contains archives ,restore archives and then do recovery

如果我们还原的备份不是冷备份,那么我们需要恢复数据库,因此,我们可以对包含归档文件的备份目录进行分类,还原归档文件然后进行恢复

SQL> recover database until cancel;
Media recovery complete.
SQL> alter database open resetlogs;
Database altered.
SQL>

7. Once database in consistent status we can open database with resetlogs option  
  一旦数据库处于一致状态,我们可以使用resetlogs选项打开数据库

SQL>alter database open resetlogs;
Database altered.
SQL>

Note: In case of Multisection backup we need to consider all the backup pieces (all sections) and use function initmsr as below to restore datafile

注意:如果是多部分备份,我们需要考虑所有备份片(所有部分),并使用如下所示的函数initmsr来还原数据文件

DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype := dbms_backup_restore.DeviceAllocate(type=>null, ident=>‘d1‘);
dbms_backup_restore.RestoreSetDatafile;
dbms_backup_restore.initmsr(1,‘/ud1001/PROD/oradata/system01-test.dbf‘);
dbms_backup_restore.RestoreDatafileTo(dfnumber => 1,toname => ‘/ud1001/PROD/oradata/system01-test.dbf‘);
dbms_backup_restore.RestoreBackupPiece(done => done,handle =>‘/backup/Oracle-DB-8-7-2014/db_L0_PROD_e6pf7too_1_1.rman‘, params => null);
dbms_backup_restore.RestoreBackupPiece(done => done,handle =>‘/backup/Oracle-DB-8-7-2014/db_L0_PROD_e6pf7too_2_1.rman‘, params => null);
END;
/

  

原文地址:https://www.cnblogs.com/zylong-sys/p/12006204.html

时间: 2024-10-09 02:05:34

缺少控制文件备份时如何还原数据库 (Doc ID 1438776.1)的相关文章

12.2新特性 使用DBCA duplicate创建物理备用数据库 (Doc ID 2283697.1)

Creating a Physical Standby database using DBCA duplicate (Doc ID 2283697.1) APPLIES TO: Oracle Database Cloud Exadata Service - Version N/A and laterOracle Database - Enterprise Edition - Version 12.2.0.1 to 12.2.0.1 [Release 12.2]Oracle Database Cl

还原数据库备份文件时,关于“System.Data.SqlClient.SqlError:媒体集有2个媒体簇,但只提供了1个。必须提供所有成员”的处理方式

好久没写博客了,最近在做毕设的权限管理模块,今天在还原数据库文件时,遇到了“System.Data.SqlClient.SqlError:媒体集有2个媒体簇,但只提供了1个.必须提供所有成员”这个错误,百度了一下,找到了原因和解决方式. 原因分析:1.备份的时候,旧路径没有删除,我添加了一个新路径,就无意中设置成了两个备份路径,SQL就会根据两个备份路径把备份文件分成两个.2.还原的时候源数据必须把两个备份文件都加载上.3.还原的新路径要手工修改成实际SQL的data文件夹路径.4.如果有同名数

SQL Server 2005还原数据库时出现“不能选择文件或文件组XXX_log用于此操作的解决办法

SQL2005 还原数据库失败,提示如下: SQL Server 2005还原数据库时出现“不能选择文件或文件组XXX_log用于此操作的解决办法 出现错误时操作步骤为:右击数据库--->任务--->还原--->文件和文件组--->源设备(选择备份文件)--->指定备份文件位置--->添加选定文件.在“还原文件和文件组”对话框中点击“确定”按钮,即出现上面显示的错误. 正确的步骤为: 右击数据库--->任务--->还原--->数据库--->源设备

sql server 还原数据库时提示数据库正在使用,无法进行操作的解决方法

这个问题的原因在于有用户连接了当前要做还原的数据库,这里的用户甚至包括当前要做还原的用户.解决办法就是关闭与要还原数据库的所有连接. ①先切换数据库到master数据库.执行语句select * from master..sysprocesses where dbid=db_id( '数据库名称')②然后逐步运行语句 exec kill spid(上一步结果集中的数据), 问题就解决了.哈哈 今天在还原数据库的时候,提示"因为数据库正在使用,所以无法获得对数据库的独占访问权",无论我是

SQL Server 在缺少文件组的情况下如何还原数据库

SQL Server 在缺少文件组的情况下如何还原数据库 一.背景 我有一个A库,由于a,b两张表的数据量比较大,所以对表进行分区:在把A库迁移到一个新的集群上去,我只备份了A库的主分区过去进行还原为B库(主分区的备份还原可参考:SQL Server 维护计划备份主分区 和 主分区备份与还原),为了对a,b表进新的数据,我修改了a,b表名,在B库新建了两张不分区的a,b表: 这样运行都没有什么问题的,但是在一次我分离了数据库B,拷贝了mdf和ldf文件,现在想使用mdf和ldf还原为B库的时候出

在SQL SERVER 2005中还原数据库时出现错误:system.data.sqlclient.sqlerror 媒体集有 2 个媒体簇 但只提供了 1 个。必须提供所有成员。 (microsoft.sqlserver.smo)

问题:在SQL SERVER 2005中还原数据库时出现错误:system.data.sqlclient.sqlerror 媒体集有 2 个媒体簇 但只提供了 1 个.必须提供所有成员. (microsoft.sqlserver.smo) 原因:由于备份时,没有去掉默认的备份路径(C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\backup.bak),而又添加了一个新的路径,结果备份了两份,但它们之间彼此依赖,所以没有办法恢复

SqlServer 2014还原数据库时提示:无法在已有的""上还原文件,请重新发出RESTORE语句,用WITH REPLACE来覆盖原先存在的文件

场景 SQL Server 2014在还原数据库时提示: 无法在已有的""上还原文件,请重新发出RESTORE语句,用WITH REPLACE来覆盖原先存在的文件... 实现 在还原时选择选项下的还原选项--覆盖现有数据库. 然后即可. 注: 博客首页: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 原文地址:https://www.cnblogs.com/badaoliumang

如何将RAC数据库的 RMAN Disk 备份 Restore 到另一个节点上的单个实例 (Doc ID 415579.1)

HowTo Restore RMAN Disk backups of RAC Database to Single Instance On Another Node (Doc ID 415579.1) APPLIES TO: Oracle Database - Enterprise Edition - Version 9.2.0.1 and laterOracle Database Cloud Schema Service - Version N/A and laterOracle Databa

SQLSERVER使用密码加密备份文件以防止未经授权还原数据库

原文:SQLSERVER使用密码加密备份文件以防止未经授权还原数据库 SQLSERVER使用密码加密备份文件以防止未经授权还原数据库 在备份数据库的时候,用户可以为媒体集.备份集或两者指定密码 在backup语句中,定义备份集密码和媒体密码为可选功能.使用密码可防止利用SQLSERVER工具未经授权地执行还原操作和在媒体中添加备份集. 如果指定了密码则用户还必须提供媒体密码才能执行这些操作 关于媒体集和备份集大家可以参考MSDN:http://msdn.microsoft.com/zh-cn/l