RMAN备份与恢复之数据文件

备份数据文件,模拟磁盘损坏时,还原恢复数据文件.

 首先,查询数据文件序号,备份数据文件,可根据数据文件序号指定备份的数据文件.

SQL> set linesize 1000
SQL> select file_name,file_id from dba_data_files;

FILE_NAME     FILE_ID
------------------------------------------------------------------------------------------
/data2/orcl/users01.dbf    4
/data2/orcl/undotbs01.dbf   3
/data2/orcl/sysaux01.dbf   2
/data2/orcl/system01.dbf   1

1.1查询数据文件序号

  备份数据文件,可单个数据文件备份,即镜像备份,如backup as copy datafile 1 ;也可以将多个数据文件作为备份集进行备份: datafile 1,2,3,4

[[email protected] ~]$ rman target sys/Sina.2015

Recovery Manager: Release 11.2.0.3.0 - Production on Wed Oct 14 11:52:47 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1420421951)

RMAN>  backup as copy datafile 1
2>  format ‘/data2/backup/df1_%d_%U‘;

Starting backup at 14-OCT-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=15 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=76 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=133 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/data2/orcl/system01.dbf
output file name=/data2/backup/df1_ORCL_data_D-ORCL_I-1420421951_TS-SYSTEM_FNO-1_1vqjmdom tag=TAG20151014T115254 RECID=6 STAMP=893073252
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:26
Finished backup at 14-OCT-15

Starting Control File and SPFILE Autobackup at 14-OCT-15
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/autobackup/2015_10_14/o1_mf_s_893073260_c1vnhhjp_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 14-OCT-15

RMAN> list copy ;
specification does not match any control file copy in the repository
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time
------- ---- - --------------- ---------- ---------------
6       1    A 14-OCT-15       1690358    14-OCT-15
        Name: /data2/backup/df1_ORCL_data_D-ORCL_I-1420421951_TS-SYSTEM_FNO-1_1vqjmdom
        Tag: TAG20151014T115254

RMAN>  backup datafile 1,2,3,4 format ‘/data2/backup/df_%d_%T_%U‘;    

Starting backup at 14-OCT-15
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/data2/orcl/system01.dbf
input datafile file number=00003 name=/data2/orcl/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 14-OCT-15
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00002 name=/data2/orcl/sysaux01.dbf
input datafile file number=00004 name=/data2/orcl/users01.dbf
channel ORA_DISK_2: starting piece 1 at 14-OCT-15
channel ORA_DISK_2: finished piece 1 at 14-OCT-15
piece handle=/data2/backup/df_ORCL_20151014_22qjme43_1_1 tag=TAG20151014T115858 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:01:35
channel ORA_DISK_1: finished piece 1 at 14-OCT-15
piece handle=/data2/backup/df_ORCL_20151014_21qjme43_1_1 tag=TAG20151014T115858 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
Finished backup at 14-OCT-15

Starting Control File and SPFILE Autobackup at 14-OCT-15
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/autobackup/2015_10_14/o1_mf_s_893073655_c1vnvsmo_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 14-OCT-15

1.2备份数据文件

1. 删除数据文件
[[email protected]EST144239 backup]# su - oracle
[[email protected] ~]$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.2.0.3.0 Production on Wed Oct 14 14:48:09 2015

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> ! rm /data2/orcl/users01.dbf

2.查看下是否删除:
[[email protected] orcl]$ ll
总用量 1712960
-rw-r----- 1 oracle oinstall   9846784 10月 14 14:50 control01.ctl
-rw-r----- 1 oracle oinstall   9748480 10月 12 15:18 control01.ctl.bak
drwxr-xr-x 3 oracle oinstall      4096 10月 10 10:48 recover_log -rw-r----- 1 oracle oinstall  52429312 10月 14 04:00 redo01.log
-rw-r----- 1 oracle oinstall  52429312 10月 14 11:37 redo02.log
-rw-r----- 1 oracle oinstall  52429312 10月 14 14:50 redo03.log
-rw-r----- 1 oracle oinstall 723525632 10月 14 14:50 sysaux01.dbf
-rw-r----- 1 oracle oinstall 754982912 10月 14 14:49 system01.dbf
-rw-r----- 1 oracle oinstall  30416896 10月 14 14:28 temp01.dbf
-rw-r----- 1 oracle oinstall  94380032 10月 14 14:50 undotbs01.dbf

2.1试验(删除数据文件)

SQL> startup mount force;
ORACLE instance started.

Total System Global Area 1937457152 bytes
Fixed Size                  2229584 bytes
Variable Size            1241516720 bytes
Database Buffers          687865856 bytes
Redo Buffers                5844992 bytes
Database mounted.

[[email protected] orcl]$ rman
Recovery Manager: Release 11.2.0.3.0 - Production on Wed Oct 14 15:51:41 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
RMAN> connect target sys/Sina.2015@study
connected to target database: ORCL (DBID=1420421951, not open)

RMAN>  run{
2>   set newname for datafile 4 to ‘/data2/orcl/user01.dbf‘;
3>   restore database;
4>   switch datafile all;
5>   recover database;
6>   alter database open;}

executing command: SET NEWNAME

Starting restore at 14-OCT-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=192 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=6 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=67 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /data2/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /data2/orcl/user01.dbf
channel ORA_DISK_1: reading from backup piece /data2/backup/df_ORCL_20151014_22qjme43_1_1
channel ORA_DISK_2: starting datafile backup set restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_DISK_2: restoring datafile 00001 to /data2/orcl/system01.dbf
channel ORA_DISK_2: restoring datafile 00003 to /data2/orcl/undotbs01.dbf
channel ORA_DISK_2: reading from backup piece /data2/backup/df_ORCL_20151014_21qjme43_1_1
channel ORA_DISK_1: piece handle=/data2/backup/df_ORCL_20151014_22qjme43_1_1 tag=TAG20151014T115858
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:02
channel ORA_DISK_2: piece handle=/data2/backup/df_ORCL_20151014_21qjme43_1_1 tag=TAG20151014T115858
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: restore complete, elapsed time: 00:01:12
Finished restore at 14-OCT-15

datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=893088213 file name=/data2/orcl/user01.dbf

Starting recover at 14-OCT-15
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3

starting media recovery
media recovery complete, elapsed time: 00:00:16

Finished recover at 14-OCT-15

database opened

SQL>  select file#,name,status from v$datafile where file#=4;

     FILE#            NAME                         STATUS
         4           /data2/orcl/user01.dbf             ONLINE

SQL> select * from scott.dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

2.2恢复数据文件

时间: 2025-01-05 18:32:04

RMAN备份与恢复之数据文件的相关文章

RMAN备份与恢复之参数文件与控制文件

0   说明 本例是基于备份数据库全库的基础上,还原参数据文件(spfile),控制文件. 1   准备 [[email protected] /]$ sqlplus /nolog SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 12 11:58:35 2015 Copyright (c) 1982, 2011, Oracle. All rights reserved. SQL> conn sys/Sina.2015@study as sys

MongoDB 数据文件备份与恢复

备份与恢复数据对于管理任何数据存储系统来说都是非常重要的. 1.冷备份与恢复——创建数据文件的副本(前提是要停止MongoDB服务器),也就是直接copy MongoDB将所有数据都存储在数据目录下,默认是/data/db/(Windows下是C:\data\db\),启动MongoDB时也可以用--dbpath指定我们自己设置的数据存储目录. 备份MongoDB数据:只要简单的创建数据存储目录的副本就可以了,直接copy一份. 恢复MongoDB数据:在MongoDB启动时用--dbpath指

RMAN备份与恢复之概念

1   RMAN备份恢复 1.1  基础理论 恢复可以分为完全恢复和不完全恢复 完全数据库恢复是恢复到故障发生前的状态,所有已经提交的操作都进行恢复,确保数据库不丢失任何数据,完全恢复只用于归档模式. 不完全数据库恢复是将数据库恢复到备份点与介质失败点之间某个时刻的状态,并不是恢复所有提交的操作,不完全恢复可能丢失部分数据. 任何类型的恢复包括两个阶段:前滚阶段和回滚(回退)阶段. 在前滚恢复阶段(roll-forward recovery),恢复管理器应用必要的事务日志组“重做”(REDO)所

ORACLE RMAN备份及还原 RMAN可以进行增量备份:数据库,表空间,数据文件

ORACLE RMAN备份及还原 RMAN可以进行增量备份:数据库,表空间,数据文件 只有使用过的block可以被备份成backup set 表空间与数据文件对应关系:dba_data_files / v$datafile_header 在noarchivelog模式下,可以使用RMAN备份read-only和offline的表空间 ORACLE RMAN停机备份: 备份 RMAN连接上ORACLE,WINDOWS下在命令模式下 RMAN TARGET / 连接本地数据库用的是本地认证模式.RM

RMAN数据库恢复之恢复表空间和数据文件

执行表空间或数据文件恢复时,数据库既可以是MOUNT状态,也可以是OPEN状态.1.恢复表空间在执行恢复之前,如果被操作的表空间未处理OFFLINE状态,必须首先通过ALTER TABLESPACE…OFFLINE语句将其置为脱机.然后再RESTORE-->RECOVER--->ONLINE即可. RMAN> SQL 'ALTER TABLESPACE USERS OFFLINE IMMEDIATE'; 在恢复目录中注册的数据库的新原型 正在启动全部恢复目录的 resync 完成全部 r

ORACLE11g 没有控制文件如何通过rman备份恢复数据的详细实战过程

1.副总裁需要裸恢复的严峻现实 集团总部的信息部负责人给我打电话说为了找一年前的记录,所以需要对一年前2015年5月1日的数据进行恢复.而2016年初因为进行迁移,所以有些文件可能丢失,手上只有rman全备文件,希望在一天之内找回,集团一个副总裁在等着这个数据有急用. 我在电话里面说马上去做,接完电话,想到只有rman备份文件,而且是备份的数据文件,没有控制文件没有参数文件的备份,所以普通的 (1)      先恢复控制文件restore controlfile from '-bak'; (2)

RMAN数据库恢复之丢失数据文件的恢复

删除某一数据文件:SQL> HOST del D:\app\Administrator\oradata\orcl\USERS01.dbf 启动数据库,提示丢失数据文件4,此时数据库处理MOUNT状态: RMAN> STARTUP …… 第 1 行出现错误:ORA-01157: 无法标识/锁定数据文件 4 - 请参阅 DBWR 跟踪文件ORA-01110: 数据文件 4: 'D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF' 执行RMAN恢复======

rman 增量恢复 dg gap后 主库添加新数据文件

1) On the standby database, 关闭 (MRP) SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; 2) On the STANDBY DATABASE, 获取备库最小scn值,用作主库增量备份点 : col MIN(CHECKPOINT_CHANGE#) for 999999999999999999 col CURRENT_SCN for 99999999999999999 SELECT CURRE

数据文件、日志文件、归档文件、控制文件、参数文件及RMAN备份数据库信息查询

一.查看数据库信息:=====================1.数据文件 SQL> SELECT FILE#,STATUS,ENABLED,NAME FROM V$DATAFILE; FILE# STATUS ENABLED NAME ---------- ------- ---------- ------------------------------------------------ 1 SYSTEM READ WRITE D:\APP\ADMINISTRATOR\ORADATA\ORC