【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之后出现的数据变化即可。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。