Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3127185
  • 博文数量: 206
  • 博客积分: 3409
  • 博客等级: 中校
  • 技术积分: 4066
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 10:21
个人简介

● ITPUB名人堂嘉宾 ● ChinaUnix社区博客专家 ● ChinaUnix社区Oracle板块版主 ● 优酷网认证音乐牛人:EricGuitar ● SDOUG 核心成员 ●E-mail:gaoqiangdba@163.com

文章分类

全部博文(206)

文章存档

2021年(11)

2020年(7)

2019年(7)

2016年(5)

2015年(36)

2014年(23)

2013年(15)

2012年(23)

2011年(61)

2010年(18)

分类: Oracle

2019-06-20 21:29:55

 


实验内容:
  测试Oracle 12C的RMAN备份与恢复功能,包括单独备份PDB和CDB。

实验流程:
  开启归档模式--->全库备份--->备份PDB--->备份根容器--->恢复跟容器--->恢复PDB


操作过程:


开启归档模式:
[oracle@cafe ~]$sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Mon Oct 19 12:14:14 2015

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL>shutdown immediate;   ------开启归档模式需要数据库在mount状态下进行配置,因此先关闭数据库
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL>startup mount;   ----启动到mount状态下
ORACLE instance started.

Total System Global Area  767557632 bytes
Fixed Size            2929112 bytes
Variable Size          599789096 bytes
Database Buffers       54525952 bytes
Redo Buffers            5455872 bytes
In-Memory Area          104857600 bytes
Database mounted.


SQL>alter database archivelog;   -----设置数据库为归档模式

Database altered.


SQL>alter database open;      ------启动数据库

Database altered.

SQL>archive log list;       -----查看数据库归档模式,额一看到归档模式已打开,路径为DB_RECOVERY_FILE_DEST参数所指定的路径
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     24
Next log sequence to archive   26
Current log sequence           26
SQL>     



在PDB中可以看到所有的数据库均已为归档模式:
SQL> alter session set container=tea;

Session altered.

SQL>archive log list;
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     24
Next log sequence to archive   26
Current log sequence           26

SQL> alter session set container=coffee;

Session altered.

SQL>archive log list;
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     24
Next log sequence to archive   26
Current log sequence           26



备份数据库:

[oracle@cafe ~]$rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Mon Oct 19 12:20:07 2015

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

connected to target database: CUP (DBID=3893929652)

RMAN>backup database;         ----基本的数据库备份命令,可以跟多种参数组合写出更细致更智慧的备份命令,也可以写成批处理的备份命令形式,做出更全面的备份方案

Starting backup at 19-OCT-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=237 device type=DISK
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=/oracle/app/oradata/CUP/datafile/o1_mf_system_bch07kvz_.dbf
input datafile file number=00003 name=/oracle/app/oradata/CUP/datafile/o1_mf_sysaux_bch020oo_.dbf
input datafile file number=00004 name=/oracle/app/oradata/CUP/datafile/o1_mf_undotbs1_bch0d2on_.dbf
input datafile file number=00006 name=/oracle/app/oradata/CUP/datafile/o1_mf_users_bch0d15n_.dbf
channel ORA_DISK_1: starting piece 1 at 19-OCT-15
channel ORA_DISK_1: finished piece 1 at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T122017_c28vw24h_.bkp tag=TAG20151019T122017 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:56
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00009 name=/oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_sysaux_bch2qbvh_.dbf
input datafile file number=00008 name=/oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_system_bch2qbrw_.dbf
input datafile file number=00010 name=/oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_users_bch2vth6_.dbf
channel ORA_DISK_1: starting piece 1 at 19-OCT-15
channel ORA_DISK_1: finished piece 1 at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T122017_c28vzomx_.bkp tag=TAG20151019T122017 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00015 name=/oracle/app/oradata/CUP/226DB6EA1DA890CCE0537EE0A8C0080C/datafile/o1_mf_sysaux_c28ryld2_.dbf
input datafile file number=00014 name=/oracle/app/oradata/CUP/226DB6EA1DA890CCE0537EE0A8C0080C/datafile/o1_mf_system_c28rylcy_.dbf
input datafile file number=00016 name=/oracle/app/oradata/CUP/226DB6EA1DA890CCE0537EE0A8C0080C/datafile/o1_mf_users_c28ryld3_.dbf
channel ORA_DISK_1: starting piece 1 at 19-OCT-15
channel ORA_DISK_1: finished piece 1 at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/226DB6EA1DA890CCE0537EE0A8C0080C/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T122017_c28w1qgv_.bkp tag=TAG20151019T122017 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:16
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/oracle/app/oradata/CUP/datafile/o1_mf_sysaux_bch0hgtv_.dbf
input datafile file number=00005 name=/oracle/app/oradata/CUP/datafile/o1_mf_system_bch0hgv5_.dbf
channel ORA_DISK_1: starting piece 1 at 19-OCT-15
channel ORA_DISK_1: finished piece 1 at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/0CAE216DB69417E7E0537EE0A8C00F15/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T122017_c28w43jj_.bkp tag=TAG20151019T122017 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:17
Finished backup at 19-OCT-15

Starting Control File and SPFILE Autobackup at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/autobackup/2015_10_19/o1_mf_s_893507153_c28w6m7f_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 19-OCT-15


单独备份某个PDB:
RMAN>backup pluggable database tea;          -----备份PDB的时候需要添加 “pluggable”

Starting backup at 19-OCT-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00009 name=/oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_sysaux_bch2qbvh_.dbf
input datafile file number=00008 name=/oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_system_bch2qbrw_.dbf
input datafile file number=00010 name=/oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_users_bch2vth6_.dbf
channel ORA_DISK_1: starting piece 1 at 19-OCT-15
channel ORA_DISK_1: finished piece 1 at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T122616_c28w7922_.bkp tag=TAG20151019T122616 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:36
Finished backup at 19-OCT-15

Starting Control File and SPFILE Autobackup at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/autobackup/2015_10_19/o1_mf_s_893507274_c28wbc9z_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 19-OCT-15


备份根容器:
RMAN>backup database root;

Starting backup at 19-OCT-15
using channel ORA_DISK_1
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=/oracle/app/oradata/CUP/datafile/o1_mf_system_bch07kvz_.dbf
input datafile file number=00003 name=/oracle/app/oradata/CUP/datafile/o1_mf_sysaux_bch020oo_.dbf
input datafile file number=00004 name=/oracle/app/oradata/CUP/datafile/o1_mf_undotbs1_bch0d2on_.dbf
input datafile file number=00006 name=/oracle/app/oradata/CUP/datafile/o1_mf_users_bch0d15n_.dbf
channel ORA_DISK_1: starting piece 1 at 19-OCT-15
channel ORA_DISK_1: finished piece 1 at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T123350_c28woh0l_.bkp tag=TAG20151019T123350 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
Finished backup at 19-OCT-15

Starting Control File and SPFILE Autobackup at 19-OCT-15
piece handle=/oracle/app/fast_recovery_area/CUP/autobackup/2015_10_19/o1_mf_s_893507746_c28ws3ch_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 19-OCT-15





Oracle RMAN的备份恢复功能非常强大,在此我们仅用最基本的命令,主要用于让大家有一个PDB和CDB的备份恢复的基本体验,如果有更细化的需求可参考RMAN的手册,也可留言交流,进行更喜欢的定制化脚本编写。

恢复根容器:

[oracle@cafe ~]$ rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Mon Oct 19 12:44:30 2015

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

connected to target database: CUP (DBID=3893929652)

RMAN> shutdown immediate;

using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down

RMAN> startup mount;

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     767557632 bytes

Fixed Size                     2929112 bytes
Variable Size                599789096 bytes
Database Buffers              54525952 bytes
Redo Buffers                   5455872 bytes
In-Memory Area               104857600 bytes

RMAN> restore database root;

Starting restore at 19-OCT-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=12 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 00001 to /oracle/app/oradata/CUP/datafile/o1_mf_system_bch07kvz_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /oracle/app/oradata/CUP/datafile/o1_mf_sysaux_bch020oo_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /oracle/app/oradata/CUP/datafile/o1_mf_undotbs1_bch0d2on_.dbf
channel ORA_DISK_1: restoring datafile 00006 to /oracle/app/oradata/CUP/datafile/o1_mf_users_bch0d15n_.dbf
channel ORA_DISK_1: reading from backup piece /oracle/app/fast_recovery_area/CUP/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T123350_c28woh0l_.bkp



channel ORA_DISK_1: piece handle=/oracle/app/fast_recovery_area/CUP/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T123350_c28woh0l_.bkp tag=TAG20151019T123350
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:56
Finished restore at 19-OCT-15

RMAN>
RMAN>
RMAN>
RMAN> recover database root;

Starting recover at 19-OCT-15
using channel ORA_DISK_1

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

Finished recover at 19-OCT-15

RMAN> alter database open;

Statement processed



恢复PDB:
RMAN> restore pluggable database tea;

Starting restore at 19-OCT-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=262 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 00008 to /oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_system_bch2qbrw_.dbf
channel ORA_DISK_1: restoring datafile 00009 to /oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_sysaux_bch2qbvh_.dbf
channel ORA_DISK_1: restoring datafile 00010 to /oracle/app/oradata/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/datafile/o1_mf_users_bch2vth6_.dbf
channel ORA_DISK_1: reading from backup piece /oracle/app/fast_recovery_area/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T125319_c28xt044_.bkp
channel ORA_DISK_1: piece handle=/oracle/app/fast_recovery_area/CUP/0CAEA15F428B1C4DE0537EE0A8C05257/backupset/2015_10_19/o1_mf_nnndf_TAG20151019T125319_c28xt044_.bkp tag=TAG20151019T125319
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 19-OCT-15

RMAN> recover pluggable database tea;

Starting recover at 19-OCT-15
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01Finished recover at 19-OCT-15

RMAN> alter pluggable database tea open;

Statement processed



  通过实验我们可以发现,尽管在12C中推出了PDB和CDB的概念,但是备份和恢复的命令和流程基本都没有变化,而且依然方便好用。




OK~

阅读(10698) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~