使用RMAN複製資料庫
1、環境介紹:
主機1:
作業系統 |
REDHAT5.5 |
IP地址 |
172.16.1.120 |
主機名 |
sigle |
資料庫版本 |
10.2.0.4 |
資料庫名 |
orcl |
DBID |
1305151947 |
catalog |
win_yjr |
catalog使用者 |
sigle/sigle |
主機2:
作業系統 |
REDHAT5.5 |
IP地址 |
172.16.1.121 |
主機名 |
clone_sigle |
資料庫版本 |
10.2.0.4 |
|
|
|
|
本次試驗的資料庫系統檔案儲存採用raw方式,因此在進行復制前,為了確保恢復的有效性,已使用dd命令將clone_sigle上的raw裝置原有資料資訊全部清空一次。
源資料庫SID:orcl
目標資料庫SID:orclaux
2、本次複製試驗目錄:
試驗在同平臺,同版本之間的資料快速遷移複製的另一種途徑,保證在複製後的資料庫中有源資料庫中的資料。
3、實際操作過程:
為了驗證複製的完整性,在熱備之前先建立一張驗證表:sys.test_rman裡面有一條資料。
SQL> select * from test_rman;
T1 T2 ---------- -------------- 1 23-3月 -12
SQL> |
1)、啟動源資料庫到open狀態
SQL*Plus: Release 10.2.0.4.0 - Production on 星期一 3月 26 23:29:16 2012
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
SQL> conn /as sysdba Connected to an idle instance. SQL> startup mount; ORACLE instance started.
Total System Global Area 486539264 bytes Fixed Size 1268196 bytes Variable Size 171968028 bytes Database Buffers 306184192 bytes Redo Buffers 7118848 bytes Database mounted. SQL> alter database open;
Database altered.
SQL> |
2)、熱備份源資料庫
RMAN> run { 2> configure controlfile autobackup on; 3> CONFIGURE BACKUP OPTIMIZATION on; 4> backup as compressed backupset 5> format '/oracle/backup/backdb.dbf' 6> database 7> include current controlfile; 8> # Archive log Backup 9> backup as compressed backupset 10> format '/oracle/backup/archive.dbf' 11> archivelog all delete all input; 12> }
old RMAN configuration parameters: CONFIGURE CONTROLFILE AUTOBACKUP ON; new RMAN configuration parameters: CONFIGURE CONTROLFILE AUTOBACKUP ON; new RMAN configuration parameters are successfully stored
old RMAN configuration parameters: CONFIGURE BACKUP OPTIMIZATION ON; new RMAN configuration parameters: CONFIGURE BACKUP OPTIMIZATION ON; new RMAN configuration parameters are successfully stored
Starting backup at 26-3月 -12 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=1628 devtype=DISK channel ORA_DISK_1: starting compressed full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/dev/raw/raw1 input datafile fno=00002 name=/dev/raw/raw3 input datafile fno=00003 name=/dev/raw/raw2 input datafile fno=00004 name=/dev/raw/raw4 channel ORA_DISK_1: starting piece 1 at 26-3月 -12 channel ORA_DISK_1: finished piece 1 at 26-3月 -12 piece handle=/oracle/backup/backdb<778981561:1>.dbf tag=TAG20120326T234601 comment=NONE778981561:1> channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55 channel ORA_DISK_1: starting compressed full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset including current control file in backupset channel ORA_DISK_1: starting piece 1 at 26-3月 -12 channel ORA_DISK_1: finished piece 1 at 26-3月 -12 piece handle=/oracle/backup/backdb<778981617:1>.dbf tag=TAG20120326T234601 comment=NONE778981617:1> channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 26-3月 -12
Starting backup at 26-3月 -12 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=41 recid=7 stamp=778981619 channel ORA_DISK_1: starting piece 1 at 26-3月 -12 channel ORA_DISK_1: finished piece 1 at 26-3月 -12 piece handle=/oracle/backup/archive<778981619:1>.dbf tag=TAG20120326T234659 comment=NONE778981619:1> channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 channel ORA_DISK_1: deleting archive log(s) archive log filename=/oracle/arch/1_41_777371211.dbf recid=7 stamp=778981619 Finished backup at 26-3月 -12
Starting Control File and SPFILE Autobackup at 26-3月 -12 piece handle=/oracle/db10g/dbs/c-1305151947-20120326-02 comment=NONE Finished Control File and SPFILE Autobackup at 26-3月 -12
RMAN> |
3)、配置監聽
為了確保複製資料庫時,在資料庫沒有啟動的情況下能正常連線數目標資料庫,需要對監聽進行配置,進行靜態註冊,可以在兩端都進行配置,為了保證配置正確,推薦使用oracle net mamager進行配置。使用命令netmgr來啟動OUI。在LISTENER中配置資料庫服務,如下圖:
配置完成後,重啟監聽。
4)、並配置密碼檔案及建立相應的引數目錄
5)、建立啟動pfile檔案
SQL> create pfile='/oracle/backup/initorclaux.ora' from spfile;
File created.
SQL> |
6)、修改pfile檔案
將其中的db_name 修改為:db_name='orclaux'
其他引數使用和源資料一樣的路徑和配置,因此不做修改。
7)、啟動目標資料到nomount狀態
[oracle@sigle backup]$ hostname [oracle@sigle backup]$ sq [uniread] Loaded history (132 lines) SQL*Plus: Release 10.2.0.4.0 - Production on 星期二 3月 27 00:59:56 2012
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
SQL> conn /as sysdba Connected to an idle instance. SQL> startup nomount pfile='/oracle/backup/initorclaux.ora'; ORACLE instance started.
Total System Global Area 486539264 bytes Fixed Size 1268196 bytes Variable Size 171968028 bytes Database Buffers 306184192 bytes Redo Buffers 7118848 bytes SQL> show parameter name
NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ db_file_name_convert string db_name string orclaux db_unique_name string orclaux global_names boolean FALSE instance_name string orclaux lock_name_space string log_file_name_convert string service_names string orclaux SQL> |
8)、連線源資料庫及目標資料庫
在源資料庫端連線
[oracle@sigle backup]$ hostname sigle [oracle@sigle backup]$ [oracle@sigle ~]$ rman target / [uniread] Loaded history (181 lines)
Recovery Manager: Release 10.2.0.4.0 - Production on 星期二 3月 27 01:04:58 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1305151947)
RMAN> CONNECT AUXILIARY sys/sysadmin@sigleaux
connected to auxiliary database: ORCLAUX (not mounted)
RMAN> |
9)、複製資料庫
需要注意的是,如果目標資料庫的資料檔案位置與源資料庫資料檔案位置相同,在執行
DUPLICATE TARGET DATABASE TO orclaux後要加nofilenamecheck引數,否則報錯:
RMAN-05001: auxiliary filename/dev/raw/raw1 conflicts with a file used by the target database
如果目標資料庫的資料檔案位置與源資料庫資料檔案位置不同,則需要加上DB_FILE_NAME_CONVERT引數來轉換資料檔案位置,例如:
DB_FILE_NAME_CONVERT=('/h1/oracle/dbs/trgt/','/h2/oracle/oradata/newdb/')
注意,在命令執行過程中,目標資料庫必須要保證沒有連線,否則指令碼執行到整個過程快結束,需要重啟目標資料庫時候掛住,直到現有連線全部退出。
RMAN> DUPLICATE TARGET DATABASE TO orclaux nofilenamecheck;
Starting Duplicate Db at 27-3月 -12 using channel ORA_AUX_DISK_1
contents of Memory Script: { set until scn 555341; set newname for datafile 1 to "/dev/raw/raw1"; set newname for datafile 2 to "/dev/raw/raw3"; set newname for datafile 3 to "/dev/raw/raw2"; set newname for datafile 4 to "/dev/raw/raw4"; 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
Starting restore at 27-3月 -12 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 /dev/raw/raw1 restoring datafile 00002 to /dev/raw/raw3 restoring datafile 00003 to /dev/raw/raw2 restoring datafile 00004 to /dev/raw/raw4 channel ORA_AUX_DISK_1: reading from backup piece /oracle/backup/backdb<778981561:1>.dbf778981561:1> channel ORA_AUX_DISK_1: restored backup piece 1 piece handle=/oracle/backup/backdb<778981561:1>.dbf tag=TAG20120326T234601778981561:1> channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:35 Finished restore at 27-3月 -12 sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCLAUX" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 1024 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/dev/raw/raw10', '/dev/raw/raw11' ) SIZE 50 M REUSE, GROUP 2 ( '/dev/raw/raw12', '/dev/raw/raw13' ) SIZE 50 M REUSE DATAFILE '/dev/raw/raw1' CHARACTER SET ZHS16GBK
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=778987671 filename=/dev/raw/raw3 datafile 3 switched to datafile copy input datafile copy recid=2 stamp=778987671 filename=/dev/raw/raw2 datafile 4 switched to datafile copy input datafile copy recid=3 stamp=778987671 filename=/dev/raw/raw4
contents of Memory Script: { set until scn 555341; recover clone database delete archivelog ; } executing Memory Script
executing command: SET until clause
Starting recover at 27-3月 -12 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: sid=1640 devtype=DISK
starting media recovery
channel ORA_AUX_DISK_1: starting archive log restore to default destination channel ORA_AUX_DISK_1: restoring archive log archive log thread=1 sequence=41 channel ORA_AUX_DISK_1: reading from backup piece /oracle/backup/archive<778981619:1>.dbf778981619:1> channel ORA_AUX_DISK_1: restored backup piece 1 piece handle=/oracle/backup/archive<778981619:1>.dbf tag=TAG20120326T234659778981619:1> channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01 archive log filename=/oracle/arch/1_41_777371211.dbf thread=1 sequence=41 channel clone_default: deleting archive log(s) archive log filename=/oracle/arch/1_41_777371211.dbf recid=1 stamp=778987673 media recovery complete, elapsed time: 00:00:00 Finished recover at 27-3月 -12
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 486539264 bytes
Fixed Size 1268196 bytes Variable Size 138413596 bytes Database Buffers 339738624 bytes Redo Buffers 7118848 bytes sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCLAUX" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 1024 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/dev/raw/raw10', '/dev/raw/raw11' ) SIZE 50 M REUSE, GROUP 2 ( '/dev/raw/raw12', '/dev/raw/raw13' ) SIZE 50 M REUSE DATAFILE '/dev/raw/raw1' CHARACTER SET ZHS16GBK
contents of Memory Script: { set newname for tempfile 1 to "/dev/raw/raw5"; switch clone tempfile all; catalog clone datafilecopy "/dev/raw/raw3"; catalog clone datafilecopy "/dev/raw/raw2"; catalog clone datafilecopy "/dev/raw/raw4"; switch clone datafile all; } executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to /dev/raw/raw5 in control file
cataloged datafile copy datafile copy filename=/dev/raw/raw3 recid=1 stamp=778987902
cataloged datafile copy datafile copy filename=/dev/raw/raw2 recid=2 stamp=778987902
cataloged datafile copy datafile copy filename=/dev/raw/raw4 recid=3 stamp=778987902
datafile 2 switched to datafile copy input datafile copy recid=1 stamp=778987902 filename=/dev/raw/raw3 datafile 3 switched to datafile copy input datafile copy recid=2 stamp=778987902 filename=/dev/raw/raw2 datafile 4 switched to datafile copy input datafile copy recid=3 stamp=778987902 filename=/dev/raw/raw4
contents of Memory Script: { Alter clone database open resetlogs; } executing Memory Script
database opened Finished Duplicate Db at 27-3月 -12
RMAN> |
10)、驗證資料庫複製
[oracle@clone_sigle /]$ hostname clone_sigle [oracle@clone_sigle /]$ sq [uniread] Loaded history (423 lines)
SQL*Plus: Release 10.2.0.4.0 - Production on 星期二 3月 27 01:36:32 2012
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
SQL> conn /as sysdba Connected. SQL> show parameter name
NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_file_name_convert string db_name string orclaux db_unique_name string orclaux global_names boolean FALSE instance_name string orclaux lock_name_space string log_file_name_convert string service_names string orclaux SQL> select * from test_rman;
T1 T2 ---------- -------------- 1 23-3月 -12
SQL> |
重啟資料庫後再進行一次驗證
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started.
Total System Global Area 486539264 bytes Fixed Size 1268196 bytes Variable Size 138413596 bytes Database Buffers 339738624 bytes Redo Buffers 7118848 bytes Database mounted. Database opened. SQL> show parameter name
NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_file_name_convert string db_name string orclaux db_unique_name string orclaux global_names boolean FALSE instance_name string orclaux lock_name_space string log_file_name_convert string service_names string orclaux SQL> SQL> select * from test_rman;
T1 T2 ---------- -------------- 1 23-3月 -12
SQL> |
至此,使用RMAN來進行資料庫複製的試驗結束,試驗達到了預期目標。
--------------------------------->>
轉載於:http://blog.chinaunix.net/uid-12380499-id-3399814.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29119536/viewspace-1167726/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用RMAN複製資料庫 active database資料庫Database
- 使用RMAN備份資料庫資料庫
- 資料庫複製(一)–複製介紹資料庫
- 3.1.1.2 使用RMAN啟動資料庫資料庫
- DM7資料複製之資料庫級複製資料庫
- 資料庫主從複製資料庫
- Oracle 11G RAC複製備庫RMAN-03002 RMAN-05501 RMAN-03015 RMAN-03009 RMAN-10038Oracle
- oracle資料庫使用rman備份指令碼Oracle資料庫指令碼
- [重慶思莊每日技術分享]-使用RMAN活動複製資料庫時出現報錯Ora-19625資料庫
- Mysql(Mariadb)資料庫主從複製MySql資料庫
- dimitri/pgcopydb:Postgres資料庫複製工具MITGC資料庫
- 使用者管理的熱備份方式複製資料庫資料庫
- 用rman遷移資料庫資料庫
- mysql資料庫的主從複製和主主複製實踐MySql資料庫
- mysql資料庫實現主從複製MySql資料庫
- 分散式資料庫的複製原理 - Quastor分散式資料庫AST
- 架構設計(二):資料庫複製架構資料庫
- 【RMAN】Oracle使用rman將11.2.0.4資料庫遷移至Oracle12c命令參考Oracle資料庫
- 利用RMAN備份重建資料庫資料庫
- 資料共享(淺複製)與資料獨立(深複製)
- 利用SQL Server Management Studio(SSMS)複製資料庫SQLServerSSM資料庫
- TiDB 異構資料庫複製最佳實踐TiDB資料庫
- 異構資料庫間批量表快速複製資料庫
- GoldenGate異種資料庫之間的複製Go資料庫
- Centos-Mysql複製備份還原資料庫CentOSMySql資料庫
- oracle sqldeveloper選擇性複製備份資料庫OracleSQLDeveloper資料庫
- MySQL-主從複製之搭建從資料庫MySql資料庫
- MySQL-主從複製之搭建主資料庫MySql資料庫
- MongoDB資料庫之主從複製配置實戰【轉】MongoDB資料庫
- 什麼是單主資料庫複製? -Vlad Mihalcea資料庫
- Day 7.5 資料型別總結 + 複製 淺複製 深複製資料型別
- Redis的資料複製Redis
- DM7資料複製之模式級複製模式
- Oracle RMAN 連線資料庫認證方法Oracle資料庫
- 資料庫複習資料庫
- MongoDB在不同主機間複製資料庫和集合MongoDB資料庫
- linux下mysql主從複製,實現資料庫同步LinuxMySql資料庫
- 資料庫容災、複製解決方案全分析(轉)資料庫
- 資料庫檔案複製問題和解決辦法資料庫