Direct NFS (DNFS) Clonedb in Oracle Database 11.2.0.2.0 version above

Duplicate a Database Using RMAN in Oracle Database 10g Release 2


Clonedb is a new Direct NFS (DNFS) feature introduced in the 11.2.0.2 database patchset. Rather than using the traditional RMAN database duplication, clonedb uses dNFS technology to instantly fire up a clone using an existing backup of a database as the data store. The clone uses copy-on-write technology, so only changed blocks need to be stored locally, while the unchanged data is referenced directly from the backup files. This drastically increases the speed of cloning a system and means that several separate clones can function against a single set of backup datafiles, thus saving considerable amounts of space.


Production Database Server: 
Name       : zhongwc
IP Address : 192.168.1.101
ORACLE_HOME: /u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_SID : zhongwc

Clonedb Database Server:
Name       : clonedb
IP Address : 192.168.1.102
ORACLE_HOME: /u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_SID : clonedb
NFS Mount  : /u01/app/oracle/oradata/clonedb

NFS Server :
Name       : dnfs
IP Address : 192.168.1.103
NFS share  : /u01/nfs_shares/clonedb


On the NFS server, create a directory as the copy-on-write location for the cloned instance.

[root@dnfs ~]# mkdir -p /u01/nfs_shares/clonedb

Export the directory as an NFS share by adding the following lines to the "/etc/exports" file.

[root@dnfs ~]# cat /etc/exports 
/u01/nfs_shares/clonedb        *(rw,sync,no_wdelay,insecure,insecure_locks,no_root_squash)

Make sure the NFS service is available after reboot and restart the NFS service.

[root@dnfs ~]# /etc/init.d/nfs restart
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS quotas:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
[root@dnfs ~]# chkconfig nfs on

We have to take an image copy of the database using RMAN.

[oracle@prodServer backup]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Mon Mar 4 15:03:10 2013

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

connected to target database: ZHONGWC (DBID=184072095)

RMAN> run
2> {
3> configure controlfile autobackup off;
4> sql 'alter database begin backup';
5> set nocfau;
6> backup as copy database format '/u01/app/backup/%U' tag 'copyfull';
7> sql 'alter database end backup';
8> }

using target database control file instead of recovery catalog
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters are successfully stored

sql statement: alter database begin backup

executing command: SET NOCFAU

Starting backup at 04-MAR-2013 15:06:56
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=38 device type=DISK
RMAN-06554: WARNING: file 1 is in backup mode
RMAN-06554: WARNING: file 2 is in backup mode
RMAN-06554: WARNING: file 3 is in backup mode
RMAN-06554: WARNING: file 4 is in backup mode
RMAN-06554: WARNING: file 5 is in backup mode
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/zhongwc/system01.dbf
output file name=/u01/app/backup/data_D-ZHONGWC_I-184072095_TS-SYSTEM_FNO-1_01o3mh0h tag=COPYFULL RECID=2 STAMP=809190437
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/zhongwc/sysaux01.dbf
output file name=/u01/app/backup/data_D-ZHONGWC_I-184072095_TS-SYSAUX_FNO-2_02o3mh1a tag=COPYFULL RECID=3 STAMP=809190457
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/zhongwc/example01.dbf
output file name=/u01/app/backup/data_D-ZHONGWC_I-184072095_TS-EXAMPLE_FNO-5_03o3mh1p tag=COPYFULL RECID=4 STAMP=809190465
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/zhongwc/undotbs01.dbf
output file name=/u01/app/backup/data_D-ZHONGWC_I-184072095_TS-UNDOTBS1_FNO-3_04o3mh28 tag=COPYFULL RECID=5 STAMP=809190474
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/zhongwc/users01.dbf
output file name=/u01/app/backup/data_D-ZHONGWC_I-184072095_TS-USERS_FNO-4_05o3mh2b tag=COPYFULL RECID=6 STAMP=809190475
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 04-MAR-2013 15:07:56

sql statement: alter database end backup

create a PFILE from the contents of the production SPFILE.

SQL> create pfile='/u01/app/backup/initclonedb.ora' from spfile;

File created.

Amend the contents of the PFILE to reflect the clone database. Here is the amended PFILE I used. In this case my original database name was zhongwc, so I have replaced all references to that database name with clonedb.

[oracle@prodServer ~]$ cat /u01/app/backup/initclonedb.ora 
clonedb.__db_cache_size=293601280
clonedb.__java_pool_size=4194304
clonedb.__large_pool_size=4194304
clonedb.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
clonedb.__pga_aggregate_target=335544320
clonedb.__sga_target=503316480
clonedb.__shared_io_pool_size=0
clonedb.__shared_pool_size=192937984
clonedb.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/clonedb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/clonedb/control01.ctl','/u01/app/oracle/oradata/clonedb/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='clonedb'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=10737418240
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=clonedbXDB)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/arch'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=836763648
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='AMERICA'
*.open_cursors=300
*.processes=800
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=885
*.undo_tablespace='UNDOTBS1'

Make sure the Direct NFS client is enabled for the Oracle home on the server that will run the clone.

[oracle@cloneServer ~]$ cd $ORACLE_HOME/rdbms/lib
[oracle@cloneServer lib]$ make -f ins_rdbms.mk dnfs_on
rm -f /u01/app/oracle/product/11.2.0/dbhome_1/lib/libodm11.so; cp /u01/app/oracle/product/11.2.0/dbhome_1/lib/libnfsodm11.so /u01/app/oracle/product/11.2.0/dbhome_1/lb/libodm11.so

Make directories for the NFS mount point, along with some others needed by the clonedb instance.

[oracle@cloneServer ~]$ mkdir -p $ORACLE_BASE/oradata/clonedb
[oracle@cloneServer ~]$ mkdir -p $ORACLE_BASE/fast_recovery_area/clonedb
[oracle@cloneServer ~]$ mkdir -p $ORACLE_BASE/admin/clonedb/adump
[oracle@cloneServer ~]$ mkdir -p $ORACLE_BASE/admin/clonedb/dpdump

Add the following line into the "/etc/fstab" file so the share is mounted automatically on reboot.

[root@cloneServer ~]# tail  -1 /etc/fstab 
dnfs:/u01/nfs_shares/clonedb /u01/app/oracle/oradata/clonedb  nfs  rw,bg,hard,nointr,tcp,vers=3,timeo=600,rsize=32768,wsize=32768,actimeo=0  0 0

Mount the backup share. If you are consistent with the UID of the OS "oracle" user the ownership and permissions should be fine.

