Home Database Mysql Tutorial rman数据库恢复;关键/非关键文件、影像副本、控制文件、还原点

rman数据库恢复;关键/非关键文件、影像副本、控制文件、还原点

Jun 07, 2016 pm 04:03 PM
The essential copy image recover control database document

执行完全恢复:在 ARCHIVELOG 模式下 丢失了系统关键数据文件: 如果某个数据文件丢失或损坏,且该文件属于 SYSTEM 或 UNDO 表空间,请执行以下步骤: 1. 实例可能会也可能不会自动关闭。 2.如果未自动关闭,请使用 SHUTDOWN ABORT 关闭实例。 3. 装载数据库

执行完全恢复:在 ARCHIVELOG 模式下 丢失了系统关键数据文件:

如果某个数据文件丢失或损坏,且该文件属于 SYSTEM 或 UNDO 表空间,请执行以下步骤:

1.
实例可能会也可能不会自动关闭。
2.如果未自动关闭,请使用 SHUTDOWN ABORT 关闭实例。
3.
装载数据库。
4.
还原并恢复缺失的数据文件。

5.打开数据库。

1.归档模式丢失非关键数据文件 完全恢复

第一种方法:

shutdown abort;

startup mount;

alter database create datafile '/home/oracle/test.dbf' as '/home/oracle/test.dbf';

recover datafile;

第二种方法:

create tablespace test datafile '/home/oracle/test.dbf' size 10m;

rman target /

backup datafile 5;

rm test.dbf

sq> alter database datafile 5 offline;

restore datafile 5;

recover datafile 5;

sq> alter database datafile 5 online;

select FILE#,STATUS from v$datafile;

2. 归档模式丢失关键数据文件 完全恢复

利用备份,同上第二种方法。

--------------------------------------------------------------------------------------------------------------
恢复映像副本:
RMAN> recover copy of database with tag 'daily_inc';

RMAN> backup incremental level 1 for recover of copy
with tag 'daily_inc' database;

RECOVER BACKUP
第 1 天 无 创建映像副本
第 2 天 无 创建 1 级增量备份
第 3 天和以后 根据增量备份恢复副本 创建 1 级增量备份


恢复映像副本:示例
如果每天都运行以上命令,则可以随时获得所有数据库数据文件的连续更新的映像副本。
图表显示了每次运行所发生的操作。请注意,这种算法需要一段准备期间;到第 3 天后策略才会起作用。

第 1 天
RECOVER 命令没有执行任何操作。尚不存在要恢复的映像副本。BACKUP 命令可用于创建映像副本。

第 2 天
RECOVER 命令仍没有执行任何操作。因为尚不存在增量备份。由于已在第 1 天创建了基准映像副本,BACKUP 命令会创建增量备份。
第 3 天
RECOVER 命令将增量备份中的更改应用于映像副本。BACKUP 命令将执行另一个增量备份,该备份将在第 4 天用于恢复映像副本,依此进行循环。

执行到映像副本的快速切换
执行以下步骤

可以使用数据文件的映像副本进行快速恢复:

1.使数据文件脱机。
2.使用 SWITCH TO ...COPY 命令指向这些文件的映像副本。

3.恢复数据文件。
4.使数据文件联机。

此时,数据库是可用的,且数据文件已恢复。但是,如果您希望将数据文件放回其原始位置,请继续执行以下步骤:

5.使用 BACKUP AS COPY 命令在原始位置创建数据文件的映像副本。

6.使数据文件脱机。

7.使用 SWITCH TO COPY 命令切换到在步骤 5 中创建的副本。

8.恢复数据文件。

9.使数据文件联机。
可以使用此命令来恢复数据文件、表空间、临时文件或整个数据库。切换到的目标文件必须为映像副本。

3. 映像副本的快速切换

backup as copy datafile 6;

rm a.dbf

sql:alter database datafile 6 offline;

rman >switch datafile '/home/oracle/test.dbf' to copy;

recover datafile 6;

--回复后数据文件的路径和名称为 '/home/oracle/test.dbf';

alter database datafile 4 online;

select FILE#,STATUS from v$datafile;

select file_name from dba_data_files;

backup as copy datafile 4 format '/u01/app/oracle/oradata/orcln/users01.dbf';

alter database datafile 4 offline;

switch datafile ' /home/oracle/backup/db_data_D-ORCL_I-4115975543_TS-TEST_FNO-6_38otbf5q.bak' to copy;

switch datafile 4 to copy;

recover datafile 4;

alter database datafile 4 online;

select file_name from dba_data_files;

