ºìÁªLinuxÃÅ»§
Linux°ïÖú

Oracle RMAN¿ìËÙÈëÃÅÖ¸ÄÏ

·¢²¼Ê±¼ä:2006-07-25 09:15:37À´Ô´:ºìÁª×÷Õß:ÒëÔª
Ç°ÑÔ

ÕâƪÎÄÕÂÖ÷Òª½éÉÜRMANµÄ³£Ó÷½·¨£¬ÆäÖаüº¬ÁË×÷ÕßһЩ×Ô¼ºµÄ¾­Ñ飬ÀïÃæµÄʵÑéÒ²»ù±¾È«ÔÚWIN 2KºÍORACLE 8.1.6»·¾³Ï²âÊԳɹ¦£¨ÒòΪÕâ¸ö»·¾³±È½ÏÈÝÒ×ʵÏÖ£©¡£

±¾ÎĽè¼øÁËÍøÉÏһЩ¸ßÊÖµÄÏà¹ØÎÄÕ£¬Ï£Íû´óÏÀÃDz»Òª¼û¹Ö£¬´Ë´¦Ò»²¢Ð»¹ý¡£

ÕâƪÎÄÕÂÖ÷ÒªÊÇÔÚ±±¾©³ö²îÆÚ¼äдµÄ£¬»Øµ½¼ÒºóÕûÀíÐÞ¸ÄÁËһϣ¬Ê±¼ä±È½Ï²Ö´Ù£¬Í¬Ê±ÒòΪƪ·ùÓÐÏÞ£¬Ò»Ð©¼¼Êõϸ½Ú²»ÄÜÒ»Ò»¸²¸ÇÁË£¬Ö»Ï£ÍûÄܹ»°ïÖúÐÂÊÖÈëÃŵÄ×÷Óã¬ÏëÕæÕýÊìÁ·ÕÆÎÕRMAN£¬±ØÐë¾­¹ý½Ï³¤Ê±¼äµÄʵ¼ùÄ¥Á·²Å¿ÉÒÔ£¬ÓÈÆäÐèÒªÔÚ¹¤³ÌÖлñµÃ±¦¹óµÄ¹ÊÕϽâ¾ö¾­Ñé¡£

1.ʲôÊÇRMAN

RMAN¿ÉÒÔÓÃÀ´±¸·ÝºÍ»¹Ô­Êý¾Ý¿âÎļþ¡¢¹éµµÈÕÖ¾ºÍ¿ØÖÆÎļþ¡£ËüÒ²¿ÉÒÔÓÃÀ´Ö´ÐÐÍêÈ«»ò²»ÍêÈ«µÄÊý¾Ý¿â»Ö¸´¡£

×¢Ò⣺RMAN²»ÄÜÓÃÓÚ±¸·Ý³õʼ»¯²ÎÊýÎļþºÍ¿ÚÁîÎļþ¡£

RMANÆô¶¯Êý¾Ý¿âÉϵÄOracle·þÎñÆ÷½ø³ÌÀ´½øÐб¸·Ý»ò»¹Ô­¡£±¸·Ý¡¢»¹Ô­¡¢»Ö¸´ÊÇÓÉÕâЩ½ø³ÌÇý¶¯µÄ¡£

RMAN¿ÉÒÔÓÉOEMµÄBackup Manager GUIÀ´¿ØÖÆ£¬µ«ÔÚ±¾ÎÄÕÂÀï²»×÷ÖصãÌÖÂÛ¡£

2. Terminologyרҵ´Ê»ã½âÊÍ

2.1. Backup sets±¸·Ý¼¯ºÏ
±¸·Ý¼¯ºÏÓÐÏÂÃæµÄÌØÐÔ£º
¡¡¡¡°üÀ¨Ò»¸ö»ò¶à¸öÊý¾ÝÎļþ»ò¹éµµÈÕÖ¾
¡¡¡¡ÒÔoracleרÓеĸñʽ±£´æ
¡¡¡¡ÓÐÒ»¸öÍêÈ«µÄËùÓеı¸·ÝƬ¼¯ºÏ¹¹³É
¡¡¡¡¹¹³ÉÒ»¸öÍêÈ«±¸·Ý»òÔöÁ¿±¸·Ý

2.2. Backup pieces±¸·ÝƬ
Ò»¸ö±¸·Ý¼¯ÓÉÈô¸É¸ö±¸·ÝƬ×é³É¡£Ã¿¸ö±¸·ÝƬÊÇÒ»¸öµ¥¶ÀµÄÊä³öÎļþ¡£Ò»¸ö±¸·ÝƬµÄ´óСÊÇÓÐÏÞÖƵģ»Èç¹ûûÓдóСµÄÏÞÖÆ£¬ ±¸·Ý¼¯¾ÍÖ»ÓÉÒ»¸ö±¸·ÝƬ¹¹³É¡£±¸·ÝƬµÄ´óС²»ÄÜ´óÓÚʹÓõÄÎļþϵͳËùÖ§³ÖµÄÎļþ³¤¶ÈµÄ×î´óÖµ¡£

2.3. Image copies¾µÏñ±¸·Ý
¾µÏñ±¸·ÝÊǶÀÁ¢Îļþ£¨Êý¾ÝÎļþ¡¢¹éµµÈÕÖ¾¡¢¿ØÖÆÎļþ£©µÄ±¸·Ý¡£ËüºÜÀàËƲÙ×÷ϵͳ¼¶µÄÎļþ±¸·Ý¡£Ëü²»ÊDZ¸·Ý¼¯»ò±¸·ÝƬ£¬Ò²Ã»Óб»Ñ¹Ëõ¡£

2.4. Full backup setsÈ«±¸·Ý¼¯ºÏ
È«±¸·ÝÊÇÒ»¸ö»ò¶à¸öÊý¾ÝÎļþÖÐʹÓùýµÄÊý¾Ý¿éµÄµÄ±¸·Ý¡£Ã»ÓÐʹÓùýµÄÊý¾Ý¿éÊDz»±»±¸·ÝµÄ£¬Ò²¾ÍÊÇ˵£¬oracle ½øÐб¸·Ý¼¯ºÏµÄѹËõ¡£

2.5. Incremental backup setsÔöÁ¿±¸·Ý¼¯ºÏ
ÔöÁ¿±¸·ÝÊÇÖ¸±¸·ÝÒ»¸ö»ò¶à¸öÊý¾ÝÎļþµÄ×Ô´ÓÉÏÒ»´Îͬһ¼¶±ðµÄ»ò¸üµÍ¼¶±ðµÄ±¸·ÝÒÔÀ´±»Ð޸ĹýµÄÊý¾Ý¿é¡£ ÓëÍêÈ«±¸·ÝÏàͬ£¬ÔöÁ¿±¸·ÝÒ²½øÐÐѹËõ¡£

2.6. File multiplexing
²»Í¬µÄ¶à¸öÊý¾ÝÎļþµÄÊý¾Ý¿é¿ÉÒÔ»ìºÏ±¸·ÝÔÚÒ»¸ö±¸·Ý¼¯ÖС£

2.7. Recovery catalog resyncing »Ö¸´Ä¿Â¼Í¬²½
ʹÓûָ´¹ÜÀíÆ÷Ö´ÐÐbackup¡¢copy¡¢restore»òÕßswitchÃüÁîʱ£¬»Ö¸´Ä¿Â¼×Ô¶¯½øÐиüУ¬µ«ÊÇÓйØÈÕÖ¾Óë¹éµµÈÕÖ¾ÐÅϢûÓÐ×Ô¶¯¼ÇÈë»Ö¸´Ä¿Â¼¡£ÐèÒª½øÐÐĿ¼ͬ²½¡£Ê¹ÓÃresync catalogÃüÁî½øÐÐͬ²½¡£

RMAN>resync catalog;

RMAN-03022£ºÕýÔÚ±àÒëÃüÁresync
RMAN-03023£ºÕýÔÚÖ´ÐÐÃüÁresync
RMAN-08002£ºÕýÔÚÆô¶¯È«²¿»Ö¸´Ä¿Â¼µÄ resync
RMAN-08004£ºÍê³ÉÈ«²¿ resync

3. »Ö¸´Ä¿Â¼

3.1.»Ö¸´Ä¿Â¼µÄ¸ÅÄî
»Ö¸´Ä¿Â¼ÊÇÓÉRMANʹÓá¢Î¬»¤µÄÓÃÀ´·ÅÖñ¸·ÝÐÅÏ¢µÄ²Ö¿â¡£RMANÀûÓûָ´Ä¿Â¼¼ÇÔصÄÐÅϢȥÅжÏÈçºÎÖ´ÐÐÐèÒªµÄ±¸·Ý»Ö¸´²Ù×÷¡£

»Ö¸´Ä¿Â¼¿ÉÒÔ´æÔÚÓÚORACLEÊý¾Ý¿âµÄ¼Æ»®ÖС£

ËäÈ»»Ö¸´Ä¿Â¼¿ÉÒÔÓÃÀ´±¸·Ý¶à¸öÊý¾Ý¿â£¬½¨ÒéΪ»Ö¸´Ä¿Â¼Êý¾Ý¿â´´½¨Ò»¸öµ¥¶ÀµÄÊý¾Ý¿â¡£

»Ö¸´Ä¿Â¼Êý¾Ý¿â²»ÄÜʹÓûָ´Ä¿Â¼±¸·Ý×ÔÉí¡£

3.2.½¨Á¢»Ö¸´Ä¿Â¼
µÚÒ»²½£¬ÔÚĿ¼Êý¾Ý¿âÖд´½¨»Ö¸´Ä¿Â¼ËùÓñí¿Õ¼ä£º

SQL> create tablespace rman_ts datafile "d:\oracle\oradata\rman\rman_ts.dbf" size 20M;

±í¿Õ¼äÒÑ´´½¨¡£
µÚ¶þ²½£¬ÔÚĿ¼Êý¾Ý¿âÖд´½¨RMAN Óû§²¢ÊÚȨ£º

SQL> create user rman identified by rman default tablespace rman_ts temporary
tablespace temp quota unlimited on rman_ts;

Óû§ÒÑ´´½¨¡£

SQL> grant recovery_catalog_owner to rman;

ÊÚȨ³É¹¦¡£

SQL> grant connect, resource to rman;

ÊÚȨ³É¹¦¡£

µÚÈý²½£¬ÔÚĿ¼Êý¾Ý¿âÖд´½¨»Ö¸´Ä¿Â¼

C:\>rman catalog rman/rman

»Ö¸´¹ÜÀíÆ÷£º°æ±¾8.1.6.0.0 - Production

