数据库不完全恢复 以及恢复到测试环境:

 sample 1: 

1.清空归档日志

RMAN> crosscheck archivelog all;

RMAN> delete achivelog all;

 

2.清空数据文件。

select name from v$datafile;

rm v$datafile

 

3.恢复数据

  ##check file date:  

##把db数据恢复到:2017-02-05 00:00:00


 ls -lt /ngenprdblog/
 ls -lt /ngprdb/data
 
 ##change data file location to '/ngprdb/data'
 rman nocatalog target /
 catalog start with '/ngprdb/data';
 switch database to copy;

 

(解释如下)
现在换个角度来考虑,这些控制文件记录的都是不存在的文件,只是数据库认为是这些文件,而我的ASM上才是真实的数据文件,那么,
我可以把ASM上的文件都认为是数据文件的copy备份,完全可以使用RMAN的catalog start with手工将这些copy“备份”加进来,数据库会认为这些文件就只是数据文件的copy备份,然后直接switch database to copy就可以成功切换。)


 ### change logfile location to '/ngprdb/data'
 select 'alter database rename file '||''''||member||''''||' to '||chr(39)||replace(member,'/ngenprdb/','/ngprdb/')||''';'   
from v$logfile;



 ###recover database method 1
recover database;
sql 'alter database open';
 
 ##recover database method 2
run{
set until time "to_date('2017-02-05 00:00:00','YYYY-MM-DD  HH24:MI:SS')";
restore database;
recover database;
sql 'alter database open resetlogs';
}


sampe 2 .restore prod db to uat db


initedruat.ora

change db_name
#db_name = edruat
db_name = edrprod

dbngt6[/home/oracle][edruat] >sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue May 9 17:06:05 2017

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

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 5678927872 bytes
Fixed Size 2215680 bytes
Variable Size 1006633216 bytes
Database Buffers 4664066048 bytes
Redo Buffers 6012928 bytes
Database mounted.
SQL> alter database backup controlfile to trace;

Database altered.

SQL> select * from v$diag_info;


initedruat.ora
change db_name
db_name = edruat
#db_name = edrprod


sed -n "1,2p"
sed -n "70,210p" /edruatdb/diag/rdbms/edrprod/edruat/trace/edruat_ora_8217.trc > /tmp/contrl.sql
set ic
%s/prod/uat/g
%s/PROD/UAT/g


###
ORA-01503: CREATE CONTROLFILE failed
ORA-01161: database name EDRPROD in file header does not match given name of
EDRUAT
ORA-01110: data file 1: '/edruatdb/data/system_f01.dbf'
#####

vi /tmp/contrl.sql
chang "resue" to "SET" and "NORESETLOGS" to "RESETLOGS"

CREATE CONTROLFILE SET DATABASE "DEV" RESETLOGS ARCHIVELOG

 

######
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-00200: control file could not be created
ORA-00202: control file: '/edruatdb/data/cntl01.ctl'
ORA-27038: created file already exists
Additional information: 1
######

mv /edruatdb/data/cntl01.ctl /edruatdb/data/cntl01.ctl.bak
mv /edruatdb/data/cntl02.ctl /edruatdb/data/cntl02.ctl.bak

 

SQL> @/tmp/contrl.sql
ORACLE instance started.

Total System Global Area 5678927872 bytes
Fixed Size 2215680 bytes
Variable Size 1006633216 bytes
Database Buffers 4664066048 bytes
Redo Buffers 6012928 bytes

Control file created.

 

SQL> recover database using backup controlfile until cancel;
ORA-00279: change 9742867340450 generated at 05/08/2017 14:00:07 needed for
thread 1
ORA-00289: suggestion : /edruatdblog/edrprod_863435250_1_37704.arc
ORA-00280: change 9742867340450 for thread 1 is in sequence #37704


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00279: change 9742867342449 generated at 05/08/2017 14:43:31 needed for
thread 1
ORA-00289: suggestion : /edruatdblog/edrprod_863435250_1_37705.arc
ORA-00280: change 9742867342449 for thread 1 is in sequence #37705
ORA-00278: log file '/edruatdblog/edrprod_863435250_1_37704.arc' no longer
needed for this recovery

 

SQL> alter database open resetlogs;

Database altered.

cd /edruatdb/change/env

SQL> @chg_env_edruat.sql

 

 

rm /edruatdb/data/temp_f*

alter tablespace TEMP add tempfile '/edruatdb/data/temp_f01.dbf' size 4000m autoextend on;
alter tablespace TEMP add tempfile '/edruatdb/data/temp_f02.dbf' size 4000m autoextend on;
alter tablespace TEMP add tempfile '/edruatdb/data/temp_f03.dbf' size 4000m autoextend on;

alter database default temporary tablespace temp;

 

 

Solution


How to restore a complete database from an RMAN backup


This note assumes an RMAN catalog is not available. The use of a catalog is optional in this scenario as the backup information is available in the controlfile.

Prior to restoring a database you must ensure you have a valid RMAN backup.

In this example we will assume all files are required to be restored:

* Datafiles
* Controlfiles
* Archivelogs (In order to perform recovery)

Online redo logs and temp files are recreated automatically by RMAN when a resetlogs is issued. Online redo logs and temp files are not backed up by RMAN

Step 1:  Identify controlfile backup to restore


Note: If  you do not need to restore a controlfile proceed to step 3.


* Locate the RMAN backup you wish to restore.
* These files should be located in the directory where they were backed up to.
* If you have the RMAN backup log available this will also be of assistance.

Within the RMAN backup log you will see the controlfile is backed up last the the piece handle is shown.

....
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2009/01/01 12:00:00
channel ORA_DISK_1: finished piece 1 at 2009/01/01 12:00:02
piece handle=/recovery_area/V11/backupset/2009_05_0 /o1_mf_ncsnf_TAG20090506T11_501tr0h7_.bkp tag=TAG20090506T11 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02

If you do not have an RMAN backup log simply locate the last file RMAN backed up.  This should contain the controlfile backup.

Step 2:  Restore the controlfile

2a) If you DO NOT have a spfile.

If you do have an spfile or init.ora move to Step 2b

If you do not have a valid spfile or init.ora RMAN has the ability to nomount an instance without the requirement of a spfile. This will allow you to restore your spfile from a valid backup.

% rman target /

RMAN> startup nomount force;

You will see this message:

..
starting Oracle instance without parameter file for retrieval of spfile
..

At this point you can restore the spfile:

RMAN> restore spfile from '/recovery_area/V11/backupset/2009_05_05/o1_mf_ncsnf_TAG20_501tr0h7_.bkp';

RMAN> shutdown immediate;

Once the spfile has been successfully restored proceed to Step 2b.

2b)

SQL> startup nomount;

Following the successful nomount of the instance you are ready to restore the
controlfile;

NOTE: The controlfile will be restored to the following location:

SQL> show parameter control_files

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_files string /oradata/V11/control01.ctl

% rman target /

You will see the message:

connected to target database: V11 (not mounted)


RMAN> restore controlfile from '/recovery_area/V11/backupset/2009_05_06/o1_mf_ncsnf_TAG20090506T113947_501tr0h7_.bkp';

Starting restore at 2009/05/11 11:01:26
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=151 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oradata/V11/control01.ctl
Finished restore at 2009/05/11 11:01:27

In this example the controlfile has been restored to '/oradata/V11/control01.ctl'

Step 3:  Restore and recover the database

Your next task is to restore the database and perform recovery.  Mount the database now that the controlfile has been restored:

RMAN> alter database mount;

Now you have two options for recovery.

1) Full/Complete recovery.
2) Point In Time Recovery (PIT)

In both examples it is assumed that all archivelogs are available to perform the recovery.

 

Full recovery
==========

To Perform a full restore and recovery.

run{
restore database;
recover database;
alter database open resetlogs;
}


If you performed a complete recovery with current controlfile and online redologs in place, you might get below error when opening the database with resetlogs:

ORA-01139: RESET LOGS option only valid after an incomplete database recovery

At this point simply open the database without resetlogs option.