-----------------------------------------------------------------------------------------------------------------

4. set newname 改名字

backup as copy datafile 6;

list copy of datafile 6;

select FILE#,STATUS from v$datafile;

run{

allocate channel c1 device type disk;

sql "alter database datafile 6 offline";

set newname for datafile '/home/oracle/test.dbf' to '/home/oracle/test_new.dbf';

restore datafile 6;

switch datafile all;

recover datafile 6;

sql "alter database datafile 6 online";

}
--------------------------------------------------------------------------------------------------------------
从自动备份还原控制文件:

RMAN> STARTUP NOMOUNT;

RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;

RMAN> ALTER DATABASE MOUNT;

RMAN> RECOVER DATABASE;

RMAN> ALTER DATABASE OPEN RESETLOGS;

 

7. 丢失控制文件,参数文件 --数据库必须在nomount状态

查看文件信息:

SQL>select name from v$controlfile;

SQL>show parameter spfile;

SQL> select name from v$datafile;

配置控制文件自动备份恢复控制文件

rman target /

connected to target database: ORCL (DBID=1353286769)

RMAN>show all;

RMAN>CONFIGURE CONTROLFILE AUTOBACKUP ON;

数据库全备份:

RMAN>backup as compressed backupset full database;

删除,参数文件,控制文件,数据文件

rm /opt/oracle/oradata/orcl/control01.ctl

rm /opt/oracle/flash_recovery_area/orcl/control02.ctl

rm /opt/oracle/oradata/orcl/control03.ctl

rm /opt/oracle/product/11.2.2/dbs/spfileorcl.ora

rm /opt/oracle/oradata/orcl/system01.dbf

rm /opt/oracle/oradata/orcl/sysaux01.dbf

rm /opt/oracle/oradata/orcl/undotbs01.dbf

rm /opt/oracle/oradata/orcl/users01.dbf

rm /home/oracle/tbs_ctl01.dbf

rman target /

RMAN> set dbid 1353286769 --如果备份在

startup nomount --虽然没有参数文件但是也可以启动实例

恢复参数文件:

restore spfile from '/data/backup/ctl_c-1353286769-20131102-04.bak';

/* 从快速恢复区恢复参数文件:

run {

restore spfile from autobackup

recovery area = 'flash recovery area destination'

db_name = 'db_name';

}

*/

查看是否有需要改的参数:主要看文件位置

SQL> create pfile from spfile;

恢复控制文件:

restore controlfile to '/opt/oracle/oradata/orcl/control01.ctl' from '/data/backup/ctl_c-1353286769-20131102-04.bak';

恢复数据文件:

RMAN> shutdown immediate

RMAN> startup mount

RMAN> restore database;

RMAN> recover database;

RMAN> alter database open;

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of alter db command at 11/02/2013 12:10:46

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

RMAN> alter database open resetlogs;
--------------------------------------------------------------------------------------------------------------
使用增量备份恢复处于 NOARCHIVELOG 模式的数据库:

STARTUP FORCE NOMOUNT;

RESTORE CONTROLFILE;

ALTER DATABASE MOUNT;

RESTORE DATABASE;

RECOVER DATABASE NOREDO;

ALTER DATABASE OPEN RESETLOGS;

8. 使用增量备份恢复处于NOARCHIVELOG 模式的数据库

1) 撤销数据库archivelog模式

SQL>shutdown immediate;

SQL>startup mount;

SQL>alter database noarchivelog;

SQL>alter database open;

SQL>archive log list; 

2) 创建测试用表及数据

conn zhuxy/zhuxy

create table c (id number);

insert into c values(1);

commit; 

3) 在noarchivelog模式下,0级备份

RMAN> run{

shutdown immediate;

startup mount;

backup as backupset incremental level 0 database;

alter database open;

4) 在noarchivelog模式下,1级备份

insert into c values(2);

commit; 

RMAN> run{

shutdown immediate;

startup mount;

backup as backupset incremental level 1 database;

alter database open;

6) 删除所有日志文件, 某些数据文件 

7) 执行恢复

rman target /

RMAN>startup mount; 

--执行全库的还原

RMAN> restore database; 

-- 使用noredo子句进行恢复

RMAN> recover database noredo; 

--恢复完成,resetlogs方式打开数据库,完成所有文件丢失的恢复

RMAN> alter database open resetlogs; 

8)验证在测试前(增量备份前)插入的数据

select * from c; 

6.非归档丢失文件

不完全恢复: SCN, 时间,还原点,或日志序列号

