程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> 【Oracle】OGG數據初始化之RMAN

【Oracle】OGG數據初始化之RMAN

編輯:Oracle教程

【Oracle】OGG數據初始化之RMAN


實驗環境:

源端、目標端:

DataBase:10.2.0.1.0

OS:OEL5.6

OGG:fbo_ggs_Linux_x86_ora11g_32bit

源端使用rman進行備份全庫:

RMAN> run{

ALLOCATE CHANNEL ch00 TYPE DISK MAXPIECESIZE 20G;

ALLOCATE CHANNEL ch01 TYPE DISK MAXPIECESIZE 20G;

CROSSCHECK BACKUPSET;

DELETE NOPROMPT EXPIRED BACKUPSET;

sql 'alter system archive log current';

BACKUP AS BACKUPSET SKIP INACCESSIBLE TAG hot_db_bk_level0 FORMAT '/home/oracle/bak//bk_%s_%p_%t' FULL DATABASE;

RELEASE CHANNEL ch00;

RELEASE CHANNEL ch01;

}2> 3> 4> 5> 6> 7> 8> 9> 10>

released channel: ORA_DISK_1

allocated channel: ch00

channel ch00: sid=141 devtype=DISK

allocated channel: ch01

channel ch01: sid=149 devtype=DISK

sql statement: alter system archive log current

Starting backup at 21-JUL-14

channel ch00: starting full datafile backupset

channel ch00: specifying datafile(s) in backupset

input datafile fno=00001 name=/u01/app/oracle/oradata/ORCL/system01.dbf

input datafile fno=00004 name=/u01/app/oracle/oradata/ORCL/users01.dbf

input datafile fno=00005 name=/u01/app/oracle/oradata/ORCL/example01.dbf

channel ch00: starting piece 1 at 21-JUL-14

channel ch01: starting full datafile backupset

channel ch01: specifying datafile(s) in backupset

input datafile fno=00003 name=/u01/app/oracle/oradata/ORCL/sysaux01.dbf

input datafile fno=00006 name=/u01/app/oracle/oradata/ORCL/ogg01.dbf

input datafile fno=00002 name=/u01/app/oracle/oradata/ORCL/undotbs01.dbf

channel ch01: starting piece 1 at 21-JUL-14

channel ch01: finished piece 1 at 21-JUL-14

piece handle=/home/oracle/bak/bk_23_1_853515593 tag=HOT_DB_BK_LEVEL0 comment=NONE

channel ch01: backup set complete, elapsed time: 00:00:35

channel ch01: starting full datafile backupset

channel ch01: specifying datafile(s) in backupset

including current control file in backupset

channel ch01: starting piece 1 at 21-JUL-14

channel ch01: finished piece 1 at 21-JUL-14

piece handle=/home/oracle/bak/bk_24_1_853515629 tag=HOT_DB_BK_LEVEL0 comment=NONE

channel ch01: backup set complete, elapsed time: 00:00:03

channel ch01: starting full datafile backupset

channel ch01: specifying datafile(s) in backupset

including current SPFILE in backupset

channel ch01: starting piece 1 at 21-JUL-14

channel ch01: finished piece 1 at 21-JUL-14

piece handle=/home/oracle/bak/bk_25_1_853515632 tag=HOT_DB_BK_LEVEL0 comment=NONE

channel ch01: backup set complete, elapsed time: 00:00:01

channel ch00: finished piece 1 at 21-JUL-14

piece handle=/home/oracle/bak/bk_22_1_853515593 tag=HOT_DB_BK_LEVEL0 comment=NONE

channel ch00: backup set complete, elapsed time: 00:01:15

Finished backup at 21-JUL-14

released channel: ch00

released channel: ch01

備份歸檔日志及控制文件,這裡以有三組日志文件做例子,全部切一遍

RMAN> run{

ALLOCATE CHANNEL ch00 TYPE DISK MAXPIECESIZE 20G;

ALLOCATE CHANNEL ch01 TYPE DISK MAXPIECESIZE 20G;

sql 'alter system switch logfile';

sql 'alter system switch logfile';

sql 'alter system switch logfile';

sql 'alter system archive log current';

BACKUP ARCHIVELOG ALL FORMAT '/home/oracle/bak/ARCH_%U';

BACKUP CURRENT CONTROLFILE FORMAT '/home/oracle/bak/bk_controlfile';

RELEASE CHANNEL ch00;

RELEASE CHANNEL ch01;

}2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12>

allocated channel: ch00

channel ch00: sid=141 devtype=DISK

allocated channel: ch01

channel ch01: sid=149 devtype=DISK

sql statement: alter system switch logfile

sql statement: alter system switch logfile

sql statement: alter system switch logfile

sql statement: alter system archive log current

Starting backup at 21-JUL-14

current log archived

channel ch00: starting archive log backupset

channel ch00: specifying archive log(s) in backup set

input archive log thread=1 sequence=2 recid=1 stamp=853513172

channel ch00: starting piece 1 at 21-JUL-14

channel ch01: starting archive log backupset

channel ch01: specifying archive log(s) in backup set