[root@cloneServer ~]# mount /u01/app/oracle/oradata/clonedb
[root@cloneServer ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       93G  9.2G   80G  11% /
/dev/sda1              99M   23M   71M  25% /boot
tmpfs                1000M     0 1000M   0% /dev/shm
dnfs:/u01/nfs_shares/clonedb
                       37G  2.6G   33G   8% /u01/app/oracle/oradata/clonedb


Set the following environment variables to the appropriate values for your setup.

MASTER_COPY_DIR=/u01/app/oracle/backup; export MASTER_COPY_DIR
CLONE_FILE_CREATE_DEST=/u01/app/oracle/oradata/clonedb; export CLONE_FILE_CREATE_DEST
CLONEDB_NAME=clonedb; export CLONEDB_NAME


Move the PFILE to the "$ORACLE_HOME/dbs" directory.

[oracle@prodServer ~]$ scp /u01/app/backup/initclonedb.ora oracle@192.168.1.102:/u01/app/oracle/product/11.2.0/dbhome_1/dbs
oracle@192.168.1.102's password: 
initclonedb.ora                                                                                                                     100% 1100     1.1KB/s   00:00    


Remove everything other than datafile image copies from the backup directory. If other file types are present, a later script will assume they are datafiles when creating the new controlfile. The contents of my backup directory is displayed below.

[oracle@prodServer ~]$ scp /u01/app/backup/* oracle@192.168.1.102:/u01/app/oracle/backup
oracle@192.168.1.102's password: 
data_D-ZHONGWC_I-184072095_TS-EXAMPLE_FNO-5_03o3mh1p                                                                                 100%  313MB  52.2MB/s   00:06    
data_D-ZHONGWC_I-184072095_TS-SYSAUX_FNO-2_02o3mh1a                                                                                  100%  540MB  20.8MB/s   00:26    
data_D-ZHONGWC_I-184072095_TS-SYSTEM_FNO-1_01o3mh0h                                                                                  100%  710MB  19.2MB/s   00:37    
data_D-ZHONGWC_I-184072095_TS-UNDOTBS1_FNO-3_04o3mh28                                                                                100%  105MB  17.5MB/s   00:06    
data_D-ZHONGWC_I-184072095_TS-USERS_FNO-4_05o3mh2b                                                                                   100% 5128KB   5.0MB/s   00:00

Switch to the "/tmp" directory and run the "clonedb.pl" script, naming the correct "init.ora" file to start the instance and specifying name for the cloning script it will create.

[oracle@cloneServer tmp]$ perl /u01/app/oracle/Clone.pl /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initclonedb.ora crtdb.sql dbren.sql
[oracle@cloneServer tmp]$ ls -l
[oracle@cloneServer tmp]$ ls -l *.sql
-rw-r--r-- 1 oracle oinstall 919 Mar  4 15:40 crtdb.sql
-rw-r--r-- 1 oracle oinstall 962 Mar  4 15:40 dbren.sql

Start SQL*Plus as SYSDBA and run the scripts created by the "clone.pl" script. The cloning script contains a generated CREATE CONTROLFILE command and calls to DBMS_DNFS.CLONEDB_RENAMEFILE to associate the copy-on-write location with the backup datafile.

[oracle@cloneServer dbs]$ mv initclonedb.ora /u01/app/oracle/oradata/clonedb
[oracle@cloneServer tmp]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Mar 4 15:46:45 2013

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

Connected to an idle instance.

SQL> @crtdb
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL> 
SQL> STARTUP NOMOUNT PFILE=/u01/app/oracle/oradata/clonedb/initclonedb.ora
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2232960 bytes
Variable Size             536874368 bytes
Database Buffers          293601280 bytes
Redo Buffers                2396160 bytes
SQL> CREATE CONTROLFILE REUSE SET DATABASE clonedb RESETLOGS
  2      MAXLOGFILES 32
  3      MAXLOGMEMBERS 2
  4      MAXINSTANCES 1
  5      MAXLOGHISTORY 908
  6  LOGFILE
  7    GROUP 1 '/u01/app/oracle/oradata/clonedb/clonedb_log1.log' SIZE 100M BLOCKSIZE 512,
  8    GROUP 2 '/u01/app/oracle/oradata/clonedb/clonedb_log2.log' SIZE 100M BLOCKSIZE 512
  9  DATAFILE
 10  '/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-EXAMPLE_FNO-5_03o3mh1p',
 11  '/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-SYSAUX_FNO-2_02o3mh1a',
 12  '/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-SYSTEM_FNO-1_01o3mh0h',
 13  '/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-UNDOTBS1_FNO-3_04o3mh28',
 14  '/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-USERS_FNO-4_05o3mh2b'
 15  CHARACTER SET WE8DEC;

Control file created.

SQL> @dbren
SQL> declare
  2  begin
  3  dbms_dnfs.clonedb_renamefile('/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-EXAMPLE_FNO-5_03o3mh1p' , '/u01/app/oracle/oradata/clonedb/ora_data_clonedb0.dbf');
  4  dbms_dnfs.clonedb_renamefile('/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-SYSAUX_FNO-2_02o3mh1a' , '/u01/app/oracle/oradata/clonedb/ora_data_clonedb1.dbf');
  5  dbms_dnfs.clonedb_renamefile('/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-SYSTEM_FNO-1_01o3mh0h' , '/u01/app/oracle/oradata/clonedb/ora_data_clonedb2.dbf');
  6  dbms_dnfs.clonedb_renamefile('/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-UNDOTBS1_FNO-3_04o3mh28' , '/u01/app/oracle/oradata/clonedb/ora_data_clonedb3.dbf');
  7  dbms_dnfs.clonedb_renamefile('/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-USERS_FNO-4_05o3mh2b' , '/u01/app/oracle/oradata/clonedb/ora_data_clonedb4.dbf');
  8  end;
  9  /
declare
*
ERROR at line 1:
ORA-01511: error in renaming log/data files
ORA-01141: error renaming data file 5 - new file
'/u01/app/oracle/oradata/clonedb/ora_data_clonedb0.dbf' not found
ORA-01110: data file 5:
'/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-EXAMPLE_FNO-5_03o3mh1p'
ORA-17515: Creation of clonedb failed using snapshot file
/u01/app/oracle/backup/data_D-ZHONGWC_I-184072095_TS-EXAMPLE_FNO-5_03o3mh1p
ORA-06512: at "SYS.X$DBMS_DNFS", line 10
ORA-06512: at line 3


SQL> show errors;
No errors.
SQL> alter database open resetlogs;

Database altered.

SQL> drop tablespace TEMP;
drop tablespace TEMP
*
ERROR at line 1:
ORA-12906: cannot drop default temporary tablespace


SQL> create temporary tablespace TEMP;
create temporary tablespace TEMP
                               *
ERROR at line 1:
ORA-02199: missing DATAFILE/TEMPFILE clause



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值