如果一个数据库非常大,要对这个数据库进行迁移,在不考虑磁盘空间的前提下,要求在最短的时间内完成切换操作。
下面是一个迁移的测试:
源数据库:rhel133
目录数据库:rhel134
1. 在Target库rman 备份数据库,并将备份copy到Auxiliary库的相同位置
[oracle@rhel133 RMAN]$ scp * 172.17.61.134:/u03/RMAN
The authenticity of host '172.17.61.134 (172.17.61.134)' can't be established.
RSA key fingerprint is d8:9e:74:00:f1:f1:5c:da:75:f8:76:ef:20:dd:69:f3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.61.134' (RSA) to the list of known hosts.
oracle@172.17.61.134's password:
arch0po6nbc3_25_1.bak 100% 1117KB 1.1MB/s 00:00
arch0qo6nbc5_26_1.bak 100% 779KB 778.5KB/s 00:00
arch0ro6nbc7_27_1.bak 100% 2560 2.5KB/s 00:00
arch0so6nbc9_28_1.bak 100% 2560 2.5KB/s 00:00
auto_c_c-1230508166-20130410-01 100% 6944KB 6.8MB/s 00:00
auto_c_c-1230508166-20130410-02 100% 6944KB 6.8MB/s 00:01
db00mo6naal_22_1.bak 100% 5495MB 22.2MB/s 04:08
db00no6nbbu_23_1.bak 100% 1088KB 1.1MB/s 00:00
2. 在Auxiliary库创建相关的目录,口令文件,和初始化文件。
初始化文件可以直接从Target copy过来。如果目录结构相同的话,都不用修改参数。
3. 用初始化文件将数据库启动到noumout状态。
[oracle@rhel134 RMAN]$ rman target /
Recovery Manager: Release 10.2.0.4.0 - Production on Wed Apr 10 09:10:11 2013
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup nomount
Oracle instance started
Total System Global Area 1325400064 bytes
Fixed Size 1267236 bytes
Variable Size 1256196572 bytes
Database Buffers 52428800 bytes
Redo Buffers 15507456 bytes
4. 恢复控制文件
RMAN> restore controlfile from '/u03/RMAN/auto_c_c-1230508166-20130410-01';
Starting restore at 10-APR-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=101 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/u01/oradata/orcl/control01.ctl
output filename=/u01/oradata/orcl/control02.ctl
output filename=/u01/oradata/orcl/control03.ctl
Finished restore at 10-APR-13
5. 将数据库启动到mout状态
SQL> alter database mount;
Database altered.
6. restore 数据库
RMAN> restore database;
Starting restore at 10-APR-13
Starting implicit crosscheck backup at 10-APR-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=101 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=100 devtype=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 10-APR-13
Starting implicit crosscheck copy at 10-APR-13
using channel ORA_DISK_1
using channel ORA_DISK_2
Finished implicit crosscheck copy at 10-APR-13
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/oradata/orcl/system01.dbf
restoring datafile 00002 to /u02/oradata/orcl/undotbs01.dbf
restoring datafile 00003 to /u02/oradata/orcl/sysaux01.dbf
restoring datafile 00004 to /u02/oradata/orcl/DEALSPACE_002.dbf
restoring datafile 00005 to /u02/oradata/orcl/DEALSPACE_001.dbf
restoring datafile 00006 to /u02/oradata/orcl/l5mspace01.dbf
restoring datafile 00007 to /u02/oradata/orcl/RCFSPACE_002.dbf
restoring datafile 00008 to /u02/oradata/orcl/RCFSPACE_001.dbf
restoring datafile 00009 to /u02/oradata/orcl/DTSPACE_001.dbf
channel ORA_DISK_1: reading from backup piece /u03/RMAN/db00mo6naal_22_1.bak
channel ORA_DISK_1: restored backup piece 1
piece handle=/u03/RMAN/db00mo6naal_22_1.bak tag=TAG20130410T080749
channel ORA_DISK_1: restore complete, elapsed time: 00:19:06
Finished restore at 10-APR-13
7. recover 数据库
RMAN> recover database;
Starting recover at 10-APR-13
using channel ORA_DISK_1
using channel ORA_DISK_2
starting media recovery
unable to find archive log
archive log thread=1 sequence=2
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/10/2013 09:34:29
RMAN-06054: media recovery requesting unknown log: thread 1 seq 2 lowscn 3524946353
由于恢复的controlfile中没有包含备份的arcivelog信息,所以需要手动将备份的archivelog注册到control file中。
RMAN> catalog start with '/u03/RMAN';
searching for all files that match the pattern /u03/RMAN
List of Files Unknown to the Database
=====================================
File Name: /u03/RMAN/arch0po6nbc3_25_1.bak
File Name: /u03/RMAN/arch0qo6nbc5_26_1.bak
File Name: /u03/RMAN/arch0ro6nbc7_27_1.bak
File Name: /u03/RMAN/arch0so6nbc9_28_1.bak
File Name: /u03/RMAN/auto_c_c-1230508166-20130410-01
File Name: /u03/RMAN/auto_c_c-1230508166-20130410-02
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u03/RMAN/arch0po6nbc3_25_1.bak
File Name: /u03/RMAN/arch0qo6nbc5_26_1.bak
File Name: /u03/RMAN/arch0ro6nbc7_27_1.bak
File Name: /u03/RMAN/arch0so6nbc9_28_1.bak
File Name: /u03/RMAN/auto_c_c-1230508166-20130410-01
File Name: /u03/RMAN/auto_c_c-1230508166-20130410-02
reover刚刚注册上来的archivelog.
RMAN> recover database;
Starting recover at 10-APR-13
using channel ORA_DISK_1
using channel ORA_DISK_2
starting media recovery
channel ORA_DISK_2: starting archive log restore to default destination
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_2: restoring archive log
archive log thread=1 sequence=3
channel ORA_DISK_2: reading from backup piece /u03/RMAN/arch0so6nbc9_28_1.bak
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=2
channel ORA_DISK_1: reading from backup piece /u03/RMAN/arch0po6nbc3_25_1.bak
channel ORA_DISK_1: restored backup piece 1
piece handle=/u03/RMAN/arch0po6nbc3_25_1.bak tag=TAG20130410T082539
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_04_10/o1_mf_1_2_8p9jl268_.arc thread=1 sequence=2
channel default: deleting archive log(s)
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_04_10/o1_mf_1_2_8p9jl268_.arc recid=18 stamp=812367426
channel ORA_DISK_2: restored backup piece 1
piece handle=/u03/RMAN/arch0so6nbc9_28_1.bak tag=TAG20130410T082539
channel ORA_DISK_2: restore complete, elapsed time: 00:00:04
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_04_10/o1_mf_1_3_8p9jl267_.arc thread=1 sequence=3
channel default: deleting archive log(s)
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_04_10/o1_mf_1_3_8p9jl267_.arc recid=17 stamp=812367426
unable to find archive log
archive log thread=1 sequence=4
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/10/2013 09:37:11
RMAN-06054: media recovery requesting unknown log: thread 1 seq 4 lowscn 3524947133
8. 在主库进行一些事务操作
SQL> conn l5m/l5m
Connected.
SQL> insert into t1
2 select * from all_objects where rownum<2000;
1999 rows created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
9. 关闭主库,迅速把主库的归档文件和online redo复制到Auxiliary库
SQL> shutdown immediate;
[oracle@rhel133 2013_04_10]$ scp o1_mf_1_4_8p9jxcvp_.arc 172.17.61.134:/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_04_10
oracle@172.17.61.134's password:
o1_mf_1_4_8p9jxcvp_.arc 100% 1456KB 1.4MB/s 00:00
[oracle@rhel133 orcl]$ scp redo* 172.17.61.134:/u01/oradata/orcl
oracle@172.17.61.134's password:
redo01.log 100% 500MB 20.8MB/s 00:24
redo02.log 100% 500MB 23.8MB/s 00:21
redo03.log 100% 500MB 21.7MB/s
10. 再次recover database
RMAN> recover database;
Starting recover at 10-APR-13
using channel ORA_DISK_1
using channel ORA_DISK_2
starting media recovery
archive log thread 1 sequence 4 is already on disk as file /u01/oradata/orcl/redo01.log
archive log thread 1 sequence 5 is already on disk as file /u01/oradata/orcl/redo02.log
archive log filename=/u01/oradata/orcl/redo01.log thread=1 sequence=4
archive log filename=/u01/oradata/orcl/redo02.log thread=1 sequence=5
media recovery complete, elapsed time: 00:00:05
Finished recover at 10-APR-13
11. 打开数据库
RMAN> alter database open resetlogs;
database opened
SQL> select count(*) from l5m.t1;
COUNT(*)
----------
2998
数据是最新的。
12. 重建Temp表空间
在恢复的时候,虽然oracle会自动创建TEMP 表空间,但还是建议重建添加temp 数据文件。
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/orcl/temp01.dbf
SQL> alter tablespace temp add tempfile '/u01/oradata/orcl/temp02.dbf' size 100m;
Tablespace altered.
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/orcl/temp01.dbf
/u01/oradata/orcl/temp02.dbf
SQL> alter database tempfile '/u01/oradata/orcl/temp01.dbf' offline;
Database altered.
SQL> alter database tempfile '/u01/oradata/orcl/temp01.dbf' drop including datafiles;
Database altered.
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/orcl/temp02.dbf