【基本操作】RMAN 相關

GM_DBA發表於2014-11-05
RMAN> show all;    可設定引數
RMAN configuration parameters for database with db_unique_name ALVIN are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_alvin.f'; # default

1、連線到目標資料庫(不用恢復目錄資料庫):
      Rman nocatalog target sys/change_on_isntall@testdb
      Rman catalog rman_user/rman_user@ora9rc target sys/change_on_install@testdb
2、SHOW命令:
      顯示rman配置: RMAN> show all;
3、REPORT命令:
   1、RMAN> report schema                        報告目標資料庫的物理結構;
   2、RMAN>report need backup days=3;            報告最近3天沒有被備份的資料檔案;
   3、RMAN> report need backup days 3 tablespace users;   在USERS表空間上3天未備份的資料檔案;
   4、RMAN> report need backup incremental 3;   報告恢復資料檔案需要的增量備份個數超過3次的資料檔案;
   5、RMAN> report need backup redundancy 2 database;           報告備份檔案低於2份的所有資料檔案;
             RMAN>report need backup redundancy=2;
   6、RMAN> report need backup recovery window of 6 days;     報告檔案報表的恢復需要超過6天的歸檔日誌的資料檔案;
   7、RMAN> report unrecoverable;               報告資料庫所有不可恢復的資料檔案;
   8、RMAN> report obsolete redunndancy 2; 報告備份次數超過2次的陳舊備份;
   9、RMAN>report obsolete;                       報告丟棄的備份;
4、LIST命令:列出備份資訊
   1、列出資料檔案備份集
     RMAN> list backup         列出詳細備份;
     RMAN> list expired backup     列出過期備份;
     RMAN> list backup of database;     列出所有資料檔案的備份集;
     RMAN> list backup of tablespace user01; 列出特定表空間的所有資料檔案備份集;
   2、RMAN> list backup of controlfile     列出控制檔案備份集;
   3、RMAN> list backup of archivelog all      列出歸檔日誌備份集詳細資訊;
        RMAN>list archivelog all;      列出歸檔日誌備份集簡要資訊
   4、RMAN> list backup of spfile              列出SPFILE備份集;
   5、RMAN> list copy of datafile 5        列出資料檔案映像副本;
   6、RMAN> list copy of controlfile           列出控制檔案映像副本;
   7、RMAN> list copy of archivelog all    列出歸檔日誌映像副本;
   8、RMAN> list incarnation of database       列出對應物/列出資料庫副本;
   9、RMAN>list backup summary;    概述可用的備份;
        B表示backup
       F表示FULL
        A表示archive log
      0 1表示incremental backup
      S說明備份狀態(A AVAILABLE   X EXPIRED )
      10、RMAN>list backup by file    按備份型別列出備份;
                    按照資料檔案備份,歸檔日誌備份,控制檔案備份,伺服器引數檔案備份 列出
5、CROSSCHECK命令:校驗備份資訊
   1、RMAN> crosscheck backup             核對所有備份集;   
   2、RMAN> crosscheck backup of database      核對所有資料檔案的備份集;   
   3、RMAN> crosscheck backup of tablespace users      核對特定表空間的備份集;   
   4、RMAN> crosscheck backup of datafile 4    核對特定資料檔案的備份集;   
   5、RMAN> crosscheck backup of controlfile   核對控制檔案的備份集;   
   6、RMAN> crosscheck backup of spfile    核對SPFILE的備份集;   
   7、RMAN> crosscheck backup of archivelog sequence 3 核對歸檔日誌的備份集;   
   8、RMAN> crosscheck copy               核對所有映像副本;   
   9、RMAN> crosscheck copy of database       核對所有資料檔案的映像副本;   
   10、RMAN> crosscheck copy of tablespace users       核對特定表空間的映像副本;   
   11、RMAN> crosscheck copy of datafile 6        核對特定資料檔案的映像副本;   
   12、RMAN> crosscheck copy of archivelog sequence 4  核對歸檔日誌的映像副本;   
   13、RMAN> crosscheck copy of controlfile       核對控制檔案的映像副本;  
   14、RMAN> crosscheck backup tag='SAT_BACKUP';
   15、RMAN> crosscheck backup completed after 'sysdate - 2'
   16、RMAN> crosscheck backup completed between 'sysdate - 5' and 'sysdate -2 '
   17、RMAN> crosscheck backup device type sBT;
   18、RMAN> crosscheck archivelog all;
   19、RMAN> crosscheck archivelog like '%ARC00012.001'
   20、RMAN> crosscheck archivelog from sequence 12;
   21、RMAN> crosscheck archivelog until sequence 522;