PITR Recovery
===========


Point-In-Time Recovery (PITR) would be used if you have decided to restore a database to a particular point in time. This may be warranted for a hardware fault or if you are aware of a database corruption that occured at a certain date/time.

run{
set until time "to_date('Aug 16 2014 10:30:00','Mon DD YYYY HH24:MI:SS')";
restore database;
recover database;
sql 'alter database open resetlogs';
}



NOTE: The above scripts may be altered to allocate more channels. Good practice would be to review the backup log and use the same number of channels for restore as that used by the backup. 

转载于:https://www.cnblogs.com/feiyun8616/p/6396735.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/457204.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

centos7安装java6_CentOS7.6安装jdk1.8

2、登录Linux服务器&#xff0c;通过rz命令将jdk导入服务器如果没有rz命令 需要先安装lrzszyum install lrzsz -y3、将jdk压缩包解压到指定路径 -C 指定路径4、配置环境变量编辑/etc/profile文件 在末尾加上以下内容 wq保存退出source /etc/profile文件 使配置文件生效export J…

ubuntu安装wkhtmltopdf

下载安装wkhtmltox系统环境 http://wkhtmltopdf.org/downloads.html wget https://bitbucket.org/wkhtmltopdf/wkhtmltopdf/downloads/wkhtmltox-0.13.0-alpha-7b36694_linux-precise-amd64.deb dpkg -i 安装包名字 当我把它生成pdf的时候我想让每个块都是一页&#xff0c;经过…

人生苦短,我用python——当我在玩python的时候我玩些什么 -

程序的基本思路 用一个txt文件记录电脑的一天内累计使用时间累计使用时间超过若干小时就会自动关机程序开机自动运行 为什么我最后选择了python 想着怎么写、搜资料的时候就发现Java并不适合&#xff0c;虽然不是不能实现&#xff0c;但有好几个问题解决起来都有点麻烦。对我这…

IO流的练习5 —— 读取文件中的字符串,排序后写入另一文件中

需求&#xff1a;已知s.txt文件中有这样的一个字符串&#xff1a;“hcexfgijkamdnoqrzstuvwybpl”     请编写程序读取数据内容&#xff0c;把数据排序后写入ss.txt中。分析&#xff1a;   A&#xff1a;读取文件中的数据   B&#xff1a;把数据存在一个字符串中   C…

java解析未知key json_Gson解析JSON中动态未知字段key的方法

前面一篇文章我介绍了Gson的解析的基本方法。但我们在享受Gson解析的高度封装带来的便利时&#xff0c;有时可能会遇到一些特殊情况&#xff0c;比如json数据中的字段key是动态可变的时候&#xff0c;由于Gson是使用静态注解的方式来设置实体对象的&#xff0c;因此我们很难直接…

Twisted入门教程(5)

2019独角兽企业重金招聘Python工程师标准>>> 第五部分&#xff1a;由Twited支持的诗歌下载服务客户端 你可以从这里从头开始阅读这个系列 抽象地构建客户端 在第四部分中&#xff0c;我们构建了第一个使用Twisted的客户端。它确实能很好地工作&#xff0c;但仍有提高…

Jquery 学习之基础一

1.添加一个CSS类 $("button").click(function(){ $("#div1").addClass("important blue");}); 2.移除一个类 $("button").click(function(){ $("h1,h2,p").removeClass("blue");}); 3.切换类 $("button&…

**print('人生苦短 我爱Python')**

print(‘人生苦短 我爱Python’) 一、变量 **""" 1.代码自上而下执行 2_运算符和表达式.一行一句&#xff0c;不要把多个语句写到一行上&#xff0c;可读性不好 3中文只能出现在引号里&#xff0c;其他地方不能出现中文 4不能随意缩进 """**pr…

java线程提高速度_如何在JAVA中减慢线程速度

我有这个类,我在其中运行10次for循环.该类实现了Runnable接口.现在在main()中我创建了2个线程.现在两个都将循环运行到10.但我想检查每个线程的循环计数.如果t1超过7,则让它休眠1秒,以便让t2完成.但是如何实现这一目标呢&#xff1f;请参阅代码.我尝试但看起来完全愚蠢.只是如何…

(转ORCLE导入导出命令)

oracle数据库导入导出命令&#xff01;Oracle数据导入导出imp/exp 功能&#xff1a;Oracle数据导入导出imp/exp就相当与oracle数据还原与备份。 大多情况都可以用Oracle数据导入导出完成数据的备份和还原&#xff08;不会造成数据的丢失&#xff09;。 Oracle有个好处&…

笔记本(华硕UL80VT)软件超频setFSB

Warning !!!If you are a beginner, do not use this software. This software is for power users only. Use "SetFSB.exe" at your own risk.试了setfsb各种版本&#xff0c;基本不能打开。还有官网的免费版&#xff0c;居然不能用&#xff0c;真是很奇怪。 官网&a…

Day01-python编程基础

1. 程序 为了完成某种特定功能&#xff0c;以某种程序设计语言编写的有序指令的集合。程序是指挥cpu工作的“工作手册”。计算机只能执行二进制代码&#xff0c;程序设计语言一般类似英文&#xff0c;想要让计算机理解你写的程序&#xff0c;必须把程序代码“翻译”成计算机能…

pro c 访问 MySQL_Pro*C  OCI  OCCI  及OCI介绍

Pro*C OCIOCCI 这三种都是C/C访问数据库的手段。Pro*C&#xff1a;内嵌SQL,预编译后把内嵌SQL处理为ORACLE标准运行库的调用&#xff0c;然后再象编译一般的C程序一样进行编译、连接、运行。1.proc XXX.pc2.gcc/g XXX.c –lclntsh(PRO*C的预编译&#xff0c;也可直接MAKEFILE…

细说Cookie

http://www.cnblogs.com/fish-li/archive/2011/07/03/2096903.html转载于:https://www.cnblogs.com/benpaodexiaopangzi/p/5933230.html

Node.js~在linux上的部署

我们以centOS为例来说说如何部署node.js环境 一 打开centos,然后开始下载node.js包 curl --silent --location https://rpm.nodesource.com/setup_6.x | bash - yum -y install nodejs 二 安装gcc环境 yum install gcc-c make 安装完成! 三 安装nodejs的npm,这是一个包程序工具…

Django中的class Meta知识点

今天来回顾一下Django中model的class Meta class Main(models.Model):img models.CharField(max_length200) # 图片name models.CharField(max_length100) # 名称trackid models.CharField(max_length16) # 通用idclass Meta:abstract True #抽象类class MainWheel(…

python wheel使用_Python wheel.Wheel方法代碼示例

# 需要導入模塊: from pip import wheel [as 別名]# 或者: from pip.wheel import Wheel [as 別名]def from_line(cls, name, comes_fromNone, prereleasesNone):"""Creates an InstallRequirement from a name, which might be arequirement, directory contai…

英语学习Day1

今天要开始学英语了&#xff0c;我这个人没什么长性&#xff0c;语言这种东西对我来说又是很不擅长的一种技能&#xff0c;那为什么要学英语呢&#xff1f;我要做翻译&#xff0c;也是呵呵了&#xff0c;主要是我想赚钱&#xff0c;这个力量能够支撑我吧&#xff0c;我想。 网上…

LeetCode题解-3-Longest Substring Without Repeating Characters

2019独角兽企业重金招聘Python工程师标准>>> 解题思路 首先要读懂题目&#xff0c;它要求的是找到最长的子串&#xff0c;并且子串中没有出现重复的字符。 我的想法&#xff0c;是用一个map存储每个字符最后出现的位置&#xff0c;还要有个变量start&#xff0c;它用…

Day02-变量_数据类型和运算符

1 数据类型 不同类型的变量可以进行的运算是不同的&#xff0c;所以必须理解变量的类型&#xff0c;python中数据类型可以分为&#xff1a; 内置类型 数值类型&#xff1a;整型int&#xff0c;浮点型float&#xff0c;复数&#xff08;complex&#xff09; 35j str:字符串 b…