RMAN-06008£ºÁ¬½Óµ½»Ö¸´Ä¿Â¼Êý¾Ý¿â
RMAN-06428£ºÎ´°²×°»Ö¸´Ä¿Â¼

RMAN>create catalog tablespace rman_ts;

RMAN-06431£º»Ö¸´Ä¿Â¼ÒÑ´´½¨
×¢Ò⣺ËäȻʹÓÃRMAN²»Ò»¶¨±ØÐè»Ö¸´Ä¿Â¼£¬µ«ÊÇÍƼöʹÓá£ÒòΪ»Ö¸´Ä¿Â¼¼ÇÔصÄÐÅÏ¢´ó²¿·Ö¿ÉÒÔͨ¹ý¿ØÖÆÎļþÀ´¼ÇÔØ£¬RMANÔÚ»Ö¸´Êý¾Ý¿âʱʹÓÃÕâЩÐÅÏ¢¡£²»Ê¹Óûָ´Ä¿Â¼½«»á¶Ô±¸·Ý»Ö¸´²Ù×÷ÓÐÏÞÖÆ¡£

3.3.ʹÓûָ´Ä¿Â¼µÄÓÅÊÆ
¿ÉÒÔ´æ´¢½Å±¾£»

¼ÇÔؽϳ¤Ê±¼äµÄ±¸·Ý»Ö¸´²Ù×÷£»

4. Æô¶¯RMAN

RMANΪ½»»¥Ê½ÃüÁîÐд¦Àí½çÃ棬Ҳ¿ÉÒÔ´ÓÆóÒµ¹ÜÀíÆ÷ÖÐÔËÐС£

ΪÁËʹÓÃÏÂÃæµÄʵÀý£¬Ïȼì²é»·¾³·ûºÏ£º

¡¡¡¡the target database is called "his" and has the same TNS alias
¡¡¡¡user rman has been granted "recovery_catalog_owner "privileges
¡¡¡¡Ä¿±êÊý¾Ý¿âµÄÁ¬½ÓÓû§ÎªinternalÕʺţ¬»òÕßÒÔÆäËûSYSDBAÀàÐÍÕʺÅÁ¬½Ó¡¡¡¡
¡¡¡¡the recovery catalog database is called "rman" and has the same TNS alias
¡¡¡¡the schema containing the recovery catalog is "rman" (same password)

ÔÚʹÓÃRMANÇ°£¬ÉèÖÃNLS_DATE_FORMAT ºÍNLS_LANG»·¾³±äÁ¿£¬ºÜ¶àRMAN LISTÃüÁîµÄÊä³ö½á¹ûÊÇÓëÈÕÆÚʱ¼äÏà¹ØµÄ£¬ÕâµãÔÚÓû§Ï£ÍûÖ´ÐÐÒÔʱ¼äΪ»ù×¼µÄ»Ö¸´¹¤×÷Ò²ºÜÖØÒª¡£

ÏÂÀýÊÇ»·¾³±äÁ¿µÄʾ·¶£º

NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
NLS_DATE_FORMAT=DD-MON-YYYY HH24:MI:SS

ΪÁ˱£Ö¤RMANʹÓÃʱÄÜÁ¬½Ó»Ö¸´Ä¿Â¼£¬»Ö¸´Ä¿Â¼Êý¾Ý¿â±ØÐë´ò¿ª£¬Ä¿±êÊý¾Ý¿âÖÁÉÙÒªSTARTED£¨unmount£©£¬·ñÔòRMAN»á·µ»ØÒ»¸ö´íÎó£¬Ä¿±êÊý¾Ý¿â±ØÐëÖÃÓڹ鵵ģʽÏ¡£

4.1.ʹÓò»´ø»Ö¸´Ä¿Â¼µÄRMAN
ÉèÖÃÄ¿±êÊý¾Ý¿âµÄ ORACLE_SID £¬Ö´ÐУº

% rman nocatalog
RMAN> connect target
RMAN> connect target internal/@his
4.2.ʹÓôø»Ö¸´Ä¿Â¼µÄRMAN
% rman rman_ts rman/rman@rman
RMAN> connect target

% rman rman_ts rman/rman@rman target internal/@his
4.3.ʹÓÃRMAN
Ò»µ©Á¬½Óµ½Ä¿±êÊý¾Ý¿â£¬¿ÉÒÔͨ¹ý½»»¥½çÃæ»òÕßÊÂÏÈ´æ´¢µÄ½Å±¾Ö´ÐÐÖ¸¶¨RMANÃüÁÏÂÃæÊÇÒ»¸öʹÓÃRMAN½»»¥½çÃæµÄʵÀý£º

RMAN> resync catalog;
RMAN-03022£ºÕýÔÚ±àÒëÃüÁresync
RMAN-03023£ºÕýÔÚÖ´ÐÐÃüÁresync
RMAN-08002£ºÕýÔÚÆô¶¯È«²¿»Ö¸´Ä¿Â¼µÄ resync
RMAN-08004£ºÍê³ÉÈ«²¿ resync
ʹÓýű¾µÄʵÀý£º

RMAN> execute script alloc_1_disk;
´´½¨»òÕßÌæ´ú´æ´¢µÄ½Å±¾£º

RMAN> replace script alloc_1_disk {
2> allocate channel d1 type disk;
3> }

5.×¢²á»òÕß×¢ÏúÄ¿±êÊý¾Ý¿â

5.1.×¢²áÄ¿±êÊý¾Ý¿â

Êý¾Ý¿â״̬£º

»Ö¸´Ä¿Â¼×´Ì¬£º´ò¿ª

Ä¿±êÊý¾Ý¿â£º¼ÓÔØ»òÕß´ò¿ª

Ä¿±êÊý¾Ý¿âÔÚµÚÒ»´ÎʹÓÃRMAN֮ǰ±ØÐëÔÚ»Ö¸´Ä¿Â¼ÖÐ×¢²á£º

µÚÒ»²½£¬Æô¶¯»Ö¸´¹ÜÀíÆ÷£¬²¢ÇÒÁ¬½ÓÄ¿±êÊý¾Ý¿â£º

C:\>rman target internal/oracle@his catalog rman/rman@rman
»Ö¸´¹ÜÀíÆ÷£º°æ±¾8.1.6.0.0 - Production
RMAN-06005£ºÁ¬½Óµ½Ä¿±êÊý¾Ý¿â£ºHIS (DBID=3021445076)
RMAN-06008£ºÁ¬½Óµ½»Ö¸´Ä¿Â¼Êý¾Ý¿â
µÚ¶þ²½£¬×¢²áÊý¾Ý¿â£º

RMAN> register database;
RMAN-03022£ºÕýÔÚ±àÒëÃüÁregister
RMAN-03023£ºÕýÔÚÖ´ÐÐÃüÁregister
RMAN-08006£º×¢²áÔÚ»Ö¸´Ä¿Â¼ÖеÄÊý¾Ý¿â
RMAN-03023£ºÕýÔÚÖ´ÐÐÃüÁfull resync
RMAN-08002£ºÕýÔÚÆô¶¯È«²¿»Ö¸´Ä¿Â¼µÄresync
RMAN-08004£ºÍê³ÉÈ«²¿resync

5.2.×¢ÏúÄ¿±êÊý¾Ý¿â

RMANÌṩÁËÒ»¸ö×¢Ïú¹¤¾ß£¬½ÐDBMS_RCVCAT¹¤¾ß°ü£¬Çë×¢ÒâÒ»µ©×¢ÏúÁ˸ÃÄ¿±êÊý¾Ý¿â£¬¾Í²»¿ÉÒÔʹÓûָ´Ä¿Â¼Öк¬Óеı¸·Ý¼¯À´»Ö¸´Êý¾Ý¿âÁË¡£

ΪÁËÄÜ×¢ÏúÊý¾Ý¿â£¬ÐèÒª»ñµÃÊý¾Ý¿âµÄ±êʶÂ루DB_ID£©ºÍÊý¾Ý¿â¼üÖµ£¨DB_KEY£©¡£ÆäÖÐÁ¬½ÓÄ¿±êÊý¾Ý¿âʱ½«»á»ñµÃDB_ID¡£

C:\>rman target internal/oracle@his catalog rman/rman@rman
»Ö¸´¹ÜÀíÆ÷£º°æ±¾8.1.6.0.0 - Production
RMAN-06005£ºÁ¬½Óµ½Ä¿±êÊý¾Ý¿â£ºHIS (DBID=3021445076)
RMAN-06008£ºÁ¬½Óµ½»Ö¸´Ä¿Â¼Êý¾Ý¿â
ÆäÖÐDBID=3021445076£¬ÀûÓÃDBID=3021445076²éѯÊý¾Ý¿â¼üÖµÂ룬Á¬½Óµ½Ä¿±êÊý¾Ý¿â£¬²éѯdb±í£º

SQL> select * from db;

DB_KEY DB_ID CURR_DBINC_KEY
---------- ---------- --------------
1 3021445076 2
»ñµÃDB_KEY£½1£¬ÕâÑù£¬¸ÃÄ¿±êÊý¾Ý¿âDB_KEY£½1£¬DBID=3021445076£¬ÀûÓÃÁ½¸öֵʹÓÃDBMS_RCVCAT¹¤¾ß°ü¾Í¿ÉÒÔ×¢ÏúÊý¾Ý¿â£º

SQL> execute dbms_rcvcat.unregisterdatabase(1,3021445076);
PL/SQL ¹ý³ÌÒѳɹ¦Íê³É¡£
ÖÁ´Ë£¬×¢ÏúÊý¾Ý¿â²Ù×÷Íê³É¡£

6.²Ù×÷ÒÑÓеı¸·Ý

6.1.¼ÓÈëĿ¼Êý¾Ý¿â
Êý¾Ý¿â״̬£º

»Ö¸´Ä¿Â¼£º´ò¿ª

Ä¿±êÊý¾Ý¿â£º¼ÓÔØ»òÕß´ò¿ª

Èç¹û´æÔÚ8.x°æ±¾ÒÔÇ°´´½¨µÄ±¸·ÝÊý¾ÝÏë×¢²áµ½Ä¿±êÊý¾Ý¿â£¬¿ÉÒÔ²ÉÓÃÈçÏÂÊÖ¹¤·½Ê½¼ÓÈëµ½»Ö¸´Ä¿Â¼ÖÐ

RMAN> catalog datafilecopy "/oracle/ .... /system01.dbf";
ʹÓÃÈçÏÂÃüÁîÏÔʾ»Ö¸´Ä¿Â¼Öаüº¬µÄÎļþ

RMAN> list copy of database;
6.2.´ÓĿ¼Êý¾Ý¿âÖÐɾ³ý

µÚÒ»²½£º²é¿´±¸·ÝÐÅÏ¢£º

RMAN>list backup;
RMAN-03022£ºÕýÔÚ±àÒëÃüÁlist
±¸·Ý¼¯Áбí

¹Ø¼ü×Ö Recid ±ê¼Ç LV ¼¯ºÏ±ê¼Ç ¼¯ºÏ¼ÆÊý Íê³Éʱ¼ä
------- ---------- ---------- -- ---------- ---------- ----------------------
1104 2 501364455 0 501364446 2 06-8ÔÂ -03
±¸·Ý¶ÎÁбí

¹Ø¼ü×Ö Pc# Cp# ״̬ Íê³Éʱ¼ä ¶ÎÃû
------- --- --- ----------- ---------------------- ------------------------
1106 1 1 AVAILABLE 06-8ÔÂ -03 D:\ORACLE\ORA81\DATABASE\02EU4DMU_1_1
Êý¾ÝÎļþ°üÀ¨Áбí

Îļþ Ãû³Æ LV ÀàÐÍ ¼ì²éµãSCN ¼ì²éµãʱ¼ä
---- ------------------------------------- -- ---- ---------- -------------
3 D:\ORACLE\ORADATA\HIS\USERS01.DBF 0 Full 160052 06-8ÔÂ -03
±¸·Ý¼¯µÄ¹Ø¼ü×ÖΪ1104¡£

µÚ¶þ²½£º¶¨ÒådeleteͨµÀ£º

RMAN>allocate channel for delete type disk;
RMAN-03022£ºÕýÔÚ±àÒëÃüÁallocate
RMAN-03023£ºÕýÔÚÖ´ÐÐÃüÁallocate
RMAN-08030£º·ÖÅäµÄͨµÀ£ºdelete
RMAN-08500£ºÍ¨µÀ delete£ºsid=19 devtype=DISK
µÚÈý²½£ºÉ¾³ýbackupset±¸·Ý¼¯

RMAN>change backupset 1104 delete;
RMAN-03022£ºÕýÔÚ±àÒëÃüÁchange
RMAN-08073£ºÒÑɾ³ý±¸·Ý¶Î
RMAN-08517£º±¸·Ý¶Î handle=D:\ORACLE\ORA81\DATABASE\02EU4DMU_1_1 recid=2 stamp=50 1364447
RMAN-03023£ºÕýÔÚÖ´ÐÐÃüÁpartial resync
RMAN-08003£ºÆô¶¯²¿·Ö»Ö¸´Ä¿Â¼µÄ resync
RMAN-08005£ºÍê³É²¿·Ö resync
×¢Ò⣺²¿·ÖÖ´ÐÐɾ³ý±¸·Ý¼¯¡¢±¸·ÝƬ»òÕßά»¤»Ö¸´Ä¿Â¼µÄÃüÁÐèÒªÏÈÖ¸¶¨Í¨µÀ£¬È磺

RMAN>allocate channel for delete type disk;

RMAN>allocate channel for maintenance type disk;

7.Ôڷǹ鵵ģʽϱ¸·Ý

Êý¾Ý¿â״̬£º

»Ö¸´Ä¿Â¼£º´ò¿ª

Ä¿±êÊý¾Ý¿â£ºÀý³ÌÆô¶¯»òÕßÊý¾Ý¿â¼ÓÔØ

»Ö¸´Ä¿Â¼Êý¾Ý¿âÐèÒª´ò¿ª£¬Ä¿±êÊý¾Ý¿â±ØÐëÆô¶¯£¨»òÕß¼ÓÔØ£©¡£ÒòΪĿ±êÊý¾Ý¿â²»Ôڹ鵵ģʽÏ£¬ËùÒÔµ±½øÐб¸·Ý»Ö¸´²Ù×÷µÄʱºòÊý¾Ý¿âÎÞ·¨´ò¿ª¡£²»¿ÉÒÔ½«±í¿Õ¼äÖÃÓÚÈȱ¸·ÝģʽÉϽøÐеÈͬÓÚÎļþϵͳ¼¶µÄ¿½±´£¬Èç¹ûÔڷǹ鵵ģʽ£¬Êý¾Ý¿â´ò¿ªµÄ״̬ϲ»ÄܽøÐÐÊý¾ÝÎļþµÄ±¸·Ý¡£

7.1.Êý¾Ý¿âÍêÈ«±¸·Ý
RMAN> run {
2> # backup the complete database to disk
3> allocate channel dev1 type disk;
4> backup
5> full
6> tag full_db_backup
7> format "/oracle/backups/db_t%t_s%s_p%p"
8> (database);
9> release channel dev1;
10> }
ÐÐ#
2: ±íÃ÷¸ÃÐÐΪעÊÍÐУ¨££ÊÇ×¢ÊÍ·û£©
3&9: See section 15 - ChannelsͨµÀ¶¨Òå
5: Full backup (default if full or incremental not specified)ÍêÈ«±¸·Ýģʽ£¨È±Ê¡Ä£Ê½£©
6: Meaningful string (<=30 chars)£¨±¸·Ý¼¯±êʶ£¬<£½30¸ö×Ö·û£©
7: Filename to use for backup pieces, including substitution variables. ±¸·ÝƬʹÓõÄÎļþÃû£¬¿ÉÒÔ°üº¬´úÌæ±äÁ¿¡£
8: Indicates all files including controlfiles are to be backed up±íÃ÷±¸·ÝËùÓÐÊý¾ÝÎļþ°üÀ¨¿ØÖÆÎļþ

ͨ¹ýÏÂÃæµÄÃüÁîÏÔʾ»Ö¸´Ä¿Â¼ÖмÇÔصı¸·Ý¼¯ÐÅÏ¢£º

RMAN> list backupset of database;
7.2.±¸·Ý±í¿Õ¼ä
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> tag tbs_users_read_only
5> format "/oracle/backups/tbs_users_t%t_s%s"
6> (tablespace users)
7> }
ʹÓÃÏÂÁÐÃüÁîÀ´ÏÔʾ»Ö¸´Ä¿Â¼ÖиñíµÄ±¸·ÝÐÅÏ¢£º

RMAN> list backupset of tablespace users;
¼ÙÉèUSERS±í¿Õ¼äÔÚ±¸·Ýºó±»ÖÃΪREAD ONLY±í¿Õ¼ä£¬ÒÔºóµÄÈ«¿â±¸·Ý¾Í¿ÉÒÔ²»Óñ¸·Ý¸Ã±í¿Õ¼ä£¬ÎªÁË´ïµ½Õâ¸öÄ¿µÄ£¬¿ÉÒÔÔÚÒÔºóµÄ±¸·ÝÖÐÖ¸¶¨"skip readonly"¡£

×¢Ò⣬Ŀ±êÊý¾Ý¿â²»ÐèÒªÒ»¶¨´ò¿ª£¬Ö»Òª¼ÓÔؾͿÉÒÔ£¬ÒòΪ±í¿Õ¼äµÄÐÅÏ¢´æ´¢ÔÚ¿ØÖÆÎļþÖС£

7.3.±¸·Ýµ¥¶ÀÊý¾ÝÎļþ
RMAN> run {
2> allocate channel dev1 type "SBT_TAPE";
3> backup
4> format "%d_%u"
5> (datafile "/oracle/dbs/sysbigdb.dbf");
6> release channel dev1;
7> }
ÐÐ#
2: ʹÓÃMML£¨media manager layer£©·ÖÅä´Å´øÇý¶¯Æ÷£¬±ØÐëÖ¸¶¨ÀàÐÍΪSBT_TAPE£»

×¢ÒâÒòΪûÓÐÖ¸¶¨±êʶ£¬ËùÒÔ±êʶΪ¿Õ£»

ʹÓÃÏÂÃæµÄÃüÁîÏÔʾ»Ö¸´Ä¿Â¼Öб¸·ÝµÄ±í¿Õ¼ä£º

RMAN> list backupset of datafile 1;

7.4.±¸·ÝÊý¾ÝÎļþ
RMAN> run {
2> allocate channel dev1 type "SBT_TAPE";
3> copy datafile "/oracle/dbs/temp.dbf" to "/oracle/backups/temp.dbf";
4> release channel dev1;
5> }
ʹÓÃÏÂÃæµÄÃüÁîÏÔʾ»Ö¸´Ä¿Â¼ÖеÄÎļþ¿½±´£º

RMAN> list copy of datafile "/oracle/dbs/temp.dbf";
¿½±´Êý¾ÝÎļþºÍ±¸·ÝÊý¾ÝÎļþÊDz»Ò»ÑùµÄ£¬Êý¾ÝÎļþ¿½±´ÊÇÒ»¸ö¸ÃÎļþµÄ¾µÏñ¡£ÎļþµÄ±¸·Ý²úÉúÒ»¸ö±¸·Ý¼¯¡£

7.5.±¸·Ý¿ØÖÆÎļþ
RMAN> run {
2> allocate channel dev1 type "SBT_TAPE";
3> backup
4> format "cf_t%t_s%s_p%p"
5> tag cf_monday_night
6> (current controlfile);
7> release channel dev1;
8> }
×¢Ò⣺Êý¾Ý¿âÍêÈ«±¸·Ý½«×Ô¶¯±¸·Ý¿ØÖÆÎļþ¡£

8.¹éµµÄ£Ê½Ïµı¸·Ý

Êý¾Ý¿â״̬£º

»Ö¸´Ä¿Â¼£º´ò¿ª

Ä¿±êÊý¾Ý¿â£ºÀý³ÌÆô¶¯£¬Êý¾Ý¿â¼ÓÔØ»òÕß´ò¿ª

±¸·Ý²Ù×÷ʹÓõÄÃüÁîÓë·Ç¹éµµÄ£Ê½Ï»ù±¾Ò»Ñù¡£

8.1. Backing up archived logs ±¸·Ý¹éµµÈÕÖ¾
ÏÂÃæµÄ½Å±¾±¸·Ý¹éµµÈÕÖ¾£º

RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format "/oracle/backups/log_t%t_s%s_p%p"
5> (archivelog all)
6> release channel dev1;
7> }
ÏÂÃæµÄ½Å±¾¹éµµÈÕÖ¾´Ó# 90 to 100£º

RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format "/oracle/backups/log_t%t_s%s_p%p"
5> (archivelog from logseq=90 until logseq=100 thread 1);
6> release channel dev1;
7> }
ÏÂÃæµÄ½Å±¾±¸·ÝÔÚ24СʱÄÚ²úÉúµÄ¹éµµÈÕÖ¾£¬ÔÚ±¸·ÝÍê³Éºó»á×Ô¶¯É¾³ý¹éµµÈÕÖ¾¡£Èç¹û±¸·Ýʧ°Ü£¬¹éµµÈÕÖ¾²»»á±»É¾³ý¡£

RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format "/oracle/backups/log_t%t_s%s_p%p"
5> (archivelog from time "sysdate-1" all delete input);
6> release channel dev1;
7> }
ʹÓÃÏÂÃæµÄÃüÁîÏÔʾ»Ö¸´Ä¿Â¼ÖеĹ鵵ÈÕÖ¾£º

RMAN> list backupset of archivelog all;
×¢Ò⣺RMANÕÒµ½¹éµµÈÕÖ¾ºó»á±¸·ÝÖ¸¶¨ÈÕÖ¾£¬Èç¹ûÎÞ·¨ÕÒµ½ÈÕÖ¾£¬ËüÒ²²»»á·µ»Ø´íÎóÐÅÏ¢¡£

8.2. Backing up the online logs ±¸·ÝÁª»úÈÕÖ¾
Áª»úÈÕÖ¾²»ÄÜÓÃRMANÀ´±¸·Ý£¬±ØÐëÏȽ«Æä¹éµµ¡£

ΪÁËʵÏÖÕâµã£¬±ØÐëÔÚRMANÖÐÖ´ÐÐÈçÏÂSQLÓï¾ä£º

RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter system archive log current";
4> backup
5> format "/oracle/backups/log_t%t_s%s_p%p"
6> (archivelog from time "sysdate-1" all delete input);
7> release channel dev1;
8> }
ÉÏÃæµÄ½Å±¾¿ÉÒÔÔÚÖ´ÐÐÍêÒ»¸öÍêÕûµÄÁª»úÊý¾Ý¿â±¸·ÝºóÖ´ÐУ¬È·±£ËùÓеÄÖØ×öÈÕÖ¾¿ÉÒÔ½«Êý¾Ý¿â»Ö¸´µ½Ò»¸öÒ»ÖÂÐÔµÄ״̬¡£

×¢Ò⣺²»¿ÉÒÔ±êʶ¹éµµÈÕÖ¾±¸·Ý¼¯¡£

9. ÔöÁ¿±¸·Ý

N¼¶±ðÔöÁ¿±¸·Ý±¸·Ý´Ó×î½üµÄN¼¶±ð»òÕ߸üС¼¶±ðÒÔÀ´µÄËùÓиü¸Ä¹ýµÄÊý¾Ý¿éÄÚÈÝ¡£ÔöÁ¿±¸·Ý·ÖΪÁ½ÖÖ£¬Ò»ÖÖÊÇÀÛ»ýÔöÁ¿±¸·Ý£¬Ò»ÖÖÊÇ·ÇÀÛ»ýÔöÁ¿±¸·Ý¡£

ÀÛ»ýÔöÁ¿±¸·Ý°üÀ¨×Ô×îºóÒ»´ÎÔÚ¸üµÍ¼¶±ð½øÐб¸·ÝÒÔÀ´ËùÓиĶ¯¹ýµÄÊý¾Ý¿é¡£

·ÇÀÛ»ýÔöÁ¿±¸·Ý°üÀ¨×ÔÇ°Ò»´ÎÔÚͬ¼¶»òÕ߸üµÍ¼¶±ð½øÐб¸·ÝÒÔÀ´¸Ä¶¯¹ýµÄÊý¾Ý¿é¡£

9.1. Level 0--ÔöÁ¿±¸·Ý²ßÂԵĻù´¡
Level 0 ÊÇÔöÁ¿±¸·Ý²ßÂԵĻù´¡--the basis of the incremental backup strategy

RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> incremental level 0
5> filesperset 4
6> format "/oracle/backups/sunday_level0_%t"
7> (database);
8> release channel dev1;
9> }
Line#
4: 0¼¶±¸·Ý
5: ¶¨Òåÿ¸öbackupset µÄ×î´óÎļþÊý

ʹÓÃLISTÓï¾ä²é¿´£¬Êý¾Ý¿â±¸·Ý¼¯µÄÁбíÏÔʾÖУ¬ "type" ½«ÏÔʾ "Incremental"£¬"LV"Áн«ÏÔʾ"0" ¡£

9.2. ʹÓÃÔöÁ¿±¸·ÝµÄ°¸Àý
Ò»¸öµäÐ͵ÄÔöÁ¿±¸·Ý°¸ÀýÈçÏ£º
¡¡¡¡ ÐÇÆÚÌìÍíÉÏ - level 0 backup performed
¡¡¡¡ ÐÇÆÚÒ»ÍíÉÏ - level 2 backup performed
¡¡¡¡ ÐÇÆÚ¶þÍíÉÏ - level 2 backup performed
¡¡¡¡ ÐÇÆÚÈýÍíÉÏ - level 1 backup performed
¡¡¡¡ ÐÇÆÚËÄÍíÉÏ - level 2 backup performed
¡¡¡¡ ÐÇÆÚÎåÍíÉÏ - level 2 backup performed
¡¡¡¡ ÐÇÆÚÁùÍíÉÏ - level 2 backup performed
¡¡¡¡ ÐÇÆÚÌìÍíÉÏ - level 0 backup performed

10. »Ö¸´

»Ö¸´°¸ÀýÈçÏ£º

10.1. Database open£¬datafile deleted Êý¾Ý¿â´ò¿ªÊ±£¬Îļþ±»É¾³ý
Êý¾ÝÎļþÔÚÊý¾Ý¿â´ò¿ªÊ±±»É¾³ý¡£ÓÐÁ½ÖÖ·½·¨¿ÉÒÔ¶Ô´ò¿ªµÄÊý¾Ý¿â½øÐлָ´£º»¹Ô­Êý¾ÝÎļþ»òÕß±í¿Õ¼ä¡£ÏÂÃæÁ½¸öʵÀýÏÔʾÁ˸÷½·¨£º

(a) Datafile recovery Êý¾ÝÎļþ»Ö¸´

RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter tablespace users offline immediate";
4> restore datafile 4;
5> recover datafile 4;
6> sql "alter tablespace users online";
7> release channel dev1;
8> }
(b) Tablespace recovery ±í¿Õ¼ä»Ö¸´

RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter tablespace users offline immediate";
4> restore tablespace users;
5> recover tablespace users;
6> sql "alter tablespace users online";
7> release channel dev1;
8> }
×¢Ò⣺Èç¹û»¹Ô­ÏµÍ³±í¿Õ¼äÎļþ£¬Êý¾Ý¿â±ØÐë¹Ø±Õ£¬ÒòΪϵͳ±í¿Õ¼ä²»¿ÉÒÔÍÑ»ú¡£

10.2. Complete restore (lost online redo) and rollforward - database closed ÍêÈ«»¹Ô­£¨¶ªÊ§Áª»úÈÕÖ¾£©²¢ÇÒÇ°¹ö - Êý¾Ý¿â¹Ø±Õ
RMAN> run {
2> allocate channel dev1 type disk;
3> set until logseq=105 thread=1;
4> restore controlfile to "/oracle/dbs/ctrltargdb.ctl";
5> replicate controlfile from "/oracle/dbs/ctrltargdb.ctl";
6> restore database;
7> sql "alter database mount";
8> recover database;
9> sql "alter database open resetlogs";
10> release channel dev1;
11> }
Notes:
"set until" ÃüÁîÖ¸Ã÷»Ö¸´µ½Ö¸¶¨µÄÈÕÖ¾Îļþ¡£ÕâÒ»µãÔÚÊý¾ÝÎļþ»Ö¸´Ê±ºÜÖØÒª£¬·ñÔòRMAN½«ÊÔͼ»Ö¸´×î½üµÄÊý¾ÝÎļþ£¬¸ÃÊý¾ÝÎļþ¿ÉÄÜÔÚÖ¸¶¨µÄÈÕÖ¾ÒÔÇ°¡£
"replicate controlfile" ¸´ÖÆ»¹Ô­µÄ¿ØÖÆÎļþµ½INIT.ORAÖ¸¶¨µÄ¿ØÖÆÎļþ¡£

Èç¹ûÊý¾Ý¿âʹÓÃWITH RESETLOGS´ò¿ª£¬ÔòÐèҪʹÓÃRESET DATABASEÃüÁî×¢²á¸Ä±äºóµÄÊý¾Ý¿â¡£ÔÚʹÓÃRESETLOGSÃüÁî´ò¿ªÊý¾Ý¿âºóÇ¿ÁÒ½¨Òé×öÒ»¸öÍêÈ«µÄÊý¾Ý¿â±¸·Ý¡£

10.3. »¹Ô­Êý¾ÝÎļþµÄ×Ó¼¯£¬ÍêÈ«»Ö¸´
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter database mount";
4> restore datafile 2;
5> restore datafile 3;
6> restore archivelog all;
7> recover database;
8> sql "alter database open";
9> release channel dev1;
10> }

11. ½Å±¾

´´½¨»òÕßÈ¡´ú½Å±¾£º

RMAN> create script alloc_disk {
2> # Allocates one disk
3> allocate channel dev1 type disk;
4> setlimit channel dev1 kbytes 2097150 maxopenfiles 32 readrate 200;
5> }

RMAN> replace script rel_disk {
2> # releases disk
3> release channel dev1;
5> }

RMAN> replace script backup_db_full {
2> # Performs a complete backup
3> execute script alloc_disk;
4> backup
5> .....
6> execute script rel_disk;
7> }
Ç°Á½¸ö½Å±¾·Ö±ðÓÃÀ´·ÖÅäºÍ»ØÊÕͨµÀ¡£

alloc_disk ½Å±¾»¹¶îÍâÖ¸¶¨Á˱¸·ÝƬµÄ×î´óÕ××Ö½ÚÊý£¬±¸·Ýʱ¿ÉÒÔͬʱ´ò¿ªµÄÊäÈëÎļþµÄ×î´óÊýÄ¿£¬ÒÔ¼°Ã¿ÃëÖÓ¶Áÿ¸öÊäÈëÎļþµÄÊý¾Ý»º³åÇøµÄ×î´óÊýÄ¿¡£

µÚÈý¸ö½Å±¾µ÷ÓÃÏÈÇ°´æ´¢µÄÁ½¸ö½Å±¾½øÐÐÊý¾Ý¿â±¸·Ý¡£

ÔËÐд洢½Å±¾µÄʾ·¶£º

RMAN> run {
2> execute script backup_db_full;
3> }
×¢Ò⣺´æ´¢µÄ½Å±¾±ØÐëÔÚ{ .... execute