1确定目标还原点:SCN、时间、还原点或日志序列号。

2设置 NLS 环境变量。

3装载数据库。

4使用 SET UNTIL、RESTORE 和 RECOVER 命令准备并运行 RUN 块。

5用 RESETLOGS 打开数据库。 

-----不完全恢复之--基于时间的恢复

1) 准备环境:RMAN全库备份

RMAN> backup as compressed backupset full database;

2) 准备环境:测试表及数据

alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

create table d (c date);

insert into d values(sysdate);

commit;

create table ff (c date);

insert into ff values(sysdate);

commit; 

启动到mount模式,进行基于时间的恢复

shutdown immediate;

startup mount; 

run

{sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';

set until time = ' 2014-03-30 00:39:34';

restore database;

recover database;

alter database open resetlogs;

}

时间也可以这么写:

set until time="to_date('2013-11-01 15:29:34','yyyy-mm-dd hh24:mi:ss')";

-----还原点:

select count(*) from copy_emp;

创建还原点:

create restore point before_delete;

delete from copy_emp where ID >=10;

commit;

alter table copy_emp enable row movement;

flashback table copy_emp to restore point b; 

--------------------------------------------------------------------------------------------------------------
将数据库还原到新主机:

为了还原数据库,请在还原主机上执行以下步骤:

1.配置 ORACLE_SID 环境变量。

2.启动 RMAN 并在 NOCATALOG 模式下连接到目标实例。

3.设置数据库标识符 (DBID)。

4.在 NOMOUNT 模式下启动实例。
5.
从备份集中还原服务器参数文件。

6.关闭实例。
7.
编辑还原的初始化参数文件。
8.
在 NOMOUNT 模式下启动实例
9.创建 RUN 块以执行下列任务:

--还原控制文件
--
装载数据库

10.创建 RMAN 恢复脚本以还原和恢复数据库。

11.执行 RMAN 脚本。

12.使用 RESETLOGS 选项打开数据库。

9 利用备份将数据库还原到新主机:目标库需要有oracle软件 

1)准备工作

源库数据库全备及控制文件自动备份,当然也包括参数文件

RMAN> backup as backupset database; 

2)拷贝RMAN备份文件到目标库

可以用scp 

3)配置目标库

目标库设置环境变量

export ORACLE_SID=new_orcl 

启动rman到nomount状态,设置dbid(即源库dbid)

$ rman target /

RMAN> set dbid 1357901988

RMAN> startup nomount; --没有参数文件,会报错,但是可以启动实例 

4)恢复参数文件 

RMAN> restore spfile to pfile '' from ''; 

编辑pfile参数文件:文件位置,数据库实例名..,创建相应的目录 

5) 启动数据库到nomount模式

SQL> create spfile from pfile;

SQL> startup nomount; 

6)还原控制文件

$ rman target / 

RMAN> restore controlfile to '' from ''; 

RMAN> alter database mount; 

7) 还原数据文件

run{

SET NEWNAME FOR DATAFILE 1 TO '/u01/app/oracle/oradata/orcl/system01.dbf';

SET NEWNAME FOR DATAFILE 2 TO '/u01/app/oracle/oradata/orcl/sysaux01.dbf';

SET NEWNAME FOR DATAFILE 3 TO '/u01/app/oracle/oradata/orcl/undotbs01.dbf';

SET NEWNAME FOR DATAFILE 4 TO '/u01/app/oracle/oradata/orcl/users01.dbf';

SET NEWNAME FOR DATAFILE 5 TO '/u01/app/oracle/oradata/orcl/example01.dbf';

SET NEWNAME FOR DATAFILE 6 TO '/u01/app/oracle/oradata/orcl/test.dbf';

RESTORE DATABASE;

SWITCH DATAFILE ALL;

RECOVER DATABASE;} 

--rename日志文件

run{

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ENMOEDU/redo01.log'' TO

''/u01/app/oracle/oradata/orcl/redo01.log'' ";

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ENMOEDU/redo02.log'' TO

''/u01/app/oracle/oradata/orcl/redo02.log'' ";

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ENMOEDU/redo03.log'' TO

''/u01/app/oracle/oradata/orcl/redo03.log'' ";

RMAN> alter database open resetlogs; 

8)临时文件位置不对

SQL> select file_name from dba_temp_files;

SQL>create temporary tablespace tempa tempfile

'/u01/app/oracle/oradata/orcl/tempa01.dbf' size 10m reuse autoextend on maxsize 200m;

SQL>alter database default temporary tablespace tempa;

SQL>drop tablespace temp;