input archive log thread=1 sequence=3 recid=2 stamp=853514244

input archive log thread=1 sequence=4 recid=3 stamp=853514831

input archive log thread=1 sequence=5 recid=4 stamp=853514881

input archive log thread=1 sequence=6 recid=5 stamp=853514923

input archive log thread=1 sequence=7 recid=6 stamp=853515051

input archive log thread=1 sequence=8 recid=7 stamp=853515051

input archive log thread=1 sequence=9 recid=8 stamp=853515057

input archive log thread=1 sequence=10 recid=9 stamp=853515057

input archive log thread=1 sequence=11 recid=10 stamp=853515060

input archive log thread=1 sequence=12 recid=11 stamp=853515131

input archive log thread=1 sequence=13 recid=12 stamp=853515131

input archive log thread=1 sequence=14 recid=13 stamp=853515136

input archive log thread=1 sequence=15 recid=14 stamp=853515136

input archive log thread=1 sequence=16 recid=15 stamp=853515139

input archive log thread=1 sequence=17 recid=16 stamp=853515193

input archive log thread=1 sequence=18 recid=17 stamp=853515193

input archive log thread=1 sequence=19 recid=18 stamp=853515198

input archive log thread=1 sequence=20 recid=19 stamp=853515198

channel ch01: starting piece 1 at 21-JUL-14

channel ch00: finished piece 1 at 21-JUL-14

piece handle=/home/oracle/bak/ARCH_0qpdv7dh_1_1 tag=TAG20140721T154137 comment=NONE

channel ch00: backup set complete, elapsed time: 00:00:04

channel ch01: finished piece 1 at 21-JUL-14

piece handle=/home/oracle/bak/ARCH_0rpdv7dh_1_1 tag=TAG20140721T154137 comment=NONE

channel ch01: backup set complete, elapsed time: 00:00:04

channel ch00: starting archive log backupset

channel ch00: specifying archive log(s) in backup set

input archive log thread=1 sequence=21 recid=20 stamp=853515202

input archive log thread=1 sequence=22 recid=21 stamp=853515384

input archive log thread=1 sequence=23 recid=22 stamp=853515384

input archive log thread=1 sequence=24 recid=23 stamp=853515388

input archive log thread=1 sequence=25 recid=24 stamp=853515388

input archive log thread=1 sequence=26 recid=25 stamp=853515391

input archive log thread=1 sequence=27 recid=26 stamp=853515527

input archive log thread=1 sequence=28 recid=27 stamp=853515527

input archive log thread=1 sequence=29 recid=28 stamp=853515532

input archive log thread=1 sequence=30 recid=29 stamp=853515532

input archive log thread=1 sequence=31 recid=30 stamp=853515535

input archive log thread=1 sequence=32 recid=31 stamp=853515593

input archive log thread=1 sequence=33 recid=32 stamp=853515689

input archive log thread=1 sequence=34 recid=33 stamp=853515689

input archive log thread=1 sequence=35 recid=34 stamp=853515694

input archive log thread=1 sequence=36 recid=35 stamp=853515694

input archive log thread=1 sequence=37 recid=36 stamp=853515697

channel ch00: starting piece 1 at 21-JUL-14

channel ch00: finished piece 1 at 21-JUL-14

piece handle=/home/oracle/bak/ARCH_0spdv7dl_1_1 tag=TAG20140721T154137 comment=NONE

channel ch00: backup set complete, elapsed time: 00:00:02

Finished backup at 21-JUL-14

Starting backup at 21-JUL-14

channel ch00: starting full datafile backupset

channel ch00: specifying datafile(s) in backupset

including current control file in backupset

channel ch00: starting piece 1 at 21-JUL-14

channel ch00: finished piece 1 at 21-JUL-14

piece handle=/home/oracle/bak/bk_controlfile tag=TAG20140721T154145 comment=NONE

channel ch00: backup set complete, elapsed time: 00:00:01

Finished backup at 21-JUL-14

released channel: ch00

released channel: ch01

源端數據庫查詢:

SYS@ORCL>select * from Gv$log;

INST_ID GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM

---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------

1 1 1 38 52428800 1 NO CURRENT 484272 21-JUL-14

1 2 1 36 52428800 1 YES INACTIVE 484261 21-JUL-14

1 3 1 37 52428800 1 YES INACTIVE 484267 21-JUL-14

記錄此時非活動日志組的SCN,有多組的時候我們取最大的FIRST_CHANGE#,在這裡是484267。

將源端庫的init<SID>.ora發送到目標端:

SYS@ORCL>create pfile from spfile;

File created.

[oracle@edbjr2p1 dbs]$ scp initORCL.ora edbjr2p2:$ORACLE_HOME/dbs

oracle@edbjr2p2's password:

initORCL.ora 100% 1049 1.0KB/s 00:00

在目標端建立所有目錄,然後將備份傳過去:

目標端:

[oracle@edbjr2p2 oracle]$ pwd

/u01/app/oracle

[oracle@edbjr2p2 oracle]$ mkdir -p admin/ORCL/{a,b,c,u}dump

