使用RMAN遷移檔案系統資料庫到ASM

us_yunleiwang發表於2013-12-05

--==================================

-- 使用RMAN移檔案系統數ASM

--==================================

 

    實際的工作程中,由於ASM管理的便利性,因此很多候需要檔案系庫遷移到ASM,本文演示瞭如何檔案系統數庫遷移到ASM例。

    如何ASM例及ASM管理請參

        ASM例及

        ASM 盤組及磁的管理

        使用 ASMCMD 工具管理ASM

       

一、主要步(假定ASM例已)

    1.算目標數(檔案系)的大小

    2.根據目標數的大小,ASM()可用磁

    3.為輔配置初始化引數檔案,密檔案,建目

    4.備份標數

    5.移目標數

       

二、

    本次移在同一臺主機實現,因此採用不同的ORACLE_SID

    境:Oracle Linux 5.4 + Oracle 10R2

    標數orcl

    orclasm

   

    1.算目標數(檔案系)的大小

        SQLshow parameter db_name

       

        NAME                                 TYPE        VALUE

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

        db_name                              string      orcl

       

        SQLselect * from v$version where rownum<2;

       

        BANNER

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

        Oracle Database 10Enterprise Edition Release 10.2.0.4.0 - Prod

   

        SQLselect sum(bytes)/1024/1024 ||'MB' from dba_segments;

       

        SUM(BYTES)/1024/1024||'MB'

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

        1195.5MB       

   

    2.為輔可用空,下面DG1中有3016MB可用空,可以滿移的需要

        ASMCMD> ls -s

        Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Name

           512   4096  1048576      6134     6032                0            3016              0  DG1/

           512   4096  1048576      2047     1997                0            1997              0  REV/

       

    3.配置

        a.啟動標數併為標數庫創pfile

            [oracle@oradb ~]$ echo $ORACLE_SID

            orcl

            [oracle@oradb ~]$ sqlplus / as sysdba

           

            idle> startup

            sys@ORCL> create pfile from spfile;

       

        b.制目標數pfile生成pfile並對行修改

            [oracle@oradb dbs]$ cd $ORACLE_HOME/dbs

            [oracle@oradb dbs]$ cp initorcl.ora initorclasm.ora

           

            修改initorclasm.ora

                檔案中所有的orcl使用替命令替換為orclasm(使用vi工具 :%s/orcl/orclasm/g)

                修改控制檔案1(DG1使用了normal redundancy),路徑為'+DG1/orclasm/controlfile/'--使用ASM注意目錄結構

                修改db_recovery_file_dest徑為'+REV'

                修改log_archive_dest_1徑為'LOCATION=+REV/orclasm'

                修改db_create_file_dest徑為'+DG1'

                增加下列引數()

                    *.db_file_name_convert=("orcl","orclasm")

                    *.log_file_name_convert=("orcl","orclasm")

 

            下面列出化的幾重要引數

                *.audit_file_dest='/u01/app/oracle/admin/orclasm/adump'

                *.background_dump_dest='/u01/app/oracle/admin/orclasm/bdump'

                *.control_files='+DG1/orclasm/controlfile/control01.ctl'

                *.core_dump_dest='/u01/app/oracle/admin/orclasm/cdump'

                *.db_name='orclasm'

                *.db_recovery_file_dest='+REV/orclasm'

                *.log_archive_dest_1='LOCATION=+REV/orclasm'           

                *.user_dump_dest='/u01/app/oracle/admin/orclasm/udump'

                *.db_create_file_dest='+DG1'

                *.db_file_name_convert=("orcl","orclasm")

                *.log_file_name_convert=("orcl","orclasm")

 

        c.根據剛剛修改引數創建目

            [oracle@oradb ~]$ mkdir -p $ORACLE_BASE/admin/orclasm/{a,b,c,u}dump

            [oracle@oradb ~]$ ls $ORACLE_BASE/admin/orclasm

            adump  bdump  cdump  udump

   

        d.建密檔案

            [oracle@oradb dbs]$ orapwd file=$ORACLE_HOME/dbs/orapworclasm password=oracle entries=8

       

    4.備份標數      

        a.標數庫應處歸檔模式下

            SQLselect name,log_mode from v$database;

 

            NAME      LOG_MODE

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

            ORCL      ARCHIVELOG   

       

        b.接到RMAN並進備份,此使用了非catalog方式

            [oracle@oradb ~]$ uniread rman target sys/oracle@orcl nocatalog

 

            RMAN> crosscheck archivelog all;       --驗歸檔日誌

 

            RMAN> delete expired archivelog all;   --無效的歸檔日誌

 

            RMAN> report obsolete;

 

            RMAN> delete noprompt obsolete;        --棄的備份

 

            RMAN> show channel;                    --看預設的備份

 

            RMAN configuration parameters are:

            CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/u01/bk/orcl/data_%d_%U';

 

            RMAN> show controlfile autobackup;    --看控制檔案的自動備份啟用情

 

            using target database control file instead of recovery catalog

            RMAN configuration parameters are:

            CONFIGURE CONTROLFILE AUTOBACKUP ON;

 

            RMAN> show controlfile autobackup format;   --看控制檔案的備份、格式

 

            RMAN configuration parameters are:

            CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO'/u01/bk/orcl/auto_ctl_%d_%F';

 

            RMAN> run{     --標數庫進備份,此備份為0增量包含了歸檔日誌,控制檔案spfile動備份

            2allocate channel ch1 device type disk;

            3backup as compressed backupset

            4> incremental level 0 database format '/u01/bk/orcl/data_%d_%U'

            5> plus archivelog format '/u01/bk/orcl/bk_lg_%U'

            6> tag='Inc0_log';

            7> release channel ch1;}      

 

    5.移目標數據到ASM

        a.看目標數SEQUENCE10,便於恢復時指定SEQUENCE

            SQLselect * from v$log;  

           

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

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

                     1          1          9   52428800          1 YES ACTIVE                  52044530-OCT-10

                     2          1         10   52428800          1 NO  CURRENT                 52058530-OCT-10

        

        b.看目標數據檔案的相息,後需要datafile指定檔名

            RMAN> report schema;

 

            Report of database schema

           

            List of Permanent Datafiles

            ===========================

            File Size(MB) Tablespace           RB segs Datafile Name

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

            1    480      SYSTEM               ***     /u01/app/oracle/oradata/orcl/system01.dbf

            2    25       UNDOTBS1             ***     /u01/app/oracle/oradata/orcl/undotbs01.dbf

            3    240      SYSAUX               ***     /u01/app/oracle/oradata/orcl/sysaux01.dbf

            4    5        USERS                ***     /u01/app/oracle/oradata/orcl/users01.dbf

            5    100      EXAMPLE              ***     /u01/app/oracle/oradata/orcl/example01.dbf

           

            List of Temporary Files

            =======================

            File Size(MB) Tablespace           Maxsize(MB) Tempfile Name

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

            1    20       TEMP                 32767       /u01/app/oracle/oradata/orcl/temp01.dbf

 

        c.asm例是否已正常提供服,以及磁狀態並啟動新的orclasm

            SQLshow parameter instance_name

           

            NAME                                 TYPE        VALUE

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

            instance_name                        string      +ASM

           

            SQLselect group_number,name,state,type,total_mb,free_mb,usable_file_mb fromv$asm_diskgroup;

           

            GROUP_NUMBER NAME                           STATE       TYPE     TOTAL_MB    FREE_MB USABLE_FILE_MB

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

                       1 DG1                            MOUNTED     NORMAL       6134      6032           3016

                       2 REV                            MOUNTED     EXTERN       2047      1997           1997

       

        d.啟動輔nomount狀態  

            [oracle@oradb ~]$ export ORACLE_SID=orclasm

            [oracle@oradb ~]$ sqlplus / as sysdba

 

            idle> startup nomount

            ORACLE instance started.

 

        e.使用RMAN接到目標數庫來完成

            [oracle@oradb dbs]$ rman auxiliary / target sys/redhat@orcl

            connected to target database: ORCL (DBID=1263182651)

            connected to auxiliary database: ORCLASM (not mounted)

 

            RMAN> run {

            2allocate auxiliary channel ach1 device type disk;

            3set until sequence 10 thread 1;

            4set newname for datafile 1 to '+DG1';

            5set newname for datafile 2 to '+DG1';

            6set newname for datafile 3 to '+DG1';

            7set newname for datafile 4 to '+DG1';

            8set newname for datafile 5 to '+DG1';

            9set newname for tempfile 1 to '+DG1';

            10>  duplicate target database to orclasm logfile

            11>  group 1('+DG1'size 5reuse,

            12>  group 2('+DG1'size 5reuse;

            13>  }

   

            contents of Memory Script:

            {

               Alter clone database open resetlogs;

            }

            executing Memory Script

           

            database opened

            Finished Duplicate Db at 30-OCT-10

   

    6.續處

        a.庫狀態並關閉數

            [oracle@oradb ~]$ export ORACLE_SID=orclasm

            [oracle@oradb ~]$ sqlplus / as sysdba

            SQLselect name,open_mode from v$database;

           

            NAME      OPEN_MODE

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

            ORCLASM   READ WRITE

           

            SQLshutdown immediate;

       

        b.使用vi工具編輯initorclasm.ora   

            除下列引數

            *.db_file_name_convert=("orcl","orclasm")

            *.log_file_name_convert=("orcl","orclasm")

   

        c.啟動數庫並創spfile

            SQL> startup

               

            SQLcreate spfile from pfile;

               

            SQL> startup force;  --如果是生產庫shutdown immediate,然後startup

   

    7.驗證遷

        SQLshow parameter db_name

       

        NAME                                 TYPE        VALUE

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

        db_name                              string      orclasm

        SQL> col name format a60

        SQLselect name,status from v$datafile;

       

        NAME                                                         STATUS

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

        +DG1/orclasm/datafile/system.256.752170937                   SYSTEM

        +DG1/orclasm/datafile/undotbs1.259.752170937                 ONLINE

        +DG1/orclasm/datafile/sysaux.257.752170937                   ONLINE

        +DG1/orclasm/datafile/users.260.752170937                    ONLINE

        +DG1/orclasm/datafile/example.258.752170937                  ONLINE

 

        SQLselect * from v$log;

       

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

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

                 1          1          5    5242880          2 YES INACTIVE                563716 27-MAY-11

                 2          1          6    5242880          2 NO  CURRENT                 583985 27-MAY-11

                

        SQLselect * from v$logfile;

       

            GROUP# STATUS  TYPE    MEMBER                                             IS_

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

                 2         ONLINE  +DG1/orclasm/onlinelog/group_2.263.752171103       NO

                 1 STALE   ONLINE  +DG1/orclasm/onlinelog/group_1.262.752171103       NO

                 1 STALE   ONLINE  +REV/orclasm/onlinelog/group_1.256.752171103       YES

                 2         ONLINE  +REV/orclasm/onlinelog/group_2.257.752171105       YES

                

        SQLselect file#,creation_change#, status,enabled,bytes,name from v$tempfile;

       

             FILE# CREATION_CHANGE# STATUS  ENABLED         BYTES NAME

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

                 1           464714 ONLINE  READ WRITE   20971520+DG1/orclasm/tempfile/temp.264.752171113  

       

        --如果在使用duplicate時沒有生成tempfile檔案,可以使用下面的方式新增tempfile檔案。

            alter tablespace temp add tempfile '+DG1' size 100autoextend off;      

           

        --可以新增歸檔修改一下歸檔

        --接到ASM歸檔

       

        SQLselect instance_name,status from v$instance;

       

        INSTANCE_NAME                  STATUS

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

        +ASM                           STARTED

       

        SQLalter diskgroup REV add directory '+REV/orclasm/arch';

        

        Diskgroup altered.

       

        --orclasm例中修改歸檔

        SQLselect instance_name,status from v$instance;

       

        INSTANCE_NAME    STATUS

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

        orclasm          OPEN

       

        SQLalter system set log_archive_dest_1='LOCATION=+REV/orclasm/arch';

       

        System altered.

       

        SQLselect name from v$archived_log where rownum<2 order by stamp;

       

        NAME

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

        +REV/orclasm/1_1_752171102.arc

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23490154/viewspace-1062410/,如需轉載,請註明出處,否則將追究法律責任。

相關文章