botang 发表于 2019-12-28 11:17:40

克隆数据库

run {
allocateauxiliary channel c1 device type disk;
allocateauxiliary channel c2 device type disk;
allocateauxiliary channel c3 device type disk;
allocateauxiliary channel c4 device type disk;
allocateauxiliary channel c5 device type disk;
allocateauxiliary channel c6 device type disk;
allocateauxiliary channel c7 device type disk;
allocateauxiliary channel c8 device type disk;
allocate   channel a1 device type disk;
allocate   channel a2 device type disk;
allocate   channel a3 device type disk;
allocate   channel a4 device type disk;
allocate   channel a5 device type disk;
allocate   channel a6 device type disk;
allocate   channel a7 device type disk;
allocate   channel a8 device type disk;

duplicate target database to clone1
from active database
nofilenamecheck
skip tablespace tbstrans2
spfile
set
memory_target='700M'
set
control_files='+DATA','+FRA'
set
db_file_name_convert='+DATA/orcl','+DATA/clone1'
set
log_file_name_convert='+DATA/orcl','+DATA/clone1','+FRA/orcl','+FRA/clone1'
set
audit_file_dest='/u01/app/oracle/admin/clone1/adump';
}
$ pwd
/u01/app/oracle/product/11.2.0/dbhome_1/network/admin
$ cd ..
$ ls
admindocinstalljlibliblogmesgtoolstrace
$ cd ..
$ ls
apex         crs      demo         install      jlib   nls         oraInst.locracg          sqlplus                     usm
assistants   csmig      diagnosticsinstantclientldap   oc4j      ord          rdbms         srvm                        utl
bin          css      dv         inventory      lib      odbc      oui          relnotes      station76.example.com_orclwwg
ccr          ctx      emcli      j2ee         log      olap      owb          root.sh       suptools                  xdk
cdata      cv         EMStage      javavm         md       OPatch      owm          scheduler   sysman
cfgtoollogsdbs      has          jdbc         mesg   OPatch.oriperl         slax          timingframework
clone      dc_ocm   hs         jdev         mgw      opmn      plsql      sqldeveloperucp
config       deinstallide          jdk            networkoracore   precomp      sqlj          uix
$ cd dbs
$ ls
hc_apple.dat   hc_mydb2.dathc_rcat.datinitorcl.oralkMYDB2lkRCAT   orapworclsnapcf_orcl.fspfilercat.ora
hc_dbtest.dathc_orcl.dat   init.ora   lkinstdbtestlkORCL   lkWINORCLorapwrcatsnapcf_rcat.f
$ vim initclone1.ora
db_name=clone1
db_domain=example.com
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"initclone1.ora" 2L, 37C written                                                                           
$ vim initclone2.ora
db_name=clone2
db_domain=example.com
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"initclone2.ora" 2L, 37C written                                                                           
$ orapwd file=orapwclone1password=oracle_4U
$ orapwd file=orapwclone2password=oracle_4U
$ cd /u01/app/
$ ls
oracleoraInventory
$ cd oracle
$ ls
admin      cfgtoollogsClusterwaredirlin            flash_recovery_areaproduct    wallet
botangdir01checkpointsdiag         fast_recovery_areaoradata            station76
$ cd admin/
$ ls
+ASMclone1dbtestmydb2orclrcat
$ cd clone1/
$ ls
adump
$ cd ..
$ ls
+ASMclone1dbtestmydb2orclrcat
$ mkdir -pclone2/adump
$ exit
logout
# vim /etc/oratab
#Backup file is/u01/app/oracle/product/11.2.0/grid/srvm/admin/oratab.bak.station76 line added by Agent
#



# This file is used by ORACLE utilities.It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# A colon, ':', is used as the field terminator.A new line terminates
# the entry.Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
+ASM:/u01/app/oracle/product/11.2.0/grid:N
rcat:/u01/app/oracle/product/11.2.0/dbhome_1:N          # line added by Agent
orcl:/u01/app/oracle/product/11.2.0/dbhome_1:N          # line added by Agent
clone1:/u01/app/oracle/product/11.2.0/dbhome_1:N                # line added by Agent
clone2:/u01/app/oracle/product/11.2.0/dbhome_1:N                # line added by Agent
~
~
~
~
~
~
~
~
"/etc/oratab" 28L, 1173C written                                                                                 
# su - oracle
$ . oraenv
ORACLE_SID = ? clone1
The Oracle base remains unchanged with value /u01/app/oracle
$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 26 04:15:30 2019

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

SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area263090176 bytes
Fixed Size                  2252256 bytes
Variable Size             205521440 bytes
Database Buffers         50331648 bytes
Redo Buffers                4984832 bytes
ORA-00205: error in identifying control file, check alert log for more info


SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
$ rman target sys/oracle_4U@orclauxiliary sys/oracle_4U@clone1

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Dec 26 04:16:20 2019

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

connected to target database: ORCL (DBID=1554722616)
connected to auxiliary database: CLONE1 (not mounted)

RMAN>
用备份冷克隆:
先备份:
run {
allocate channelc1 device type disk format '/home/oracle/clone1/%U';
allocate channelc2 device type disk format '/home/oracle/clone1/%U';
allocate channelc3 device type disk format '/home/oracle/clone1/%U';
allocate channelc4 device type disk format '/home/oracle/clone1/%U';
allocate channelc5 device type disk format '/home/oracle/clone1/%U';
allocate channelc6 device type disk format '/home/oracle/clone1/%U';
allocate channelc7 device type disk format '/home/oracle/clone1/%U';
allocate channelc8 device type disk format '/home/oracle/clone1/%U';
backup database plus archivelog force;
backup spfile force;
backup current controlfile force;
}
run {
allocateauxiliary channel c1 device type disk;
allocateauxiliary channel c2 device type disk;
allocateauxiliary channel c3 device type disk;
allocateauxiliary channel c4 device type disk;
allocateauxiliary channel c5 device type disk;
allocateauxiliary channel c6 device type disk;
allocateauxiliary channel c7 device type disk;
allocateauxiliary channel c8 device type disk;
duplicate database to clone2
backup location '/home/oracle/clone1'
nofilenamecheck
skip tablespace tbstrans2
db_file_name_convert '+DATA/orcl','+DATA/clone2'
logfile
group 1 ('+DATA','+FRA') size 50M,
group 2 ('+DATA','+FRA') size 50M,
group 3 ('+DATA','+FRA') size 50M
spfile
parameter_value_convert '+DATA/orcl','+DATA/clone2','+FRA/orcl','+FRA/clone2','/u01/app/oracle/admin/orcl/adump','/u01/app/oracle/admin/clone2/adump'
set
control_files='+DATA','+FRA'
set
memory_target='700M';
}
$ rman auxiliary sys/oracle_4U@clone2 cmdfile=/home/oracle/clone2.rcv

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Dec 26 10:10:27 2019

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

connected to auxiliary database: CLONE2 (not mounted)

RMAN> run {
2> allocateauxiliary channel c1 device type disk;
3> allocateauxiliary channel c2 device type disk;
4> allocateauxiliary channel c3 device type disk;
5> allocateauxiliary channel c4 device type disk;
6> allocateauxiliary channel c5 device type disk;
7> allocateauxiliary channel c6 device type disk;
8> allocateauxiliary channel c7 device type disk;
9> allocateauxiliary channel c8 device type disk;
10> duplicate database to clone2
11> backup location '/home/oracle/clone1'
12> nofilenamecheck
13> skip tablespace tbstrans2
14> db_file_name_convert '+DATA/orcl','+DATA/clone2'
15> logfile
16> group 1 ('+DATA','+FRA') size 50M,
17> group 2 ('+DATA','+FRA') size 50M,
18> group 3 ('+DATA','+FRA') size 50M
19> spfile
20> parameter_value_convert '+DATA/orcl','+DATA/clone2','+FRA/orcl','+FRA/clone2','/u01/app/oracle/admin/orcl/adump','/u01/app/oracle/admin/clone2/adump'
21> set
22> control_files='+DATA','+FRA'
23> set
24> memory_target='700M';
25> }
26>
allocated channel: c1
channel c1: SID=429 device type=DISK

allocated channel: c2
channel c2: SID=5 device type=DISK

allocated channel: c3
channel c3: SID=146 device type=DISK

allocated channel: c4
channel c4: SID=288 device type=DISK

allocated channel: c5
channel c5: SID=430 device type=DISK

allocated channel: c6
channel c6: SID=6 device type=DISK

allocated channel: c7
channel c7: SID=147 device type=DISK

allocated channel: c8
channel c8: SID=289 device type=DISK

Starting Duplicate Db at 2019-12-26:10:10:50

contents of Memory Script:
{
   restore clone spfile to'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileclone2.ora' from
'/home/oracle/clone1/4iukc5nj_1_1';
   sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileclone2.ora''";
}
executing Memory Script

Starting restore at 2019-12-26:10:10:51

channel c2: skipped, AUTOBACKUP already found
channel c3: skipped, AUTOBACKUP already found
channel c4: skipped, AUTOBACKUP already found
channel c5: skipped, AUTOBACKUP already found
channel c6: skipped, AUTOBACKUP already found
channel c7: skipped, AUTOBACKUP already found
channel c8: skipped, AUTOBACKUP already found
channel c1: restoring spfile from AUTOBACKUP /home/oracle/clone1/4iukc5nj_1_1
channel c1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2019-12-26:10:11:03

sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileclone2.ora''

contents of Memory Script:
{
   sql clone "alter system setdb_name =
''CLONE2'' comment=
''duplicate'' scope=spfile";
   sql clone "alter system setcontrol_files =
''+DATA'', ''+FRA'' comment=
'''' scope=spfile";
   sql clone "alter system setmemory_target =
700M comment=
'''' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system setdb_name =''CLONE2'' comment= ''duplicate'' scope=spfile

sql statement: alter system setcontrol_files =''+DATA'', ''+FRA'' comment= '''' scope=spfile

sql statement: alter system setmemory_target =700M comment= '''' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area   730714112 bytes

Fixed Size                     2256832 bytes
Variable Size                486539328 bytes
Database Buffers             234881024 bytes
Redo Buffers                   7036928 bytes
allocated channel: c1
channel c1: SID=68 device type=DISK
allocated channel: c2
channel c2: SID=131 device type=DISK
allocated channel: c3
channel c3: SID=192 device type=DISK
allocated channel: c4
channel c4: SID=8 device type=DISK
allocated channel: c5
channel c5: SID=69 device type=DISK
allocated channel: c6
channel c6: SID=132 device type=DISK
allocated channel: c7
channel c7: SID=193 device type=DISK
allocated channel: c8
channel c8: SID=9 device type=DISK

contents of Memory Script:
{
   sql clone "alter system setcontrol_files =
''+DATA/clone2/controlfile/current.276.1028023901'', ''+FRA/clone2/controlfile/current.479.1028023903'' comment=
''Set by RMAN'' scope=spfile";
   sql clone "alter system setdb_name =
''ORCL'' comment=
''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system setdb_unique_name =
''CLONE2'' comment=
''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile from'/home/oracle/clone1/4jukc5nk_1_1';
   alter clone database mount;
}
executing Memory Script

sql statement: alter system setcontrol_files =   ''+DATA/clone2/controlfile/current.276.1028023901'', ''+FRA/clone2/controlfile/current.479.1028023903'' comment= ''Set by RMAN'' scope=spfile

sql statement: alter system setdb_name =''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system setdb_unique_name =''CLONE2'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area   730714112 bytes

Fixed Size                     2256832 bytes
Variable Size                486539328 bytes
Database Buffers             234881024 bytes
Redo Buffers                   7036928 bytes
allocated channel: c1
channel c1: SID=68 device type=DISK
allocated channel: c2
channel c2: SID=131 device type=DISK
allocated channel: c3
channel c3: SID=192 device type=DISK
allocated channel: c4
channel c4: SID=8 device type=DISK
allocated channel: c5
channel c5: SID=69 device type=DISK
allocated channel: c6
channel c6: SID=132 device type=DISK
allocated channel: c7
channel c7: SID=193 device type=DISK
allocated channel: c8
channel c8: SID=9 device type=DISK

Starting restore at 2019-12-26:10:12:27

channel c2: skipped, AUTOBACKUP already found
channel c3: skipped, AUTOBACKUP already found
channel c4: skipped, AUTOBACKUP already found
channel c5: skipped, AUTOBACKUP already found
channel c6: skipped, AUTOBACKUP already found
channel c7: skipped, AUTOBACKUP already found
channel c8: skipped, AUTOBACKUP already found
channel c1: restoring control file
channel c1: restore complete, elapsed time: 00:00:11
output file name=+DATA/clone2/controlfile/current.276.1028023901
output file name=+FRA/clone2/controlfile/current.479.1028023903
Finished restore at 2019-12-26:10:12:45

database mounted
Not connected to TARGET or TARGET not open, cannot verify that subset of tablespaces is self-contained
Not connected to TARGET, cannot verify that set of tablespaces being duplicated does not have SYS objects
Datafile 6 skipped by request
RMAN-05529: WARNING: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.

contents of Memory Script:
{
   set until scn1623324;
   set newname for datafile1 to
"+data";
   set newname for datafile2 to
"+data";
   set newname for datafile3 to
"+data";
   set newname for datafile4 to
"+data";
   set newname for datafile5 to
"+data";
   restore
   clone database
   skip forever tablespace"TBSTRANS2"   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2019-12-26:10:12:57

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00005 to +data
channel c1: reading from backup piece /home/oracle/clone1/4cukc5mt_1_1
channel c2: starting datafile backup set restore
channel c2: specifying datafile(s) to restore from backup set
channel c2: restoring datafile 00001 to +data
channel c2: reading from backup piece /home/oracle/clone1/49ukc5ms_1_1
channel c3: starting datafile backup set restore
channel c3: specifying datafile(s) to restore from backup set
channel c3: restoring datafile 00002 to +data
channel c3: reading from backup piece /home/oracle/clone1/4aukc5ms_1_1
channel c4: starting datafile backup set restore
channel c4: specifying datafile(s) to restore from backup set
channel c4: restoring datafile 00003 to +data
channel c4: reading from backup piece /home/oracle/clone1/4bukc5ms_1_1
channel c5: starting datafile backup set restore
channel c5: specifying datafile(s) to restore from backup set
channel c5: restoring datafile 00004 to +data
channel c5: reading from backup piece /home/oracle/clone1/4fukc5mu_1_1
channel c1: piece handle=/home/oracle/clone1/4cukc5mt_1_1 tag=TAG20191226T043226
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:02
channel c5: piece handle=/home/oracle/clone1/4fukc5mu_1_1 tag=TAG20191226T043226
channel c5: restored backup piece 1
channel c5: restore complete, elapsed time: 00:00:01
channel c4: piece handle=/home/oracle/clone1/4bukc5ms_1_1 tag=TAG20191226T043226
channel c4: restored backup piece 1
channel c4: restore complete, elapsed time: 00:00:04
channel c2: piece handle=/home/oracle/clone1/49ukc5ms_1_1 tag=TAG20191226T043226
channel c2: restored backup piece 1
channel c2: restore complete, elapsed time: 00:00:17
channel c3: piece handle=/home/oracle/clone1/4aukc5ms_1_1 tag=TAG20191226T043226
channel c3: restored backup piece 1
channel c3: restore complete, elapsed time: 00:00:17
Finished restore at 2019-12-26:10:13:18

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=6 STAMP=1028023998 file name=+DATA/clone2/datafile/system.278.1028023981
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=1028023998 file name=+DATA/clone2/datafile/sysaux.256.1028023983
datafile 3 switched to datafile copy
input datafile copy RECID=8 STAMP=1028023999 file name=+DATA/clone2/datafile/undotbs1.272.1028023983
datafile 4 switched to datafile copy
input datafile copy RECID=9 STAMP=1028023999 file name=+DATA/clone2/datafile/users.284.1028023983
datafile 5 switched to datafile copy
input datafile copy RECID=10 STAMP=1028023999 file name=+DATA/clone2/datafile/tbstrans1.275.1028023981

contents of Memory Script:
{
   set until scn1623324;
   recover
   clone database
   skip forever tablespace"TBSTRANS2"    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 2019-12-26:10:13:21

Executing: alter database datafile 6 offline drop
starting media recovery

channel c1: starting archived log restore to default destination
channel c1: restoring archived log
archived log thread=1 sequence=30
channel c1: reading from backup piece /home/oracle/clone1/4hukc5nh_1_1
channel c1: piece handle=/home/oracle/clone1/4hukc5nh_1_1 tag=TAG20191226T043248
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
archived log file name=+FRA/clone2/archivelog/2019_12_26/thread_1_seq_30.478.1028024009 thread=1 sequence=30
channel clone_default: deleting archived log(s)
archived log file name=+FRA/clone2/archivelog/2019_12_26/thread_1_seq_30.478.1028024009 RECID=1 STAMP=1028024009
media recovery complete, elapsed time: 00:00:02
Finished recover at 2019-12-26:10:13:32
Oracle instance started

Total System Global Area   730714112 bytes

Fixed Size                     2256832 bytes
Variable Size                486539328 bytes
Database Buffers             234881024 bytes
Redo Buffers                   7036928 bytes

contents of Memory Script:
{
   sql clone "alter system setdb_name =
''CLONE2'' comment=
''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system resetdb_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system setdb_name =''CLONE2'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system resetdb_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area   730714112 bytes

Fixed Size                     2256832 bytes
Variable Size                486539328 bytes
Database Buffers             234881024 bytes
Redo Buffers                   7036928 bytes
allocated channel: c1
channel c1: SID=70 device type=DISK
allocated channel: c2
channel c2: SID=131 device type=DISK
allocated channel: c3
channel c3: SID=192 device type=DISK
allocated channel: c4
channel c4: SID=6 device type=DISK
allocated channel: c5
channel c5: SID=71 device type=DISK
allocated channel: c6
channel c6: SID=132 device type=DISK
allocated channel: c7
channel c7: SID=193 device type=DISK
allocated channel: c8
channel c8: SID=7 device type=DISK
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CLONE2" RESETLOGS ARCHIVELOG
MAXLOGFILES   16
MAXLOGMEMBERS      3
MAXDATAFILES      100
MAXINSTANCES   8
MAXLOGHISTORY      292
LOGFILE
GROUP   1 ( '+DATA', '+FRA' ) SIZE 50 M ,
GROUP   2 ( '+DATA', '+FRA' ) SIZE 50 M ,
GROUP   3 ( '+DATA', '+FRA' ) SIZE 50 M
DATAFILE
'+DATA/clone2/datafile/system.278.1028023981'
CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile1 to
"+data";
   switch clone tempfile all;
   catalog clone datafilecopy"+DATA/clone2/datafile/sysaux.256.1028023983",
"+DATA/clone2/datafile/undotbs1.272.1028023983",
"+DATA/clone2/datafile/users.284.1028023983",
"+DATA/clone2/datafile/tbstrans1.275.1028023981";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to +data in control file

cataloged datafile copy
datafile copy file name=+DATA/clone2/datafile/sysaux.256.1028023983 RECID=1 STAMP=1028024100
cataloged datafile copy
datafile copy file name=+DATA/clone2/datafile/undotbs1.272.1028023983 RECID=2 STAMP=1028024100
cataloged datafile copy
datafile copy file name=+DATA/clone2/datafile/users.284.1028023983 RECID=3 STAMP=1028024101
cataloged datafile copy
datafile copy file name=+DATA/clone2/datafile/tbstrans1.275.1028023981 RECID=4 STAMP=1028024101

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=1028024100 file name=+DATA/clone2/datafile/sysaux.256.1028023983
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=1028024100 file name=+DATA/clone2/datafile/undotbs1.272.1028023983
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=1028024101 file name=+DATA/clone2/datafile/users.284.1028023983
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=1028024101 file name=+DATA/clone2/datafile/tbstrans1.275.1028023981

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Dropping offline and skipped tablespaces
Executing: drop tablespace "TBSTRANS2" including contents cascade constraints
Finished Duplicate Db at 2019-12-26:10:16:18
released channel: c1
released channel: c2
released channel: c3
released channel: c4
released channel: c5
released channel: c6
released channel: c7
released channel: c8

Recovery Manager complete.
$

页: [1]
查看完整版本: 克隆数据库