Oracle RMAN备份与还原

  

  RMAN在数据库服务器的帮助下实现数据库文件、控制文件、数据库文件与控制文件的映像副本、归档日志文件、数据库服务器参数文件的备份。

  RMAN的特点:

(1) 支持增量备份:传统的exp与expdp备份工具,只能实现一个完整备份而不能增量备份,RMAN采用备份级别实现增量备份,在一个完整的备份基础上采用增量备份可以大大减少备份的数量;

(2) 自动管理备份文件:RMAN备份的数据是RMAN自动管理的,包括文件名字,备份文件存储目录等;

(3) 自动化备份与恢复:在备份与恢复操作时,使用简单的指令就可以实现备份与恢复,执行过程完全有RMAN维护。

(4) 不产生重做信息: RMAN联机备份不产生重做信息。

(5) 支持映像复制: 使用RMAN可以实现映像复制,映像以操作系统的文件格式存在,这种复制类似于用户管理的脱机备份方式。

(6) 备份的数据文件压缩处理: RMAN提供一个参数,说明是否对备份文件进行压缩,压缩的备份文件以二进制文件格式存在,可以减少备份文件的存储空间。

(7) 备份文件有效性检查功能: 可以在备份之后恢复检测备份文件是否可用,避免无效恢复操作。

1 RMAN 脱机备份与还原

1.1 使用RMAN命令连接到数据库

[[email protected] ~]$ rman target/

Recovery Manager: Release 11.2.0.1.0 - Production on Tue May 30 14:33:04 2017

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

connected to target database: ORCL (DBID=1452257309)

1.2 脱机备份之前确定数据库处于非归档模式下,使用管理员账号登录到数据库查看

SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Current log sequence

1.3 脱机备份时数据必须处于mount状态下,关机启动数据库到mount状态下

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 450953216 bytes
Fixed Size 2214256 bytes
Variable Size 339740304 bytes
Database Buffers 104857600 bytes
Redo Buffers 4141056 bytes
Database mounted.

1.4 RMAN模式下输入脱机备份命令,系统会自动备份整个数据库到默认的目录下

RMAN> backup as compressed backupset database;

Starting backup at 30-MAY-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
input datafile file number=00007 name=/home/oracle/data/CTRR_DATA_1.dbf
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp tag=TAG20170530T105100 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00009 name=/home/oracle/data/rman_ts1.dbf
input datafile file number=00006 name=/usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmdbx_.bkp tag=TAG20170530T105100 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/usr/oracle/app/oradata/orcl/system01.dbf
input datafile file number=00004 name=/usr/oracle/app/oradata/orcl/users01.dbf
input datafile file number=00008 name=/home/oracle/data/default_tablespace.dbf
input datafile file number=00003 name=/usr/oracle/app/oradata/orcl/undotbs01.dbf
input datafile file number=00002 name=/usr/oracle/app/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmfgv_.bkp tag=TAG20170530T105100 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26
Finished backup at 30-MAY-17

Starting Control File and SPFILE Autobackup at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/autobackup/2017_05_30/o1_mf_s_945338539_dlsqp4yv_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 30-MAY-17

以上备份信息可以看出,RMAN将数据文件备份在目录/usr/oracle/app/flash_recovery_area/ORCL/backupset/下,将控制文件与服务器参数文件备份在/usr/oracle/app/flash_recovery_area/ORCL/autobackup/下。这里需要注意如果想要RMAN在整库备份时自动备份控制文件与服务器参数文件,需要设置参数

configure controlfile autobackup的值为on: configure controlfile autobackup on;

RMAN> configure controlfile autobackup on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

此时使用RMAN完成了整个数据库的脱机备份。

备份完成之后用scott用户创建一个测试表,插入一条数据,等恢复完成之后看这个表是否还存在。

create table t_test1(id number, name varchar2(50));

insert into t_test1(id, name)
values(1,‘latiny1‘);

commit;

非归档模式下实现脱机备份恢复

为了测试利用脱机备份文件完全恢复数据库,我们删除部分数据文件、全部控制文件模拟数据库文件丢失,然后进行恢复。

[[email protected] orcl]# ls -l
total 4867456
-rw-r----- 1 oracle oinstall 524296192 May 30 12:12 APSALU3_DATA.dbf
-rw-r----- 1 oracle oinstall 9748480 May 30 14:48 control01.ctl
-rw-r----- 1 oracle oinstall 2147491840 May 30 12:12 CTRR_DATA.dbf
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 14:48 redo01.log
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 12:12 redo02.log
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 12:12 redo03.log
-rwxrwxr-x 1 oracle oinstall 660611072 May 30 14:48 sysaux01.dbf
-rwxrwxr-x 1 oracle oinstall 754982912 May 30 14:48 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 Mar 23 10:52 temp01.dbf
-rwxrwxr-x 1 oracle oinstall 723525632 May 30 14:48 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 30 12:12 users01.dbf

首先关闭数据库,然后删除users01.dbf、CTRR_DATA.dbf、control01.ctl、APSALU3_DATA.dbf,然后启动数据库:

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 450953216 bytes
Fixed Size 2214256 bytes
Variable Size 339740304 bytes
Database Buffers 104857600 bytes
Redo Buffers 4141056 bytes
ORA-00205: error in identifying control file, check alert log for more info

由于控制文件丢失,数据库无法启动到mount状态,先恢复控制文件再启动,恢复控制文件需要指定控制文件对应的备份文件路劲,之前的备份信息里可以获取得到:

RMAN> restore controlfile from ‘/usr/oracle/app/flash_recovery_area/ORCL/autobackup/2017_05_30/o1_mf_s_945338539_dlsqp4yv_.bkp‘;

Starting restore at 30-MAY-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/usr/oracle/app/oradata/orcl/control01.ctl
output file name=/usr/oracle/app/flash_recovery_area/orcl/control02.ctl
Finished restore at 30-MAY-17

控制文件恢复成功之后启动数据库到mount状态:

SQL> alter database mount;

Database altered.

启动到mount状态之后,在RMAN模式下恢复数据文件:

RMAN> restore database;

Starting restore at 30-MAY-17
released channel: ORA_DISK_1
Starting implicit crosscheck backup at 30-MAY-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 11 objects
Finished implicit crosscheck backup at 30-MAY-17

Starting implicit crosscheck copy at 30-MAY-17
using channel ORA_DISK_1
Finished implicit crosscheck copy at 30-MAY-17

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /usr/oracle/app/flash_recovery_area/ORCL/autobackup/2017_05_30/o1_mf_s_945338539_dlsqp4yv_.bkp

using channel ORA_DISK_1

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 00005 to /usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
channel ORA_DISK_1: restoring datafile 00007 to /home/oracle/data/CTRR_DATA_1.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp
channel ORA_DISK_1: ORA-19870: error while restoring backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp
ORA-19502: write error on file "/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf", block number 216192 (block size=8192)
ORA-27072: File I/O error
Linux-x86_64 Error: 25: Inappropriate ioctl for device
Additional information: 4
Additional information: 216192
Additional information: 6963
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 00006 to /usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
channel ORA_DISK_1: restoring datafile 00009 to /home/oracle/data/rman_ts1.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmdbx_.bkp
channel ORA_DISK_1: piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmdbx_.bkp tag=TAG20170530T105100
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
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 00001 to /usr/oracle/app/oradata/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /usr/oracle/app/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /usr/oracle/app/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /usr/oracle/app/oradata/orcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00008 to /home/oracle/data/default_tablespace.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmfgv_.bkp
channel ORA_DISK_1: piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmfgv_.bkp tag=TAG20170530T105100
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:25
failover to previous backup

creating datafile file number=5 name=/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
Finished restore at 30-MAY-17

  其他文件正常恢复,CTRR_DATA.dbf数据文件时遇到错误:

ORA-19502: write error on file "/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf", block number 216192 (block size=8192)
ORA-27072: File I/O error
Linux-x86_64 Error: 25: Inappropriate ioctl for device

查了一下错误原因,发现因为此数据文件较大恢复时导致磁盘空间不足引起的,于是删除一些文件释放磁盘重新执行命令恢复成功:

RMAN> restore database;

Starting restore at 30-MAY-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

skipping datafile 1; already restored to file /usr/oracle/app/oradata/orcl/system01.dbf
skipping datafile 2; already restored to file /usr/oracle/app/oradata/orcl/sysaux01.dbf
skipping datafile 3; already restored to file /usr/oracle/app/oradata/orcl/undotbs01.dbf
skipping datafile 4; already restored to file /usr/oracle/app/oradata/orcl/users01.dbf
skipping datafile 8; already restored to file /home/oracle/data/default_tablespace.dbf
skipping datafile 7; already restored to file /home/oracle/data/CTRR_DATA_1.dbf
skipping datafile 6; already restored to file /usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
skipping datafile 9; already restored to file /home/oracle/data/rman_ts1.dbf
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 00005 to /usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp
channel ORA_DISK_1: piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp tag=TAG20170530T105100
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:26
Finished restore at 30-MAY-17

  然后去之前存放数据文件、控制文件的目录下看一下文件是否都恢复成功:

[[email protected] orcl]# ls -l
total 4867456
-rw-r----- 1 oracle oinstall 524296192 May 30 12:12 APSALU3_DATA.dbf
-rw-r----- 1 oracle oinstall 9748480 May 30 14:48 control01.ctl
-rw-r----- 1 oracle oinstall 2147491840 May 30 12:12 CTRR_DATA.dbf
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 14:48 redo01.log
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 12:12 redo02.log
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 12:12 redo03.log
-rwxrwxr-x 1 oracle oinstall 660611072 May 30 14:48 sysaux01.dbf
-rwxrwxr-x 1 oracle oinstall 754982912 May 30 14:48 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 Mar 23 10:52 temp01.dbf
-rwxrwxr-x 1 oracle oinstall 723525632 May 30 14:48 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 30 12:12 users01.dbf

  使用recover 命令恢复数据库,由于是脱机备份恢复不使用重做日志恢复模式:

RMAN> recover database noredo;

Starting recover at 30-MAY-17
using channel ORA_DISK_1

Finished recover at 30-MAY-17

  然后打开数据库到open状态:

SQL> alter database open resetlogs;

Database altered.

查看备份之后scott用户创建的表,已经不存在了,自备份之后的数据全部丢失。

时间: 2024-10-29 19:10:30

Oracle RMAN备份与还原的相关文章

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

ORACLE RMAN备份及还原(转)

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

Oracle RMAN备份与还原注意事项

1 备份文件管理 如果要删除之前的备份,不要手动去目录下删除,应该在rman命令模式下使用删除命令,否则虽然在磁盘上把物理备份文件删除了,但是使用备份查看命令会一直看到已经删除的备份文件 list backup; 查看当前系统有哪些可用的备份文件 list backupset summary; 查看备份文件的概要信息 crosscheck backup; 更新rman备份信息,如果有损坏的不可用的,或者手动删除的物理备份文件都可以通过此命令查看ex delete expired backup;

第22章 oracle RMAN备份恢复

2015-10-24 目录 参考资料 [1] 林树泽.Oracle 11g R2 DBA操作指南[M].北京:清华大学出版社,2013 [2] Oracle备份与恢复介绍(物理备份与逻辑备份) [3] Oracle备份与恢复案例 [4] ORACLE 备份与恢复 [5] Oracle数据库的备份方法 [6] oracle之rman入门指南 [7] ORACLE RMAN备份及还原 [8] rman备份恢复实例(经典) [9] RMAN 备份详解 [10] RMAN 还原与恢复 [11] RMAN

Oracle RMAN备份深入解析--联机备份

Oracle RMAN备份深入解析--联机备份 RMAN> backup database plus archivelog;    1.首先,进程使用alter system archivelog current命令完成了日志切换操作.    2.进程将现存所有归档重做日志备份    3.开始执行实际的数据库备份操作,此时会发生一次日志切换(alter system archivelog current),同时RMAN备份剩余的归档重做日志(使用backup archivelog all命令).

ORACLE RMAN备份--差异增量与累积增量的策略实例图

转自原文 ORACLE RMAN备份--差异增量与累积增量的策略实例图 BACKUP 命令在不显式指定的情况下,默认情况下会选择Differential方式,即差异增量备份.不过从恢复效率的角度考虑,Cumulative方式的增量备份表现更好一些,毕竟不需要读取那么多备份集了. 注意: 在10g之前的版本中,增量备份可以有 n 多个级别,从0级.1级.2级……这样顺序排列直到 n 级( n 为小于等于4的正整数). 在10g版本中,Oarcle的官方文档明确指出增量备份只有0和1两种级别(太多增

Oracle RMAN备份恢复1-基础篇_超越OCP精通Oracle视频教程培训17

oracle视频教程目标 Oracle视频教程,风哥本套oracle教程培训学习oracle数据库RMAN备份恢复基础,如rman作用与体系架构,nocatalog和catalog介绍与catalog配置,详解rman的使用,详解rman常用的命令list,report, backup,configure,set,crosscheck,validate,change,delete,restore,recover,switch,blockrecover,convert等使用. 适用人群 IT相关从

Oracle RMAN备份恢复2-案例篇_超越OCP精通Oracle视频教程培训18

oracle视频教程目标 Oracle视频教程,风哥本套oracle教程培训学习oracle数据库如何设计一个TB级数据库的RMAN备份策略,RMAN备份与恢复案例-丢失所有文件,丢失单个数据文件,丢失整个数据和system表空间,丢失控制文件和参数文件,存储损坏数据丢失,丢失REDO重做日志文件,基于时间点,scn,cancel,备份控制文件的不完成恢复案例. 适用人群 IT相关从业人员.Oracle数据库技术人员.想加工资的.想升职的都可以. 视频在线学习地址: http://edu.51c

Oracle RMAN备份恢复3-高级篇_超越OCP精通Oracle视频课程培训19

oracle视频教程目标 Oracle视频教程,风哥本套oracle教程培训学习oracle数据库关于RMAN内存缓冲与块跟踪,DBMS_BACKUP_RESTORE,使用RMAN BlockRecover恢复坏块,RMAN Recovery Advisor 案例,RMAN备份压缩技术,RMAN增量备份恢复,RMAN备份加密,RMAN克隆数据库,生产环境RMAN异机恢复的几种经典场景案例 . 适用人群 IT相关从业人员.Oracle数据库技术人员.想加工资的.想升职的都可以. 视频在线学习地址: