ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 使用RMAN复制数据库到同一台机器

使用RMAN复制数据库到同一台机器

原创 Linux操作系统 作者:xuyongw2000 时间:2012-01-09 14:45:18 0 删除 编辑
实验环境:
oracle version: 10.2.0.1
oracle home : /usr/local/oracle/10g
oracle sid: test ,dupdp
1、使用RMAN备份原数据库
[oracle@test backup]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Wed Dec 28 17:22:06 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: TEST (DBID=2069242183)
RMAN> backup format='/usr/local/oracle/backup/%d_%s.dbf' database include current controlfile plus archivelog;

Starting backup at 28-DEC-11
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=142 devtype=DISK
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=2 recid=1 stamp=771096133
channel ORA_DISK_1: starting piece 1 at 28-DEC-11
channel ORA_DISK_1: finished piece 1 at 28-DEC-11
piece handle=/usr/local/oracle/backup/TEST_1.dbf tag=TAG20111228T172214 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 28-DEC-11
Starting backup at 28-DEC-11
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/usr/local/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/usr/local/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/usr/local/oracle/oradata/test/example01.dbf
input datafile fno=00002 name=/usr/local/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/usr/local/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 28-DEC-11
channel ORA_DISK_1: finished piece 1 at 28-DEC-11
piece handle=/usr/local/oracle/backup/TEST_2.dbf tag=TAG20111228T172215 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 28-DEC-11
channel ORA_DISK_1: finished piece 1 at 28-DEC-11
piece handle=/usr/local/oracle/backup/TEST_3.dbf tag=TAG20111228T172215 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 28-DEC-11
Starting backup at 28-DEC-11
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=3 recid=2 stamp=771096163
channel ORA_DISK_1: starting piece 1 at 28-DEC-11
channel ORA_DISK_1: finished piece 1 at 28-DEC-11
piece handle=/usr/local/oracle/backup/TEST_4.dbf tag=TAG20111228T172243 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 28-DEC-11
2、准备复制库的spfile文件
[oracle@test dbs]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Dec 28 17:23:47 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create pfile='/usr/local/oracle/10g/dbs/initdupdb.ora' from spfile;
File created.
SQL>
把所有test替换为dupdb
[oracle@test dbs]$ vi initdupdb.ora
dupdb.__db_cache_size=771751936
dupdb.__java_pool_size=16777216
dupdb.__large_pool_size=16777216
dupdb.__shared_pool_size=268435456
dupdb.__streams_pool_size=0
*.audit_file_dest='/usr/local/oracle/admin/dupdb/adump'
*.background_dump_dest='/usr/local/oracle/admin/dupdb/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/usr/local/oracle/oradata/dupdb/control01.ctl','/usr/local/oracle/oradata/dupdb/control02.ctl','/usr/local/oracle/oradata/dupdb/control03.ctl'
*.core_dump_dest='/usr/local/oracle/admin/dupdb/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='dupdb'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=dupdbXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='LOCATION=/usr/local/oracle/arch'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=362807296
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=1089470464
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/usr/local/oracle/admin/dupdb/udump'
db_file_name_convert=('/usr/local/oracle/oradata/test','/usr/local/oracle/oradata/dupdb')
log_file_name_convert=('/usr/local/oracle/oradata/test','/usr/local/oracle/oradata/dupdb')
-------这两个参数比较重要,如果不设置则在复制时需 要使用SET NEWNAME

~

创建相关目录
[oracle@test dbs]$ mkdir -p /usr/local/oracle/admin/dupdb/adump
[oracle@test dbs]$ mkdir -p /usr/local/oracle/admin/dupdb/bdump
[oracle@test dbs]$ mkdir -p /usr/local/oracle/admin/dupdb/cdump
[oracle@test dbs]$ mkdir -p /usr/local/oracle/admin/dupdb/udump
[oracle@test dbs]$ mkdir -p /usr/local/oracle/oradata/dupdb
根据pfile创建spfile文件
oracle@test dbs]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Dec 28 17:25:41 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1090519040 bytes
Fixed Size 1218920 bytes
Variable Size 301991576 bytes
Database Buffers 771751936 bytes
Redo Buffers 15556608 bytes
SQL> create spfile from pfile;
File created.
SQL> shutdown immediate;
ORA-01507: database not mounted

ORACLE instance shut down.
SQL>
3、准备复制库密码文件
[oracle@test dbs]$ orapwd file=orapwdupdb password="7177743" entries=4
[oracle@test dbs]$
4、复制数据库
[oracle@test dbs]$ rman target sys/7177743@192.168.160.55/test auxiliary sys/7177743
Recovery Manager: Release 10.2.0.1.0 - Production on Wed Dec 28 17:35:44 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: TEST (DBID=2069242183)
connected to auxiliary database: DUPDB (not mounted)
RMAN> duplicate target database to dupdb;
Starting Duplicate Db at 28-DEC-11
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=156 devtype=DISK
contents of Memory Script.:
{
set until scn 477728;
set newname for datafile 1 to
"/usr/local/oracle/oradata/dupdb/system01.dbf";
set newname for datafile 2 to
"/usr/local/oracle/oradata/dupdb/undotbs01.dbf";
set newname for datafile 3 to
"/usr/local/oracle/oradata/dupdb/sysaux01.dbf";
set newname for datafile 4 to
"/usr/local/oracle/oradata/dupdb/users01.dbf";
set newname for datafile 5 to
"/usr/local/oracle/oradata/dupdb/example01.dbf";
restore
check readonly
clone database
;
}
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 28-DEC-11
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /usr/local/oracle/oradata/dupdb/system01.dbf
restoring datafile 00002 to /usr/local/oracle/oradata/dupdb/undotbs01.dbf
restoring datafile 00003 to /usr/local/oracle/oradata/dupdb/sysaux01.dbf
restoring datafile 00004 to /usr/local/oracle/oradata/dupdb/users01.dbf
restoring datafile 00005 to /usr/local/oracle/oradata/dupdb/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /usr/local/oracle/backup/TEST_2.dbf
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/usr/local/oracle/backup/TEST_2.dbf tag=TAG20111228T172215
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:26
Finished restore at 28-DEC-11
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/usr/local/oracle/oradata/dupdb/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/usr/local/oracle/oradata/dupdb/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/usr/local/oracle/oradata/dupdb/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/usr/local/oracle/oradata/dupdb/system01.dbf'
CHARACTER SET WE8ISO8859P1

contents of Memory Script.:
{
switch clone datafile all;
}
executing Memory Script
released channel: ORA_AUX_DISK_1
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=771096993 filename=/usr/local/oracle/oradata/dupdb/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=771096993 filename=/usr/local/oracle/oradata/dupdb/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=771096993 filename=/usr/local/oracle/oradata/dupdb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=771096993 filename=/usr/local/oracle/oradata/dupdb/example01.dbf
contents of Memory Script.:
{
set until scn 477728;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 28-DEC-11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=156 devtype=DISK
starting media recovery
archive log thread 1 sequence 3 is already on disk as file /usr/local/oracle/arch/1_3_771095752.dbf
archive log filename=/usr/local/oracle/arch/1_3_771095752.dbf thread=1 sequence=3
media recovery complete, elapsed time: 00:00:01
Finished recover at 28-DEC-11
contents of Memory Script.:
{
shutdown clone;
startup clone nomount ;
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1090519040 bytes
Fixed Size 1218920 bytes
Variable Size 301991576 bytes
Database Buffers 771751936 bytes
Redo Buffers 15556608 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/usr/local/oracle/oradata/dupdb/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/usr/local/oracle/oradata/dupdb/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/usr/local/oracle/oradata/dupdb/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/usr/local/oracle/oradata/dupdb/system01.dbf'
CHARACTER SET WE8ISO8859P1

contents of Memory Script.:
{
set newname for tempfile 1 to
"/usr/local/oracle/oradata/dupdb/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/usr/local/oracle/oradata/dupdb/undotbs01.dbf";
catalog clone datafilecopy "/usr/local/oracle/oradata/dupdb/sysaux01.dbf";
catalog clone datafilecopy "/usr/local/oracle/oradata/dupdb/users01.dbf";
catalog clone datafilecopy "/usr/local/oracle/oradata/dupdb/example01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to /usr/local/oracle/oradata/dupdb/temp01.dbf in control file
cataloged datafile copy
datafile copy filename=/usr/local/oracle/oradata/dupdb/undotbs01.dbf recid=1 stamp=771097005
cataloged datafile copy
datafile copy filename=/usr/local/oracle/oradata/dupdb/sysaux01.dbf recid=2 stamp=771097005
cataloged datafile copy
datafile copy filename=/usr/local/oracle/oradata/dupdb/users01.dbf recid=3 stamp=771097005
cataloged datafile copy
datafile copy filename=/usr/local/oracle/oradata/dupdb/example01.dbf recid=4 stamp=771097005
datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=771097005 filename=/usr/local/oracle/oradata/dupdb/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=771097005 filename=/usr/local/oracle/oradata/dupdb/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=771097005 filename=/usr/local/oracle/oradata/dupdb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=771097005 filename=/usr/local/oracle/oradata/dupdb/example01.dbf
contents of Memory Script.:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 28-DEC-11
RMAN>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/593077/viewspace-714610/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-01-09

  • 博文量
    6
  • 访问量
    28774