利用RMAN在文件系统与ASM之间迁移数据库(2)

13.对于主库,要迁移联机重做日志文件是通过增加新的重做日志文件并存储在ASM中并删除旧的重做日志文件。对于备库,就是删除旧的备重做日志并增加新的备重做日志并存储在ASM中
SQL> select * from v$log;

GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS            FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ----------------  ------------- ------------
        1          1        97  52428800          1 NO  CURRENT            1288360      01-APR-15
        2          1        95  52428800          1 YES INACTIVE          1226685      30-MAR-15
        3          1        96  52428800          1 YES INACTIVE          1268619      31-MAR-15

SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database add logfile group 2 '+DISK1/redo02.log' size 50M;

Database altered.

SQL> alter database drop logfile group 3;

Database altered.

SQL> alter database add logfile group 3 '+DISK1/redo03.log' size 50M;

Database altered.

SQL> alter system switch logfile;

System altered.

SQL> alter database drop logfile group 1;
alter database drop logfile group 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance test (thread 1)
ORA-00312: online log 1 thread 1: '/u01/app/Oracle/oradata/test/redo01.log'


SQL> alter database clear logfile group 1;

Database altered.

SQL> alter database drop logfile group 1;

Database altered.

SQL> alter database add logfile group 1 '+DISK1/redo01.log' size 50M;

Database altered.

将数据库从ASM中迁移到文件系统
1.记录数据库迁移之前的数据文件,控制文件,联机重做日志文件的文件名
SQL> select member,status from v$logfile;

MEMBER                                                                          STATUS
-------------------------------------------------------------------------------- -------
+DISK1/redo03.log
+DISK1/redo02.log
+DISK1/redo01.log

SQL> show parameter control_files

NAME                                TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      +DISK1/control01.ctl

SQL> select name,status from v$datafile;

NAME                                                                            STATUS
-------------------------------------------------------------------------------- -------
+DISK1/test/datafile/system.266.875894803                                        SYSTEM
+DISK1/test/datafile/undotbs1.263.875894899                                      ONLINE
+DISK1/test/datafile/sysaux.267.875894845                                        ONLINE
+DISK1/test/datafile/users.262.875894907                                        ONLINE
+DISK1/test/datafile/example.265.875894871                                      ONLINE
+DISK1/test/datafile/tspitr.264.875894885                                        ONLINE
+DISK1/test/datafile/test.261.875894909                                          ONLINE

7 rows selected

2.将数据库文件作为副本备份到ASM磁盘组
RMAN> backup as copy incremental level 0 database format '/u02/asm_backup/%U' tag 'NO_ASM_MIGRATION';

Starting backup at 2015-04-01 20:47:32
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=140 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=+DISK1/test/datafile/system.266.875894803
output filename=/u02/asm_backup/data_D-TEST_I-2168949517_TS-SYSTEM_FNO-1_4rq3amf5 tag=NO_ASM_MIGRATION recid=46 stamp=875911696
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003 name=+DISK1/test/datafile/sysaux.267.875894845
output filename=/u02/asm_backup/data_D-TEST_I-2168949517_TS-SYSAUX_FNO-3_4sq3amgj tag=NO_ASM_MIGRATION recid=47 stamp=875911724
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005 name=+DISK1/test/datafile/example.265.875894871
output filename=/u02/asm_backup/data_D-TEST_I-2168949517_TS-EXAMPLE_FNO-5_4tq3amhm tag=NO_ASM_MIGRATION recid=48 stamp=875911742
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile fno=00006 name=+DISK1/test/datafile/tspitr.264.875894885
output filename=/u02/asm_backup/data_D-TEST_I-2168949517_TS-TSPITR_FNO-6_4uq3ami5 tag=NO_ASM_MIGRATION recid=49 stamp=875911756
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002 name=+DISK1/test/datafile/undotbs1.263.875894899
output filename=/u02/asm_backup/data_D-TEST_I-2168949517_TS-UNDOTBS1_FNO-2_4vq3amik tag=NO_ASM_MIGRATION recid=50 stamp=875911766
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004 name=+DISK1/test/datafile/users.262.875894907
output filename=/u02/asm_backup/data_D-TEST_I-2168949517_TS-USERS_FNO-4_50q3amin tag=NO_ASM_MIGRATION recid=51 stamp=875911768
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile fno=00007 name=+DISK1/test/datafile/test.261.875894909
output filename=/u02/asm_backup/data_D-TEST_I-2168949517_TS-TEST_FNO-7_51q3amio tag=NO_ASM_MIGRATION recid=52 stamp=875911769
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2015-04-01 20:49:29

