windows bat
1,C:\dba\utility\rman\rman.bat
del C:\dba\utility\rman\full_db_* /q
set TNSNAME=ceipuat
rman target /@%TNSNAME% cmdfile=C:\dba\utility\rman\rman.cmd
2.C:\dba\utility\rman\rman.cmd
backup filesperset = 5 as compressed backupset database format 'C:\dba\utility\rman\full_db_%U' plus archivelog delete all input format 'C:\dba\utility\rman\full_db_arch_%U';
12C引进了pdb的概念,使得rman的恢复相对来说复杂了一些,这里对pdb的常规备份和恢复进行了简单测试,供大家参考
1.cdb启动和pdb关系测试
[oracle@xifenfei tmp]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.0.2 Copyright (c) 1982, 2012, Oracle. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.0.2 With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> startup ORACLE instance started. Total System Global Area 939495424 bytes Fixed Size Variable Size Database Buffers 268435456 Redo Database mounted. Database opened. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID ---------- ---------- 2 3 4 5 SQL> alter pluggable database all open; Pluggable database altered. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID ---------- ---------- 2 3 4 5 |
证明直接startup cdb里面的pdb不会自动open,需要手工进行open
2.rman使用cdb备份数据库
[oracle@xifenfei ~]$ rman target / Recovery Manager: Release 12.1.0.0.2 Copyright (c) 1982, 2012, Oracle and/or its affiliates. All rights reserved. connected to target database: xifenfei RMAN> backup filesperset = 5 as Starting backup at 12-DEC-12 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=259 device channel ORA_DISK_1: starting compressed channel ORA_DISK_1: specifying input datafile file number=00001 name=/u01/app/oracle/oradata/xifenfei/system01.dbf input datafile file number=00010 name=/u01/app/oracle/oradata/xifenfei/LX2/system01.dbf input datafile file number=00011 name=/u01/app/oracle/oradata/xifenfei/LX2/sysaux01.dbf channel ORA_DISK_1: starting piece 1 at channel ORA_DISK_1: finished piece 1 at piece handle=/tmp/full_db_06nsn3uq_1_1 tag=TAG20121212T213626 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45 channel ORA_DISK_1: starting compressed channel ORA_DISK_1: specifying input datafile file number=00019 name=/u01/app/oracle/oradata/xifenfei/xffexample01.dbf input datafile file number=00005 name=/u01/app/oracle/oradata/xifenfei/undotbs01.dbf input datafile file number=00007 name=/u01/app/oracle/oradata/xifenfei/LX1/system01.dbf input datafile file number=00018 input datafile file number=00008 name=/u01/app/oracle/oradata/xifenfei/LX1/sysaux01.dbf channel ORA_DISK_1: starting piece 1 at channel ORA_DISK_1: finished piece 1 at piece handle=/tmp/full_db_07nsn407_1_1 tag=TAG20121212T213626 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45 channel ORA_DISK_1: starting compressed channel ORA_DISK_1: specifying input datafile file number=00017 name=/u01/app/oracle/oradata/xifenfei/xffsysaux01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/xifenfei/pdbseed/system01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/xifenfei/pdbseed/sysaux01.dbf channel ORA_DISK_1: starting piece 1 at channel ORA_DISK_1: finished piece 1 at piece handle=/tmp/full_db_08nsn41l_1_1 tag=TAG20121212T213626 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15 channel ORA_DISK_1: starting compressed channel ORA_DISK_1: specifying input datafile file number=00003 name=/u01/app/oracle/oradata/xifenfei/sysaux01.dbf input datafile file number=00016 name=/u01/app/oracle/oradata/xifenfei/xffsystem01.dbf input datafile file number=00006 name=/u01/app/oracle/oradata/xifenfei/users01.dbf input datafile file number=00009 name=/u01/app/oracle/oradata/xifenfei/LX1/LX1_users01.dbf input datafile file number=00012 name=/u01/app/oracle/oradata/xifenfei/LX2/LX2_users01.dbf channel ORA_DISK_1: starting piece 1 at channel ORA_DISK_1: finished piece 1 at piece handle=/tmp/full_db_09nsn440_1_1 tag=TAG20121212T213626 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45 channel ORA_DISK_1: starting compressed channel ORA_DISK_1: specifying including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at channel ORA_DISK_1: finished piece 1 at piece handle=/tmp/full_db_0ansn45d_1_1 tag=TAG20121212T213626 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 12-DEC-12 RMAN> list backup summary; List of Backups =============== Key TY LV S Device Type ------- -- -- - ----------- 1 2 3 4 5 6 RMAN> report schema; Report of database schema for database with db_unique_name xifenfei List of Permanent Datafiles =========================== File Size(MB) ---- -------- 1 2 3 4 5 6 7 8 9 10 11 12 16 270 17 18 19 List of Temporary Files ======================= File Size(MB) ---- -------- 1 2 3 4 5 |
试验证明:通过rman通过cdb库的备份,可以实现对对应的cdb和所包含的pdb进行备份
3.配置pdb访问tns
[oracle@xifenfei ~]$ lsnrctl status LSNRCTL for Linux: Version 12.1.0.0.2 Copyright (c) 1991, 2012, Oracle. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xifenfei)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias Version Start Uptime Trace Security SNMP Listener Parameter File Listener Log Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xifenfei)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xifenfei)(PORT=5500))(Presentation=HTTP)(Session=RAW)) Services Summary... Service "ff" has 1 instance(s). Instance "xff", Service "xifenfei" has 1 instance(s). Instance "xff", Service "lx1" has 1 instance(s). Instance "xff", Service "lx2" has 1 instance(s). Instance "xff", Service "xffXDB" has 1 instance(s). Instance "xff", The command completed successfully [oracle@xifenfei admin]$ vi tnsnames.ora lx1 = (DESCRIPTION = (ADDRESS = (CONNECT_DATA = (SERVER (SERVICE_NAME ) ) ff = (DESCRIPTION = (ADDRESS = (CONNECT_DATA = (SERVER (SERVICE_NAME ) ) |
sqlplus访问pdb
[oracle@xifenfei admin]$ sqlplus sys@lx1 SQL*Plus: Release 12.1.0.0.2 Copyright (c) 1982, 2012, Oracle. Enter password: Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.0.2 With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> show con_name; CON_NAME ------------------------------ LX1 SQL> create user xff identified by xifenfei; User created. SQL> GRANT SYSDBA TO XFF; Grant succeeded. |
4.rman备份pdb数据库
[oracle@xifenfei admin]$ rman target Recovery Manager: Release 12.1.0.0.2 Copyright (c) 1982, 2012, Oracle and/or its affiliates. All rights reserved. connected to target database: xifenfei RMAN> backup filesperset = 5 as Starting backup at 12-DEC-12 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=256 device channel ORA_DISK_1: starting compressed channel ORA_DISK_1: specifying input datafile file number=00007 name=/u01/app/oracle/oradata/xifenfei/LX1/system01.dbf input datafile file number=00008 name=/u01/app/oracle/oradata/xifenfei/LX1/sysaux01.dbf input datafile file number=00009 name=/u01/app/oracle/oradata/xifenfei/LX1/LX1_users01.dbf channel ORA_DISK_1: starting piece 1 at channel ORA_DISK_1: finished piece 1 at piece handle=/tmp/lx1_db_0bnsn80f_1_1 tag=TAG20121212T224534 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25 Finished backup at 12-DEC-12 RMAN> report schema; Report of database schema for database with db_unique_name xifenfei List of Permanent Datafiles =========================== File Size(MB) ---- -------- 7 8 9 List of Temporary Files ======================= File Size(MB) ---- -------- 3 |
5.rman通过cdb备份pdb
[oracle@xifenfei admin]$ rman target / Recovery Manager: Release 12.1.0.0.2 Copyright (c) 1982, 2012, Oracle and/or its affiliates. All rights reserved. connected to target database: xifenfei RMAN> backup filesperset = 5 as Starting backup at 12-DEC-12 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=262 device channel ORA_DISK_1: starting compressed channel ORA_DISK_1: specifying input datafile file number=00017 name=/u01/app/oracle/oradata/xifenfei/xffsysaux01.dbf input datafile file number=00019 name=/u01/app/oracle/oradata/xifenfei/xffexample01.dbf input datafile file number=00016 name=/u01/app/oracle/oradata/xifenfei/xffsystem01.dbf input datafile file number=00018 name=/u01/app/oracle/oradata/xifenfei/xffSAMPLE_SCHEMA_users01.dbf channel ORA_DISK_1: starting piece 1 at channel ORA_DISK_1: finished piece 1 at piece handle=/tmp/ff_db_0cnsn8vm_1_1 tag=TAG20121212T230214 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26 Finished backup at 12-DEC-12 |
6.模拟pdb库全库恢复
SQL> conn xff/xifenfei@lx1 as sysdba Connected. SQL> create table t_xifenfei as select * from dba_objects; Table created. SQL> select count(*) from t_xifenfei; COUNT(*) ---------- 19121 --在pdb中不能切换日志(因为日志是全局的) SQL> alter system switch logfile; alter system switch logfile * ERROR at line 1: ORA-65040: operation not allowed from within a pluggable database SQL> shutdown immediate; Pluggable Database closed. --删除数据文件 [oracle@xifenfei admin]$ rm --rman基于cdb恢复pdb库 [oracle@xifenfei ~]$ rman target / Recovery Manager: Release 12.1.0.0.2 Copyright (c) 1982, 2012, Oracle and/or its affiliates. All rights connected to target database: xifenfei (DBID=2412861330) RMAN> restore pluggable database lx1; Starting restore at 12-DEC-12 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=25 device channel ORA_DISK_1: starting datafile channel ORA_DISK_1: specifying channel ORA_DISK_1: restoring datafile channel ORA_DISK_1: restoring datafile channel ORA_DISK_1: restoring datafile channel ORA_DISK_1: reading from backup piece /tmp/lx1_db_0bnsn80f_1_1 channel ORA_DISK_1: piece channel ORA_DISK_1: restored backup piece channel ORA_DISK_1: restore complete, Finished restore at 12-DEC-12 RMAN> recover pluggable database lx1; Starting recover at 12-DEC-12 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: Finished recover at 12-DEC-12 RMAN> alter pluggable database lx1 open; Statement processed --验证恢复结果 SQL> conn xff/xifenfei@lx1 as sysdba Connected. SQL> select count(*) from t_xifenfei; COUNT(*) ---------- 19121 |
试验证明:对于pdb库的备份,使用rman可以在cdb级别进行还原和恢复
7.模拟数据文件恢复
SQL> create table t_xifenfei tablespace example 2 as 3 select * from dba_objects; Table created. SQL> select count(*) from t_xifenfei; COUNT(*) ---------- 89604 SQL> col name for a60 SQL> set lines 134 SQL> select file#,name from v$datafile; FILE# NAME ---------- ----------------------------------------------------------- 5 16 17 18 19 --离线含测试数据的数据文件 SQL> alter database datafile 19 offline; Database altered. --删除数据文件 SQL> !rm SQL> !ls -l ls: --尝试pdb级别恢复 [oracle@xifenfei ~]$ rman target Recovery Manager: Release 12.1.0.0.2 Copyright (c) 1982, 2012, Oracle and/or its affiliates. All rights connected to target database: xifenfei (DBID=2412861330) RMAN> restore datafile 19; Starting restore at 12-DEC-12 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=19 device RMAN-00571: RMAN-00569: =============== ERROR MESSAGE RMAN-00571: RMAN-03002: failure of restore command at 12/12/2012 RMAN-06026: some targets not found - aborting restore RMAN-06023: no backup or copy of datafile 19 found to restore --pdb级别不能识别对应数据文件(一种可能是我在cdb级别备份FF库,另一种可能bug) RMAN> list backup of datafile 19; specification does not match any backup in the repository --在cdb级别还原 [oracle@xifenfei tmp]$ rman target / Recovery Manager: Release 12.1.0.0.2 Copyright (c) 1982, 2012, Oracle and/or its affiliates. All rights connected to target database: xifenfei (DBID=2412861330) RMAN> list backup of datafile 19; using target database control file instead of recovery catalog List of Backup Sets =================== BS Key Type LV ------- ---- -- ---------- ----------- 3 BP Piece List of Datafiles in backup set 3 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- 19 BS Key Type LV ------- ---- -- ---------- ----------- 8 BP Piece List of Datafiles in backup set 8 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- 19 RMAN> restore datafile 19; Starting restore at 12-DEC-12 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=28 device channel ORA_DISK_1: starting datafile channel ORA_DISK_1: specifying channel ORA_DISK_1: restoring datafile channel ORA_DISK_1: reading from backup piece /tmp/ff_db_0cnsn8vm_1_1 channel ORA_DISK_1: piece channel ORA_DISK_1: restored backup piece channel ORA_DISK_1: restore complete, Finished restore at 12-DEC-12 --cdb级别恢复数据文件 RMAN> recover datafile 19; Starting recover at 12-DEC-12 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: Finished recover at 12-DEC-12 --cdb级别不能直接online RMAN> alter database datafile 19 online; RMAN-00571: RMAN-00569: =============== ERROR MESSAGE RMAN-00571: RMAN-03002: failure of sql statement command at 12/12/2012 ORA-01516: nonexistent log file, data RMAN> alter pluggable database ff datafile 19 RMAN-00571: RMAN-00569: =============== ERROR MESSAGE RMAN-00571: RMAN-03002: failure of sql statement command at 12/12/2012 ORA-65046: operation not allowed from outside a pluggable database --进入pdb库进行online SQL> alter database datafile 19 Database altered. --验证数据 SQL> select count(*) from t_xifenfei; COUNT(*) ---------- 89604 |
试验证明:rman通过cdb级别操作,还是一步步恢复了pdb中离线异常的数据文件
8.pdb数据库冷备恢复
pdb数据库冷备恢复不需要完全关闭cdb数据库,只需要pdb数据库启动到mounted状态即可。
1.确保需要冷备的pdb1的open mode是mounted状态
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB READ WRITE NO
4 PDB1 MOUNTED
2.备份pdb1
[oracle@ora12c cdb]$ cp -r pdb1 pdb_bak
3.删除pdb1
[oracle@ora12c cdb]$ rm -rf pdb1
4.把pdb1数据库open
SQL> alter pluggable database pdb1 open;
alter pluggable database pdb1 open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 44 - see DBWR trace file
ORA-01110: data file 44: '/u01/app/oracle/oradata/cdb/pdb1/pdb_users01.dbf'
5.利用冷备还原
[oracle@ora12c cdb]$ mv pdb_bak pdb1
6.重新把pdb1数据库open。
SQL> alter pluggable database pdb1 open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB READ WRITE NO
4 PDB1 READ WRITE NO
-------------
pdb数据库冷备恢复不需要完全关闭cdb数据库,只需要pdb数据库启动到mounted状态即可。
1.确保需要冷备的pdb1的open mode是mounted状态
SQL> show pdbs
CON_ID CON_NAME OPEN MODE
RESTRICTED
---------- ------------------------------
---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB READ WRITE NO
4 PDB1 MOUNTED
2.备份pdb1
[oracle@ora12c cdb]$ cp -r pdb1 pdb_bak
3.删除pdb1
[oracle@ora12c cdb]$ rm -rf pdb1
4.把pdb1数据库open
SQL> alter pluggable database pdb1 open;
alter pluggable database pdb1 open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 44 -
see DBWR trace file
ORA-01110: data file 44:
'/u01/app/oracle/oradata/cdb/pdb1/pdb_users01.dbf'
5.利用冷备还原
[oracle@ora12c cdb]$ mv pdb_bak pdb1
6.重新把pdb1数据库open。
SQL> alter pluggable database pdb1 open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE
RESTRICTED
---------- ------------------------------
---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB READ WRITE NO
4 PDB1 READ WRITE NO