RMAN 異機遷移實戰操作-附加常用命令

來源:互聯網
上載者:User

RMAN 異機遷移實戰操作-附加常用命令

操作操作環境

 原始伺服器      OEL 6.3 11G R2 11.2.0.3
目標伺服器    OEL 6.3 11G R2 11.2.0.3
原始伺服器和目標伺服器存放資料路徑一樣

 原始伺服器
[Oracle@mxq ~]$ rman target /

 Recovery Manager: Release 11.2.0.2.0 - Production on Sat May 16 08:51:05 2015

 Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 connected to target database: ORACLE11 (DBID=2573050700)

 RMAN> run
 {allocate channel orademo type disk MAXPIECESIZE 1024m;
 backup incremental level 0 as compressed backupset database include current controlfile tag='full' format '/home/oracle/db_%s_%p_%t' plus archivelog tag='arch_all' format  '/home/oracle/arch_%s_%p_%t' delete input;
 }2> 3> 4>

 released channel: ORA_DISK_1
 allocated channel: orademo
 channel orademo: SID=147 device type=DISK


 Starting backup at 16-MAY-15
 current log archived
 channel orademo: starting compressed archived log backup set
 channel orademo: specifying archived log(s) in backup set
 input archived log thread=1 sequence=96 RECID=69 STAMP=879840530
 channel orademo: starting piece 1 at 16-MAY-15
 channel orademo: finished piece 1 at 16-MAY-15
 piece handle=/home/oracle/arch_59_1_879840531 tag=ARCH_ALL comment=NONE
 channel orademo: backup set complete, elapsed time: 00:00:01
 channel orademo: deleting archived log(s)
 archived log file name=/orafile/arc/1_96_879804940.arc RECID=69 STAMP=879840530
 Finished backup at 16-MAY-15

 Starting backup at 16-MAY-15
 channel orademo: starting compressed incremental level 0 datafile backup set
 channel orademo: specifying datafile(s) in backup set
 including current SPFILE in backup set
 including current control file in backup set
 input datafile file number=00002 name=/orafile/oradata/sysaux01.dbf
 input datafile file number=00001 name=/orafile/oradata/system01.dbf
 input datafile file number=00003 name=/orafile/oradata/undotbs01.dbf
 input datafile file number=00004 name=/orafile/oradata/users01.dbf
 channel orademo: starting piece 1 at 16-MAY-15
 channel orademo: finished piece 1 at 16-MAY-15
 piece handle=/home/oracle/db_60_1_879840533 tag=FULL comment=NONE
 channel orademo: backup set complete, elapsed time: 00:02:55
 Finished backup at 16-MAY-15

 Starting backup at 16-MAY-15
 current log archived
 channel orademo: starting compressed archived log backup set
 channel orademo: specifying archived log(s) in backup set
 input archived log thread=1 sequence=97 RECID=72 STAMP=879840713
 channel orademo: starting piece 1 at 16-MAY-15
 channel orademo: finished piece 1 at 16-MAY-15
 piece handle=/home/oracle/arch_61_1_879840714 tag=ARCH_ALL comment=NONE
 channel orademo: backup set complete, elapsed time: 00:00:01
 channel orademo: deleting archived log(s)
 archived log file name=/orafile/arc/1_97_879804940.arc RECID=72 STAMP=879840713
 Finished backup at 16-MAY-15
 released channel: orademo

把新的備份組拷貝到目標伺服器
[oracle@mxq ~]$ cd /home/oracle/
 [oracle@mxq ~]$ ls
 arch_59_1_879840531  arch_61_1_879840714  db_60_1_879840533
 [oracle@mxq ~]$ ll
 total 248900
 -rw-r----- 1 oracle oinstall    219648 May 16 08:08 arch_59_1_879840531
 -rw-r----- 1 oracle oinstall  1256448 May 16 08:11 arch_61_1_879840714
 -rw-r----- 1 oracle oinstall 253394944 May 16 08:11 db_60_1_879840533
 [oracle@mxq ~]$ scp * [email protected]:/home/oracle/
 [email protected]'s password:
 arch_59_1_879840531                          100%  215KB 214.5KB/s  00:00   
 arch_61_1_879840714                          100% 1227KB  1.2MB/s  00:00   
 db_60_1_879840533                            100%  242MB  13.4MB/s  00:18 

目標伺服器

 提示:
 如果已經資料檔案、控制檔案、線上記錄檔、參數檔案那麼新刪除掉在進行做恢複不然後面報錯

[oracle@mxq ~]$ rman target /

 Recovery Manager: Release 11.2.0.2.0 - Production on Sun May 17 12:10:05 2015

 Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 connected to target database (not started)


 RMAN> startup force nomount;

 Oracle instance started

 Total System Global Area    521936896 bytes

 Fixed Size                    2228072 bytes
 Variable Size                159383704 bytes
 Database Buffers            352321536 bytes
 Redo Buffers                  8003584 bytes


 RMAN> restore spfile from '/home/oracle/db_54_1_879855779';

 Starting restore at 17-MAY-15
 allocated channel: ORA_DISK_1
 channel ORA_DISK_1: SID=134 device type=DISK

 channel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/db_54_1_879855779
 channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
 Finished restore at 17-MAY-15

 RMAN> shutdown immediate;

 Oracle instance shut down

 RMAN> set DBID=2573050700

 executing command: SET DBID

 RMAN> startup nomount;

 connected to target database (not started)
 Oracle instance started

 Total System Global Area    521936896 bytes

 Fixed Size                    2228072 bytes
 Variable Size                176160920 bytes
 Database Buffers            335544320 bytes
 Redo Buffers                  8003584 bytes


 RMAN> restore controlfile from '/home/oracle/db_54_1_879855779';

 Starting restore at 17-MAY-15
 allocated channel: ORA_DISK_1
 channel ORA_DISK_1: SID=134 device type=DISK

 channel ORA_DISK_1: restoring control file
 channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
 output file name=/orafile/oradata/control01.ctl
 output file name=/orafile/oradata/control02.ctl
 Finished restore at 17-MAY-15

 RMAN> alter database mount;

 database mounted


 RMAN> list backup summary;


 List of Backups
 ===============
 Key    TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
 ------- -- -- - ----------- --------------- ------- ------- ---------- ---
 10      B  A  A DISK        16-MAY-15      1      1      YES        ARCH_ALL
 11      B  A  A DISK        16-MAY-15      1      1      YES        ARCH_ALL
 12      B  0  A DISK        16-MAY-15      1      1      YES        FULL

 RMAN> restore database from tag='FULL';

 Starting restore at 17-MAY-15
 allocated channel: ORA_DISK_1
 channel ORA_DISK_1: SID=133 device type=DISK

 channel ORA_DISK_1: starting datafile backup set restore
 channel ORA_DISK_1: specifying datafile(s) to restore from backup set
 channel ORA_DISK_1: restoring datafile 00001 to /orafile/oradata/system01.dbf
 channel ORA_DISK_1: restoring datafile 00002 to /orafile/oradata/sysaux01.dbf
 channel ORA_DISK_1: restoring datafile 00003 to /orafile/oradata/undotbs01.dbf
 channel ORA_DISK_1: restoring datafile 00004 to /orafile/oradata/users01.dbf
 channel ORA_DISK_1: reading from backup piece /home/oracle/db_60_1_879840533
 channel ORA_DISK_1: piece handle=/home/oracle/db_60_1_879840533 tag=FULL
 channel ORA_DISK_1: restored backup piece 1
 channel ORA_DISK_1: restore complete, elapsed time: 00:01:45
 Finished restore at 17-MAY-15

 RMAN> recover database from tag='ARCH_ALL';

 Starting recover at 17-MAY-15
 using channel ORA_DISK_1

 starting media recovery

 archived log for thread 1 with sequence 97 is already on disk as file /orafile/arc/1_97_879804940.arc
 archived log for thread 1 with sequence 1 is already on disk as file /orafile/arc/1_1_879955249.arc
 archived log for thread 1 with sequence 2 is already on disk as file /orafile/arc/1_2_879955249.arc
 archived log for thread 1 with sequence 3 is already on disk as file /orafile/arc/1_3_879955249.arc
 archived log file name=/orafile/arc/1_97_879804940.arc thread=1 sequence=97
 archived log file name=/orafile/arc/1_2_879955249.arc thread=1 sequence=2
 media recovery complete, elapsed time: 00:00:17
 Finished recover at 17-MAY-15

 RMAN> alter database open;

 database opened

 -----------------------
 The migration completed

附加常用命令:

1、概念

 差異增量:是備份上級及同級備份以來所有變化的資料區塊,差異增量是預設增量備份方式
 累積增量:是備份上級備份以來所有變化的塊

 因為累積增量是備份上級備份以來所有變化的資料區塊,所以累積增量需要更多的備份時間,同時需要較小的恢復;
 而差異增量正好相反,它可以備份同級備份以來變化的資料區塊。所以會減少備份時間,但需要更多的恢復.在oracle
 9中增量備份需要通過掃描整個資料庫的資料區塊才能知道哪些資料區塊發生了變化,這是一個代價很大,時間很長的過程,
 而且由於增量備份形成多個不同的備份組,使恢複變得更加不��靠,所以增量備份在版本9中仍然不被推薦使用;在10g中,
 增量備份作了很大的改進,不需要再掃描所有資料區塊就能得知哪些資料區塊發生變化,從而大大提升備份效率。但這些卻以犧牲磁碟i/o為代價,
 所以在oltp事務系統中還得衡量是否願意以i/o為代價來保證安全及高可用性。10g還支援增量合并,增量備份可支援7級增量。

 

1、鏡像複製(Image Copies)

  鏡像複製實際上就是資料檔案、控制檔案或歸檔檔案的複製,與使用者通過作業系統命令建立的檔案複製實質一樣,只不過RMAN是利用目標資料庫中的服務進程來完成檔案複製,而使用者則是用作業系統命令。所以鏡像複製的方式體現不出RMAN的優勢,也並非我們討論的重點,大家瞭解一下即可(啥?想知道鏡像複製咋用?卡,問村長去~~~~~)。

2、備份組(Backup Sets)

  備份組是通過RMAN建立的邏輯備份對象。一個備份組中可以包含多個資料檔案、控制檔案或歸檔檔案。備份組在物理上是由多個備份片段組成,每個備份片段是一個作業系統檔案。

 

1. List 當前RMAN所備份的資料庫:

    完全恢複
   
    restore database 修複資料庫
    recover database 恢複資料庫
   
    不完全恢複
   
    set until time '2012-06-06 21:00:00'; 設定基於時間不完全恢複
    set until scn 3404460;                設定基於scn不完全恢複
    set until sequence=3;                設定基於序號不全恢複
    restore database
    recover database
   
    backup
       
        備份整個資料庫
      後面指定備份到那裡
     
        bakckup database format='/home/oracle/all_U'
       
        備份當前控制檔案
     
        backup current controlfile format='/home/oracle/all_U'
       
        備份資料表空間
     
        backup tablespace user format='/home/oracle/all_U'
       
        備份參數檔案
     
        backup spfile format '/home/oracle/spfile_U'
       
        備份所有歸檔日誌,刪除備份後的歸檔日誌
     
        backup archivelog all delete input format '/home/oracle/arc_U'
       
       
      保留原則:

 基於時間:

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF  n  DAYS;

基於冗餘數量:

CONFIGURE RETENTION POLICY TO REDUNDANCY  n
       


    1.1. list backup summary; --概述可用的備份
          list incarnation;--匯總查詢

                    --如果備份檔案多的話多用這兩個list命令可以對備份檔案有個總體瞭解。
        B 表示backup
        A 表示Archivelog、 F 表示full backup、 0,1,2 表示incremental level備份
        A 表示可用AVALIABLE、 X 表示EXPIRED

        列出可以用備份組
        list backup of database summary
        列出可以用的歸檔日誌
        list backup of archivelog all summary
        列出可以用的資料表空間
        list backup of tablespace users summary;
        列出可以用的資料檔案
        list backup of datafile n,n,n summary
   
    列出所有備份參數檔案
    list backup of spfile;


    列出所有備份的控制檔案
    list backup of controlfile;


    列出所有備份資料檔案
    list backup of datafle n,n,n,n;


    列出所有的備份資料表空間
    list backup of tablespace tablespace_name;
       
    列出到期所有到期備份
    list expired backup;
   
    列出所有備份歸檔檔案
    list archivelog all;
   
    delele
   
    刪除所有過舊的備份
    delete noprompt obsolete;
   
    刪除到期備份
  delete noprompt expired backup;
  上面命令物理備份檔案被刪除通過下面檢查備份是否可用
  corsscheck backup;
 
  刪除所有到期歸檔
  delete expired archivelog all;
   
  刪除指定60天后歸檔
  delete archivelog all completed before 'sysdate-60’;
 
  crosscheck backup of archivelog all;
 
  crosscheck backup of controlfile  核對控制檔案的備份組;
 
  crosscheck backup of spfile    核對SPFILE的備份組;

--------------------------------------推薦閱讀 --------------------------------------

RMAN 配置歸檔日誌刪除策略

Oracle基礎教程之通過RMAN複製資料庫

RMAN備份策略制定參考內容

RMAN備份學習筆記

OracleDatabase Backup加密 RMAN加密

--------------------------------------分割線 --------------------------------------

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.