Starting Control File and SPFILE Autobackup at 2015-04-01 20:49:30
piece handle=/u02/c-2168949517-20150401-16 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-04-01 20:49:34


[oracle@oracle11g asm_backup]$ ls -lrt
total 1014840
-rw-r----- 1 oracle oinstall 482353152 Apr  1 20:48 data_D-TEST_I-2168949517_TS-SYSTEM_FNO-1_4rq3amf5
-rw-r----- 1 oracle oinstall 293609472 Apr  1 20:48 data_D-TEST_I-2168949517_TS-SYSAUX_FNO-3_4sq3amgj
-rw-r----- 1 oracle oinstall 104865792 Apr  1 20:49 data_D-TEST_I-2168949517_TS-EXAMPLE_FNO-5_4tq3amhm
-rw-r----- 1 oracle oinstall 104865792 Apr  1 20:49 data_D-TEST_I-2168949517_TS-TSPITR_FNO-6_4uq3ami5
-rw-r----- 1 oracle oinstall  31465472 Apr  1 20:49 data_D-TEST_I-2168949517_TS-UNDOTBS1_FNO-2_4vq3amik
-rw-r----- 1 oracle oinstall  10493952 Apr  1 20:49 data_D-TEST_I-2168949517_TS-USERS_FNO-4_50q3amin
-rw-r----- 1 oracle oinstall  10493952 Apr  1 20:49 data_D-TEST_I-2168949517_TS-TEST_FNO-7_51q3amio


为了确保数据库能执行一致性恢复,归档当前联机重做日
RMAN> sql 'alter system archive log current';

sql statement: alter system archive log current

如果数据库很大在执行上面的备份时可能会要很长时间。如果在执行备份时有大量的数据库活动,可以对数据库生成一个增量备份在迁移之前将0级备份之后的改变刷新到0级备份所创建的副本中。
RMAN> backup incremental level 1 for recover of copy with tag 'NO_ASM_MIGRATION' database;

Starting backup at 2015-04-01 20:51:43
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=+DISK1/test/datafile/system.266.875894803
input datafile fno=00003 name=+DISK1/test/datafile/sysaux.267.875894845
input datafile fno=00005 name=+DISK1/test/datafile/example.265.875894871
input datafile fno=00006 name=+DISK1/test/datafile/tspitr.264.875894885
input datafile fno=00002 name=+DISK1/test/datafile/undotbs1.263.875894899
input datafile fno=00004 name=+DISK1/test/datafile/users.262.875894907
input datafile fno=00007 name=+DISK1/test/datafile/test.261.875894909
channel ORA_DISK_1: starting piece 1 at 2015-04-01 20:51:44
channel ORA_DISK_1: finished piece 1 at 2015-04-01 20:52:19
piece handle=/u02/ora_test875911904_1631 tag=NO_ASM_MIGRATION comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 2015-04-01 20:52:19

Starting Control File and SPFILE Autobackup at 2015-04-01 20:52:19
piece handle=/u02/c-2168949517-20150401-17 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-04-01 20:52:23


RMAN> recover copy of database with tag 'NO_ASM_MIGRATION';