[oracle@edbjr2p2 oracle]$ mkdir flash_recovery_area/ORCL

[oracle@edbjr2p2 oracle]$ mkdir -p oradata/ORCL

源端:

[oracle@edbjr2p1 bak]$ ls

ARCH_0qpdv7dh_1_1 ARCH_0spdv7dl_1_1 bk_23_1_853515593 bk_25_1_853515632

ARCH_0rpdv7dh_1_1 bk_22_1_853515593 bk_24_1_853515629 bk_controlfile

[oracle@edbjr2p1 bak]$ scp * edbjr2p2:~/bak/

oracle@edbjr2p2's password:

ARCH_0qpdv7dh_1_1 100% 11MB 11.2MB/s 00:00

ARCH_0rpdv7dh_1_1 100% 2648KB 2.6MB/s 00:00

ARCH_0spdv7dl_1_1 100% 55KB 55.0KB/s 00:00

bk_22_1_853515593 100% 410MB 9.1MB/s 00:45

bk_23_1_853515593 100% 159MB 4.4MB/s 00:36

bk_24_1_853515629 100% 7232KB 3.5MB/s 00:02

bk_25_1_853515632 100% 96KB 96.0KB/s 00:00

bk_controlfile 100% 7232KB 7.1MB/s 00:00

目標端將庫啟動到nomount狀態:

[oracle@edbjr2p2 ~]$ export ORACLE_SID=ORCL

[oracle@edbjr2p2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jul 21 16:11:45 2014

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

Connected to an idle instance. 

SQL> create spfile from pfile;

File created.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 452984832 bytes

Fixed Size 1219928 bytes

Variable Size 109052584 bytes

Database Buffers 335544320 bytes

Redo Buffers 7168000 bytes

SQL>

然後使用rman將數據庫恢復出來:

RMAN> restore controlfile from '/home/oracle/bak/bk_controlfile';

Starting restore at 21-JUL-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:04

output filename=/u01/app/oracle/oradata/ORCL/control01.ctl

output filename=/u01/app/oracle/oradata/ORCL/control02.ctl

output filename=/u01/app/oracle/oradata/ORCL/control03.ctl

Finished restore at 21-JUL-14

RMAN> sql 'alter database mount';

sql statement: alter database mount

released channel: ORA_DISK_1

RMAN> restore database;

Starting restore at 21-JUL-14

Starting implicit crosscheck backup at 21-JUL-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=155 devtype=DISK

Crosschecked 7 objects

Finished implicit crosscheck backup at 21-JUL-14

Starting implicit crosscheck copy at 21-JUL-14

using channel ORA_DISK_1

Finished implicit crosscheck copy at 21-JUL-14

searching for all files in the recovery area

cataloging files...

no files cataloged

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to /u01/app/oracle/oradata/ORCL/undotbs01.dbf

restoring datafile 00003 to /u01/app/oracle/oradata/ORCL/sysaux01.dbf

restoring datafile 00006 to /u01/app/oracle/oradata/ORCL/ogg01.dbf

channel ORA_DISK_1: reading from backup piece /home/oracle/bak/bk_23_1_853515593

channel ORA_DISK_1: restored backup piece 1

piece handle=/home/oracle/bak/bk_23_1_853515593 tag=HOT_DB_BK_LEVEL0

channel ORA_DISK_1: restore complete, elapsed time: 00:00:27

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /u01/app/oracle/oradata/ORCL/system01.dbf

restoring datafile 00004 to /u01/app/oracle/oradata/ORCL/users01.dbf

restoring datafile 00005 to /u01/app/oracle/oradata/ORCL/example01.dbf

channel ORA_DISK_1: reading from backup piece /home/oracle/bak/bk_22_1_853515593

channel ORA_DISK_1: restored backup piece 1

piece handle=/home/oracle/bak/bk_22_1_853515593 tag=HOT_DB_BK_LEVEL0

channel ORA_DISK_1: restore complete, elapsed time: 00:00:46

Finished restore at 21-JUL-14

然後recover數據庫到前邊我們記錄的SCN處:

RMAN>run

{

SET UNTIL SCN 484267;

RECOVER DATABASE;

}2> 3> 4> 5>

目標端查看此時SCN並打開數據庫:

SQL> SELECT CHECKPOINT_CHANGE#,CHECKPOINT_TIME FROM V$DATAFILE_HEADER;

CHECKPOINT_CHANGE# CHECKPOIN

------------------ ---------

484267 21-JUL-14

484267 21-JUL-14

484267 21-JUL-14

484267 21-JUL-14

484267 21-JUL-14

484267 21-JUL-14

6 rows selected. 

SQL> alter database open resetlogs; 

Database altered. 

目標端啟動Replicat進程:

GGSCI (edbjr2p2) 1>start repya ,afterscn 484267

此處使用的SCN是我們之前記錄的SCN。因為數據文件恢復到了這個SCN,rman保證了這個SCN之前的源端和目標端庫的數據一致性,OGG只要應用此SCN之後出現的數據變化即可。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved