备份恢复4.2rman恢复基础概念
rman恢复与用户管理的备份恢复一样,都分为完全恢复和不完全恢复,都需要工作在archivelog模式下。 rman10g之后只保留了0级和1级备份,1级备份分为:cumulative(累积增量)和differential(差异增量)两种模式,如果不加关键词默认是差异增量备份: backup
rman恢复与用户管理的备份恢复一样,都分为完全恢复和不完全恢复,都需要工作在archivelog模式下。
rman10g之后只保留了0级和1级备份,1级备份分为:cumulative(累积增量)和differential(差异增量)两种模式,如果不加关键词默认是差异增量备份:
backup incremental level 1 cumulative database(累积增量)
backup incremental level 1 database(差异增量)
连接:
rman
connect target /
@/mydir/lyg.txt
或者:
rman @/mydir/lyg.txt
1、rman转储命令:
当使用rman执行介质恢复时,首先需要用restore命令来完成转储备份文件的,执行restore命令时,rman自动转储最近备份的文件。
restore database : 转储数据库的所有数据文件,当数据库的所有数据文件都出现介质失败,或者执行不完全恢复时,应该使用restore database 命令转储所有数据文件,此命令只能在mount状态下使用。
restore tablespace :用于转储特定表空间的数据文件,如果某个表空间的所有数据文件都出现介质失败,并且数据库处于open阶段,那就应该使用restore tablespace命令。该命令只能在open状态下使用。
restore datafile:转储特定数据文件,该命令既可以在mount状态下,也可以在open状态下使用。
restore controlfile: 该命令用于转储控制文件,当执行基于控制文件的不完全恢复或者将数据库恢复到先前副本状态时,必须转储控制文件,restore controlfile 命令只能在nomount状态下使用。
restore archivelog:转储归档日志,当执行完全恢复和不完全恢复时,都需要应用归档日志。如果归档日志出现介质失败,或者归档日志的映像副本不存在,那么应该使用restore archivelog命令转储归档日志,注意,该命令既可以在mount状态下使用,也可以在open状态下使用。
restore spfile: 转储服务器参数文件。如果服务器参数文件出现介质失败,那么可以使用restore spfile命令进行转储。该命令只能在nomount状态使用。
2、rman恢复命令:
当执行介质恢复时,在转储了数据文件备份之后,需要应用归档日志恢复数据文件,恢复数据文件是使用recover命令来完成的,当执行recover命令时,rman会自动应用自 最近备份以来的所有归档日志。
recover database : 用于恢复数据库所有的数据文件,当使用restore database命令转储了所有的数据文件备份之后,应该使用recover database命令执行恢复,注意该命令只能在mount状态下使用。
recover tablespace: 恢复特定表空间的数据文件,先用restore tablespace命令转储,然后使用recover tablespace执行恢复。注意,该命令只能在open状态下。
recover datafile: 该命令既可以在mount状态下,也可以在open状态下使用。
恢复数据库:
通过查询动态性能视图 v$recover_file可以确定需要恢复的数据文件:
SQL> startup —— 数据库显示mounted 但是open时出错
SQL> select file#, error from v$recover_file; ——查询需要恢复的文件,以及出错的原因
示例一 :所有数据文件被误删除:因为所有数据文件全部被误删除,所以可以使用restore database 命令转储所有数据文件,在使用recover database 命令恢复数据库,最后执行 alter database open打开数据库:
C:\> rman target sys/liu123@mynewdb nocatalog
RMAN> startup force mount
RMAN>run{ restore database;
recover database;
sql 'alter database open ';
}
示例二:数据文件所在磁盘出现硬件故障:
需要注意,数据文件此事将不能被转储到其原来的位置,为了恢复数据库,必须将数据文件转储到其他磁盘。在执行restore database 命令之前,通过执行set newname命令可以为数据文件指定新的位置。在执行restore database 命令之后,通过执行switch datafile命令,可以改变控制文件所记载的数据文件位置和名称,在通过执行recover database命令可以应用归档日志。最后用sql语句打开数据库。示例:
RMAN> run{
startup force mount;
set newname for datafile 1 to 'c:\demo\system01.dbf';
set newname for datafile 2 to 'c:\demo\undotas01.dbf';
set newname for datafile 3 to 'c:\demo\sysaux01.dbf';
set newname for datafile 4 to 'c:\demo\users01.dbf';
set newname for datafile 5 to 'c:\demo\user01.dbf';
set newname for datafile 6 to 'c:\demo\user02.dbf';
restore database;
switch databse;
sql 'alter database open'
}
在恢复并打开数据库之后,执行report schema命令可以查看到数据库新的物理方案
RMAN> report schema;
恢复system表空间的数据文件:
因为system表空间出现介质失败时,数据库不能被打开,所以必须在mount状态下恢复其数据文件。
示例一:system表空间的数据文件被误删除,在装载了数据库之后,先使用restore datafile 命令转储该表空间所对应的数据文件,在使用recover datafile 命令应用归档日志。最后打开数据库。命令:
RMAN> run{
startup force mount;
restore datafile 1 ;
recover datafile 1 ;
sql 'alter database open'
}
示例二:system表空间数据文件所在磁盘出现故障,肯定不能转储到原来位置,在restore datafile之前,执行set newname为数据文件指定新的位置。执行完restore datafile之后,通过switch datafile可以应用归档日志,最后打开数据库。示例:
RMAN> run {
startup force mount;
set newname for datafile 1 to 'd:\demo\system01.dbf';
restore datafile 1 ;
switch datafle 1;
recover datafile 1;
sql 'alter database open';
}
在open状态下恢复关闭后意外丢失的数据文件:
除了system 表空间的数据文件之外,其他数据文件都可以使用该方法进行恢复:
示例一:数据文件被误删除:装载数据库之后,先使用sql语句alter database datafile 。。。offline脱机丢失的数据文件,接着alter database open 打开数据库。,再使用restore datafile命令转储数据文件,使用recover datafile 命令应用归档日志。,最后再 alter database datafile 。。online恢复联机、示例:
RMAN > run {
startup force mount;
sql ‘ alter database datafile 4 offline’;
sql 'alter database open';
restore datafile 4;
recover dtafile 4;
sql 'alter database datafile 4 online';
}
示例二:数据文件所在的磁盘出现损坏:
很显然数据文件不能被转储到原来的位置。首先装载数据库,然后alter database datafile 。。 offline 。然后alter database open。 在restore datafile之前,先set newname 命令为数据文件制定新的位置,在执行了restore datafile命令之后,用switch datafile 命令可以改变控制文件所记载的数据文件的位置和名称,在通过recover datafile 命令可以应用归档日志。最后alter database datafile 。。 online联机。示例代码:
RMAN > run{
startup force mount;
sql 'alter databse datafile 4 offline';
sql 'alter database open ';
set newname for datafile 4 to 'd:\demouser01.dbf';
restore datafile 4;
switch datafile 4;
recover datafile 4;
sql 'alter database datafile 4 onlune';
}
在open状态下恢复打开时意外丢失的数据文件:
此时,只有出现介质失败的数据文件不能访问,而不影响其他数据文件,假定在open状态下users01,.dbf出现介质失败。
示例一:数据文件被误删除:先在open状态下alter database datafile 。。offline ,使用restore datafile 命令转储数据文件,再recovert datafile应用归档日志,最后alter database datafile 。。online使数据文件联机:
RMAN>run {
sql 'alter database datafile 4 offline';
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
示例二:数据文件所在磁盘出现故障:不能讲数据文件转储到原来位置,首先alter database datafile 。。offline 。然后set newname for 命令为数据文件指定新位置。然后restore datafile,再switch datafile 更改控制文件中数据文件的名称和位置。再使用recover datafile应用归档日志。最后alter database datafile 。。online。示例:
RMAN > run {
sql ' alter database datafile 4 offline';
set newname for datafile 4 to 'd:\demo\users01.dbf';
restore datafile 4;
switch datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
在open状态下恢复未备份的数据文件:
示例一:数据文件被误删除:
注意此时数据文件并没有备份,从10g开始,如果数据文件备份不存在,那么转储数据文件时会自动建立数据文件,建立了数据文件之后,就可以根据归档日志跑日志,一直恢复到删除文件的时间点。示例:
RMAN>run {
starup force mount;
sql 'alter database datafile 7 offline';
sql 'alter database open';
restore datafile 7;
recover datafile 7;
sql 'alter database datafile 7 online';
}
示例二:数据文件所在磁盘损坏。
RMAN>run{
startup force mount ;
sql 'alter database datafile 7 offline';
sql 'alter database open';
set newname for datafile 7 to 'c:\demo\user04.dbf';
restore datafile 7;
switch datafile 7;
recover datafile 7;
sql 'alter database datafile 7 online';
}
恢复表空间:
示例一:数据库处于open状态下,如果某个表空间所有数据文件出现介质故障,首先要使用alter tablespace 。。offline for recover来脱机表空间。接着使用restore tablespace 。。再revover tablespace应用归档日志,最后alter tablespace 。。online 。示例:
RMAN > run{
sql ' alter tablespace users offline for recover';
restore tablespace users;
recover tablespace users;
sql ' alter tablespace users online';
}
示例二:表空间数据文件所在磁盘故障:
RMAN> run{
sql 'alter tablespace users offline for recover';
set newname for datafile 4 to 'd:\demo\users01.dbf';
restore tablespace user;
switch datafile all;
recover tablespace users;
sql 'alter tablespace users online';
}
数据块介质恢复:
只有当访问到这些坏块的时候才会报错。如报错:
ora-01578:oracle data block corrupted (file# 5, block# 21)
ora-01110:data file 5 :’d:\demo\uyser01,dbf‘
使用命令如下:RMAN > blockrecover device type disk datafile 5 block 21 ,48 ,128;
RMAN不完全恢复:
rman的不完全恢复能在mount状态下完成。
1、基于时间恢复:当rman执行基于时间点的 不完全恢复时,首先要在命令行设置环境变量NLS_DATE_FORMAT。进入rman之后,先mount数据库,再使用SET UNTIL TIME 命令执行要恢复到的时间点。示例:
C:\> set nls_date_format = yyyy-mm-dd hh24:mi:ss
C:\>rman target sys/oracle@demo nocatalog
RMAN > run{
startup force mount;
set until time = '2012-05-08 17:00:28';
restore database;
recover database;
sql 'alter database open resetlogs';
}
当使用resetlogs选项打开数据库之后,会复位日志序列号,并生成新的数据库副本,在10g之前,不完全恢复之后必须重新备份数据库,10g之后,oracle提供了安全机制可以确保归档日志不会被覆盖,从而使得在恢复数据库时可以使用早期数据库副本的备份,但在执行了不完全恢复之后,建议删除早期的所有备份,并重新备份数据库。示例:
RMAN > run {
delete noprompt backup;
delete noprompt copy;
backup database format =’d:backup\%d_%s.bakj‘;
sql 'alter system archive log current';
}
基于SCN的恢复:
首先查询当前scn号:SQL> select current_scn from v$databse;
然后删除一个表scott.emp。
示例如下:RMAN > run{
startup force mount;
set until scn = 511416;
restore database;
recover database;
sql 'alter database open resetlogs';
}
当使用resetlogs选项打开数据库之后,会复位日志序列号,并生成新的数据库副本,在10g之前,不完全恢复之后必须重新备份数据库,10g之后,oracle提供了安全机制可以确保归档日志不会被覆盖,从而使得在恢复数据库时可以使用早期数据库副本的备份,但在执行了不完全恢复之后,建议删除早期的所有备份,并重新备份数据库。示例:
RMAN > run {
delete noprompt backup;
delete noprompt copy;
backup database format =’d:backup\%d_%s.bakj‘;
sql 'alter system archive log current';
}
基于日志序列号恢复:
假定我们在执行完全备份恢复失败时,出现了如下错误
这种情况下dba可以实用基于日志序列号的不完全恢复:示例:
RMAN > run{
startup force mount;
set until sequence = 6;
restore database;
recover database;
sql ’alter database open resetlogs‘;
}
当使用resetlogs选项打开数据库之后,会复位日志序列号,并生成新的数据库副本,在10g之前,不完全恢复之后必须重新备份数据库,10g之后,oracle提供了安全机制可以确保归档日志不会被覆盖,从而使得在恢复数据库时可以使用早期数据库副本的备份,但在执行了不完全恢复之后,建议删除早期的所有备份,并重新备份数据库。示例:
RMAN > run {
delete noprompt backup;
delete noprompt copy;
backup database format =’d:backup\%d_%s.bakj‘;
sql 'alter system archive log current';
}
基于备份控制文件恢复:
是指实用备份控制文件恢复数据库的过程,当误删除了表空间或者数据库所有控制文件全部损坏时,可以使用这种方法。下面模拟dba用户删除了users表空间为例,说明基于备份控制文件恢复的方法;
SQL> drop tablespace user01 including contents;
通过查询alert文件可以确定误操作时间,alert文件位置:background_dump_dest所对应的目录中,文件名格式:alert_mynewdb.log查看alert文件时,应该有文件尾部向上查看,可以看到删除该表的具体时间,大概为2012-05-08 22:13:34 ,只要恢复到该时间点就可以了,注意:当使用基于备份控制文件的rman不完全恢复时,必须使用恢复目录,将控制文件内的rman元数据周期性写到恢复目录中去,如果没有使用恢复目录,那就要求激活控制文件自动备份功能,否则就不能转储控制文件备份,转储控制文件之前,需要使用set dbid命令,设置数据库id编号,在转储了控制文件之后装载数据库,然后执行基于时间点的rman不完全恢复。示例:
C:\> set nls_date_format = yyyy-mm-dd hh24:mi:ss
C:\>rman target sys/oracle@demo nocatalog
RMAN > startup force nomount
RMAN > set dbid = 3282656886;
RMAN > restore controlfile from autobackup maxseq 6;
RMAN > alter database mount
RMAN >run{
set until time = '2012-05-08 22:13:34';
restore database;
recover database;
sql 'alter database open resetlogs';
}
当使用resetlogs选项打开数据库之后,会复位日志序列号,并生成新的数据库副本,在10g之前,不完全恢复之后必须重新备份数据库,10g之后,oracle提供了安全机制可以确保归档日志不会被覆盖,从而使得在恢复数据库时可以使用早期数据库副本的备份,但在执行了不完全恢复之后,建议删除早期的所有备份,并重新备份数据库。示例:
RMAN > run {
delete noprompt backup;
delete noprompt copy;
backup database format =’d:backup\%d_%s.bakj‘;
sql 'alter system archive log current';
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Open WeChat, select Settings in Me, select General and then select Storage Space, select Management in Storage Space, select the conversation in which you want to restore files and select the exclamation mark icon. Tutorial Applicable Model: iPhone13 System: iOS15.3 Version: WeChat 8.0.24 Analysis 1 First open WeChat and click the Settings option on the My page. 2 Then find and click General Options on the settings page. 3Then click Storage Space on the general page. 4 Next, click Manage on the storage space page. 5Finally, select the conversation in which you want to recover files and click the exclamation mark icon on the right. Supplement: WeChat files generally expire in a few days. If the file received by WeChat has not been clicked, the WeChat system will clear it after 72 hours. If the WeChat file has been viewed,

Private browsing is a very convenient way to browse and protect your privacy when surfing the Internet on your computer or mobile device. Private browsing mode usually prevents the browser from recording your visit history, saving cookies and cache files, and preventing the website you are browsing from leaving any traces in the browser. However, for some special cases, we may need to restore the browsing history of Incognito Browsing. First of all, we need to make it clear: the purpose of private browsing mode is to protect privacy and prevent others from obtaining the user’s online history from the browser. Therefore, incognito browsing

How to backup Google Chrome extension? For most Google Chrome users, more or less plug-ins are installed during daily use. The existence of plug-ins can improve our usage experience. When we reinstall the system or browser, these plug-ins cannot be retained, and it is troublesome to download and install them again. So is there a way to back up the currently installed plug-ins? Here’s how to do it. The tutorial method of backing up chrome plug-ins first opens Google Chrome, click the menu in the upper right corner, and select More Tools - Extensions. Click Package extension above the extensions page. In C:UsersAdministratorAppDataLocalGoogleChromeUserDataDe

On Douyin, a short video platform full of creativity and vitality, we can not only enjoy a variety of exciting content, but also have in-depth communications with like-minded friends. Among them, chat sparks are an important indicator of the intensity of interaction between the two parties, and they often inadvertently ignite the emotional bonds between us and our friends. However, sometimes due to some reasons, the chat spark may be disconnected. So what should we do if we want to restore the chat spark? This tutorial guide will bring you a detailed introduction to the content strategy, hoping to help everyone. How to restore the spark of Douyin chat? 1. Open the Douyin message page and select a friend to chat. 2. Send messages and chat to each other. 3. If you send messages continuously for 3 days, you can get the spark logo. On a 3-day basis, send pictures or videos to each other

How to restore Xiaomi Cloud Photo Album to local? You can restore Xiaomi Cloud Photo Album to local in Xiaomi Cloud Photo Album APP, but most friends don’t know how to restore Xiaomi Cloud Photo Album to local. The next step is to restore Xiaomi Cloud Photo Album to local. Local method graphic tutorials, interested users come and take a look! How to restore Xiaomi cloud photo album to local 1. First open the settings function in Xiaomi phone and select [Personal Avatar] on the main interface; 2. Then enter the Xiaomi account interface and click the [Cloud Service] function; 3. Then jump to Xiaomi For the function of cloud service, select [Cloud Backup]; 4. Finally, in the interface as shown below, click [Cloud Album] to restore the album to local.

If you wish to hide the "Start Backup" option in Windows 11's File Explorer, here's what you can do. There are several ways to disable or hide the startup backup option in File Explorer, and we'll briefly list some methods to help you accomplish this task quickly. Before you get started, you need to understand that this option is closely tied to OneDrive. Once you open a library folder (such as Document, Pictures, Music, etc.), it will immediately appear in the file explorer's path. How to delete startup backup in Windows 11’s File Explorer To delete startup backup in Windows 11’s File Explorer, follow the steps below

Windows 10's May 2019 Update features a new, brighter default desktop background. It looks great - with the new light theme. If you use Windows 10’s dark theme, you may want a darker background. Strangely, the original Windows 10 desktop background has been removed from the latest version of Windows 10. You have to download it from the web or copy its files from an old Windows 10 PC. Although we were unable to find this wallpaper image on Microsoft's official website, you can download it from other sources. We found a copy of the original Windows 10 desktop wallpaper in 4K resolution on Imgur. Additionally, there are other sizes and more default walls

Title: How to restore the hosts file after deletion Summary: The hosts file is a very important file in the operating system and is used to map domain names to IP addresses. If you accidentally delete the hosts file, you may be unable to access certain websites or have other network problems. This article will introduce how to recover accidentally deleted hosts file in Windows and Mac operating systems. Text: 1. Restore hosts file in Windows operating system. Hosts file in Windows operating system