6、DELETE:刪除備份
   1、RMAN> delete obsolete;      刪除陳舊備份;
   2、RMAN> delete expired backup; 刪除EXPIRED備份     
   3、RMAN> delete expired copy;   刪除EXPIRED副本;
   4、RMAN> delete backupset 19;   刪除特定備份集;
   5、RMAN> delete backuppiece ''d:\backup\DEMO_19.bak''   刪除特定備份片;
   6、RMAN> delete backup      刪除所有備份集;
   7、RMAN> delete datafilecopy ''d:\backup\DEMO_19.bak''  刪除特定映像副本;
   8、RMAN> delete copy   刪除所有映像副本;
   9、RMAN> delete archivelog all delete input;
        RMAN> delete backupset 22 format = ''d:\backup\%u.bak'' delete input
                       在備份後刪除輸入物件;
   10、RMAN> delete backupset id;
7、CHANGE命令:改變備份集的狀態
   1、RMAN> change backupset 22 unavailable      改變備份集狀態;   
   2、RMAN> change datafilecopy ''d:\backup\demo_37.bak'' unavailable     改變映像副本狀態;
   3、RMAN> change backupset 156 keep forever logs         使備份集156永久保留;
   4、RMAN> change backupset 198 keep until ''sysdate+60'' logs       使備份集198保留60天;
   5、RMAN> change backupset 156 nokeep         免除備份集156的保留期限;
   6、change backupset 117,118 delete;
   7、change backuppiece 1304 delete;
   8、change archivelog until logseq =544 delete;
8、CONFIGURE命令
   1顯示當前的配置資訊
      1.01 RMAN> show all;
      1.02查詢RMAN設定中非預設值:  
     SQL> select name,value from v$rman_configuration;
    2.常用的configure選項
       2.01儲存策略(retention policy)
         configure retention policy to recovery window of 3 days;
         configure retention policy to redundancy 3;
         configure retention policy clear;
       2.02備份優化backup optimization
         configure backup optimization on;
         configure backup optimization off;
         configure backup optimization clear;
       2.03預設裝置default device type
        configure default device type to disk;
        configure default device type to stb;
        configure default device type clear;
       2.04控制檔案controlfile
        configure controlfile autobackup on;
        configure controlfile autobackup format for device type disk to '/cfs01/backup/conf/conf_%F';
        configure controlfile autobackup clear;
        configrue controlfile autobackup format for device type disk clear;
        configrue snapshot controlfile name to '/cfs01/backup/snapcf/scontrofile.snp';
        configrue snapshot controlfile name clear;
       2.05並行數(通道數) device type disk|stb parallelism n;
        configure device type disk|stb parallelism 2;
        configure device type disk|stb clear;
        configure channel device type disk format 'e/:rmanback_%U';
        configure channel device type disk maxpiecesize 100m
        configure channel device type disk rate 1200K
        configure channel 1 device type disk format 'e/:rmanback_%U';
        configure channel 1 device type disk maxpiecesize 100m
       2.06生成備份副本datafile|archivelog backup copies
        configure datafile backup copies for device type disk|stb to 3;
        configure archivelog backup copies for device type disk|stb to 3;
        configure datafile|archivelog backup copies for device type disk|stb clear
        backup device type disk database
          format '/disk1/backup/%U', '/disk2/backup/%U', '/disk3/backup/%U';
       2.07排除選項exclude
        configure exclude for tablespace 'users';
        configrue exclude clear;
       2.08備份集大小maxsetsize
        configure maxsetsize to 1G|1000M|1000000K|unlimited;
        configure maxsetsize clear;
       2.09其它選項auxiliary
        CONFIGURE AUXNAME FOR DATAFILE 1 TO '/oracle/auxfiles/aux_1.f';
        CONFIGURE AUXNAME FOR DATAFILE 2 TO '/oracle/auxfiles/aux_2.f';
        CONFIGURE AUXNAME FOR DATAFILE 3 TO '/oracle/auxfiles/aux_3.f';
        CONFIGURE AUXNAME FOR DATAFILE 4 TO '/oracle/auxfiles/aux_4.f';
        CONFIGURE AUXNAME FOR DATAFILE 1 CLEAR;