Starting recover at 2015-04-01 20:52:57
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile copies to recover
recovering datafile copy fno=00001 name=/u02/asm_backup/data_D-TEST_I-2168949517_TS-SYSTEM_FNO-1_4rq3amf5
recovering datafile copy fno=00002 name=/u02/asm_backup/data_D-TEST_I-2168949517_TS-UNDOTBS1_FNO-2_4vq3amik
recovering datafile copy fno=00003 name=/u02/asm_backup/data_D-TEST_I-2168949517_TS-SYSAUX_FNO-3_4sq3amgj
recovering datafile copy fno=00004 name=/u02/asm_backup/data_D-TEST_I-2168949517_TS-USERS_FNO-4_50q3amin
recovering datafile copy fno=00005 name=/u02/asm_backup/data_D-TEST_I-2168949517_TS-EXAMPLE_FNO-5_4tq3amhm
recovering datafile copy fno=00006 name=/u02/asm_backup/data_D-TEST_I-2168949517_TS-TSPITR_FNO-6_4uq3ami5
recovering datafile copy fno=00007 name=/u02/asm_backup/data_D-TEST_I-2168949517_TS-TEST_FNO-7_51q3amio
channel ORA_DISK_1: reading from backup piece /u02/ora_test875911904_1631
channel ORA_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875911904_1631 tag=NO_ASM_MIGRATION
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished recover at 2015-04-01 20:53:00

Starting Control File and SPFILE Autobackup at 2015-04-01 20:53:00
piece handle=/u02/c-2168949517-20150401-18 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-04-01 20:53:04

3.在/u02/asm_backup目录中创建一个SPFILE文件副本。将要迁移的数据库SPFILE文件存储为
/u02/asm_backup/spfiletest.ora如果数据库是使用的SPFILE启动,就执行以下命令:
RMAN> run
2> {
3> backup as backupset spfile;
4> restore spfile to '/u02/asm_backup/spfiletest.ora';
5> }

Starting backup at 2015-04-01 20:55:31
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 2015-04-01 20:55:32
channel ORA_DISK_1: finished piece 1 at 2015-04-01 20:55:33
piece handle=/u02/ora_test875912132_1661 tag=TAG20150401T205531 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-04-01 20:55:33

Starting Control File and SPFILE Autobackup at 2015-04-01 20:55:33
piece handle=/u02/c-2168949517-20150401-19 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-04-01 20:55:36

Starting restore at 2015-04-01 20:55:38
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: restoring SPFILE
output filename=/u02/asm_backup/spfiletest.ora
channel ORA_DISK_1: reading from backup piece /u02/c-2168949517-20150401-19
channel ORA_DISK_1: restored backup piece 1
piece handle=/u02/c-2168949517-20150401-19 tag=TAG20150401T205533
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2015-04-01 20:55:39

[oracle@oracle11g asm_backup]$ ls -lrt
total 1014844
-rw-r----- 1 oracle oinstall  10493952 Apr  1 20:52 data_D-TEST_I-2168949517_TS-USERS_FNO-4_50q3amin
-rw-r----- 1 oracle oinstall  31465472 Apr  1 20:52 data_D-TEST_I-2168949517_TS-UNDOTBS1_FNO-2_4vq3amik
-rw-r----- 1 oracle oinstall 104865792 Apr  1 20:52 data_D-TEST_I-2168949517_TS-TSPITR_FNO-6_4uq3ami5
-rw-r----- 1 oracle oinstall  10493952 Apr  1 20:52 data_D-TEST_I-2168949517_TS-TEST_FNO-7_51q3amio
-rw-r----- 1 oracle oinstall 482353152 Apr  1 20:52 data_D-TEST_I-2168949517_TS-SYSTEM_FNO-1_4rq3amf5
-rw-r----- 1 oracle oinstall 293609472 Apr  1 20:52 data_D-TEST_I-2168949517_TS-SYSAUX_FNO-3_4sq3amgj
-rw-r----- 1 oracle oinstall 104865792 Apr  1 20:52 data_D-TEST_I-2168949517_TS-EXAMPLE_FNO-5_4tq3amhm
-rw-r----- 1 oracle oinstall      2560 Apr  1 20:55 spfiletest.ora

如果数据库是使用PFILE启动,可以在SQL*Plus中执行create spfile命令来创建SPFILE
SQL>create spfile='/u02/asm_backup/spfiletest.ora' from pfile='+DISK1/inittest.ora'

File created.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c0029ab565deb2079ed1e29ebe653229.html