SQL>select file_name from dba_temp_files; 

注:这个测试改变了实例名
--------------------------------------------------------------------------------------------------------------
执行灾难恢复 :

灾难意味着丢失了整个目标数据库、恢复目录数据库、所有当前控制文件、所有联机重做日志文件和所有参数文件。

灾难恢复包括还原和恢复目标数据库。

备份集的最低要求:

1.数据文件的备份
2.
相应的归档重做日志文件
3.
至少一个控制文件自动备份

基本过程:
1.
还原服务器参数文件的自动备份。

2.启动目标数据库实例。

3.从自动备份还原控制文件。

4.装载数据库。

5.还原数据文件。

6.恢复数据文件。

7.使用 RESETLOGS 选项打开数据库。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei Imaging XMAGE: Ten major trends will set the tone for the new direction of mobile imaging in the future Huawei Imaging XMAGE: Ten major trends will set the tone for the new direction of mobile imaging in the future Jun 01, 2024 pm 12:27 PM

The development history of the P series is the history of the development of moving images. On the occasion of the 12th anniversary of the birth of the P series, Huawei sets out again with its deep understanding of mobile imaging and future plans. From the emergence of the concept of moving images to its gradual development and growth, Huawei has always played an important role as a leader, becoming the main way for millions of users to record their lives. Today, when the industry is desperately innovating in three dimensions: stacking hardware, improving image quality, and bundling traditional imaging brand styles, we clearly see that homogeneous hardware stacking and algorithm optimization cannot truly differentiate each brand. There is a gap in image capabilities, and more importantly, specific image styles have been difficult to adapt to the individual needs of consumers. Standing at a higher dimension and thinking about the next development direction of mobile imaging, Huawei is the leader.

Control Center not working in iPhone: Fix Control Center not working in iPhone: Fix Apr 17, 2024 am 08:16 AM

Imagine an iPhone without a functioning Control Center. You can't, right? If the buttons on the Control Center don't work properly, you won't be able to use your iPhone properly. The main idea of ​​Control Center is to easily access certain features directly from anywhere on your phone. In this case, these solutions will help to resolve the issue on your phone. Fix 1 – Use a Cloth to Clean Your Phone Sometimes the upper part of the display gets dirty from regular use. This may cause the Control Center to not function properly. Step 1 – Take a soft, clean microfiber cloth and clean the top half of your iPhone screen. You can also use any screen cleaning solution. Step 2 – Make sure to remove any dust, oil, or anything else from your phone’s display. After clearing phone screen

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

OPPO Find X7 is a masterpiece! Capture your every moment with images OPPO Find X7 is a masterpiece! Capture your every moment with images Aug 07, 2024 pm 07:19 PM

In this fast-paced era, OPPO Find X7 can use its imaging power to let us savor every beautiful moment in life. Whether it's magnificent mountains, rivers, lakes, or seas, warm family gatherings, or encounters and surprises on the street, it can help you record them with "unparalleled" picture quality. From the outside, the camera Deco design of Find It looks very recognizable and has a high-end feel. The inside is also unique, starting with the basic hardware configuration. FindX7 maintains the previous

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

200 million pixel image of Thanos! Vivo X100 Ultra real phone hands-on: huge ring camera 200 million pixel image of Thanos! Vivo X100 Ultra real phone hands-on: huge ring camera May 07, 2024 am 09:50 AM

According to news on May 7, vivo will hold a new product launch conference on May 13, and will release the vivoX100s series and vivoX100Ultra. In addition, vivo’s new imaging technology brand blueprint imaging will also be unveiled at the conference. Recently, vivo's official flagship store released a hands-on video of the vivo X100 Ultra real machine. The back of the new machine adopts a new lens layout and has a huge ring-shaped camera module, including the main camera, periscope telephoto and ultra-wide-angle lenses. Vivo also added a circle of brushed metal texture outside the lens ring, and the details are very exquisite. Vivo brand vice president Jia Jingdong said during the warm-up that vivoX100Ultra is an "image destroyer" and was originally developed internally by vivo.

Full analysis of Go language file renaming operation Full analysis of Go language file renaming operation Apr 08, 2024 pm 03:30 PM

The os.Rename function is used in Go language to rename files. The syntax is: funcRename(oldpath,newpathstring)error. This function renames the file specified by oldpath to the file specified by newpath. Examples include simple renaming, moving files to different directories, and ignoring error handling. The Rename function performs an atomic operation and may only update directory entries when the two files are in the same directory. Renames may fail across volumes or while a file is in use.

See all articles