9、CATALOG命令   用於追加備份記錄到RMAN資料庫中。
    1、RMAN> catalog datafilecopy ''d:\backup\user01.bak'';
      RMAN>catalog controlfile ''d:\backup\demo.ctl'';
      RMAN> catalog archivelog ''d:\backup\demo_25.bak'';
    註冊副本;
    2、RMAN> catalog backuppiece ''d:\backup\demo_40.dbf''        註冊備份片;
    3、RMAN> catalog start with ''d:\bak''         註冊特定目錄的所有備份檔案;
    4、RMAN> change datafilecopy ''d:\bak\user01.bak'' uncatalog;
        RMAN> change controlfilecopy ''d:\bak\demo.ctl'' uncatalog;
        RMAN> change backuppiece ''d:\bak\demo_25.bak'' uncatalog;
        登出備份記錄
10、FORMAT字串替代變數:
    使用FORMAT引數時可使用的各種替換變數,如下:
      %d:資料庫名稱;
      %D:位於該月中的天數(DD);
      %M:位於該年中的月份(MM);
      %F:一個基於DBID唯一的名稱,這個格式的形式為c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII為該資料庫的DBID,
      YYYYMMDD為日期,QQ是一個1-256的序列;
      %n:資料庫名稱,並且會在右側用x字元進行填充,使其保持長度為8;
      %u:是一個由備份集編號和建立時間壓縮後組成的8字元名稱。利用%u可以為每個備份集生成一個唯一的名稱;
      %p:表示備份集中備份片段的編號,從1開始編號;
      %c:備份片的拷貝數(從1開始編號);
      %U:是%u_%p_%c的簡寫形式,利用它可以為每一個備份片段(即磁碟檔案)生成一個唯一名稱,
       這是最常用的命名方式;
      %s:備份集的號;
      %t:備份集時間戳;
      %T:年月日格式(YYYYMMDD);s
           注:如果在BACKUP命令中沒有指定FORMAT選項,則RMAN預設使用%U為備份片段命名。
11、validate命令
      1、validate命令驗證備份集片是否能夠被還原;
      2、list backup summary;得到了備份集得主鍵ID如40,然後validate backupset 40;
12、恢復目錄的記錄刪除
         1. $Oracle_HOME/rdbms/admin/prgrmanc.sql指令碼定期刪除恢復目錄中具有DELETED狀態的記錄
         2.要刪除舊的對應物記錄incarnation.必須從DBINC表中刪除這些對應物,
        使用RC_DATABASE_INCARNATION檢視來確定要刪除的對應物。記錄要刪除的每個對應物的DBINC_KEY,
    隨後啟動SQL*Plus,執行delete from dbinc where dbinc_key=2;
13、手工同步恢復目錄:resync catalog;
14、在RMAN中儲存指令碼
    1,連線到目標資料庫和恢復目錄
    2,建立指令碼
      RMAN>create script. my_bk_script
        2>{backup database plus archivelog;}
    3,列印指令碼
      RMAN>print script. my_bk_script;
    4,執行這個指令碼,備份目標資料庫
      RMAN>run {execute scipt my_bk_script;}
    5刪除指令碼
      RMAN>delete script. my_bk_script;
15、archivelog模式下的完全恢復
  step1:set oracle_sid=testdb
      rman target rman_user/password
      configure controlfile autobackup on;
  step2:backup database plus archivelog delete input;
  step3:shutdown immediate;
  step4:重新命名所有的資料檔案和控制檔案,不重新命名聯機重做日誌。
      step5: startup nomount;
     set DBID=****
     restore controlfile from autobackup;
     alter database mount;
  step6: restore database;
     recover database;
     alter database open resetlogs;
16、表空間恢復
  sql"alter tablespace users offline";
  sql"alter tablespace tools offline";
  restore tablespace users,tools;
  recover tablespace users,tools;
  sql"alter tablespace users online";
  sql"alter tablespace tools online";
17、資料檔案恢復
sql"alter database datafile 3 offline";
  sql"alter database datafile 'd:oracleoradatausers01.dbf' offline";
  restore datafile 3
  restore datafile 'd:oracleoradatausers01.dbf';
  recover datafile 3
  recover datafile 'd:oracleoradatausers01.dbf';
  sql"alter database datafile 3 online";
  sql"alter database datafile 'd:oracleoradatausers01.dbf'online";
18、RMAN高階恢復
  1基於時間點的恢復
  run
  {
   set until time "to_date('07/01/02 15:00:00','mm/dd/yy hh24:mi:ss')"
   restore database;
   recover database;
   alter database open resetlogs;
 }
  2基於SCN的恢復
   startup mount;
   restore database UNTIL SCN 10000;
   recover database UNTIL SCN 10000;
  alter database open resetlogs;
  3基於日誌序列的恢復
   startup mount;
   restore database UNTIL SEQUENCE 100 thread 1;
   recover database UNTIL SEQUENCE 100 thread 1;
   alter database open resetlogs;

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

相關文章