RMAN 101 Ahbaid Gaffoor Amazon/A9.com Overview 1. 2. 3. 4. 5. RMAN Architecture RMAN Backup RMAN Recovery RMAN Catalog RMAN Stored Scripts 2 1. RMAN Architecture Non RMAN Backups RMAN RMAN Components RMAN Interface 1. RMAN Architecture 1. 2. 3. 4. 3 1. 2. 3. 4. 5. Export/Import Cold Database Hot Database Storage Layer Standby Database 1.1 RMAN Architecture – Non RMAN Backups 1.1 Non RMAN Backups 1. Server Managed Recovery 2. Point in Time Recovery 3. Database, Tablespace, Data file, Block Recovery 4. Hot Objects 5. Optimization 6. Compression 7. Parallelism 8. Stored Scripts 1.2 RMAN Architecture – RMAN 1.2 RMAN 1. Client 2. Backup media/destination (Channels) 3. Catalog (optional, recommended) 1.3 RMAN Architecture – RMAN Components 1.3 RMAN Components 1.4 RMAN Interface [oracle@red:~/rman_demo]$ echo $ORACLE_HOME /xfer/app/oracle/product/11.2.0.2 [oracle@red:~/rman_demo]$ which rman /xfer/app/oracle/product/11.2.0.2/bin/rman • Target = Database to Backup [oracle@red:~/rman_demo]$ echo $ORACLE_SID ora [oracle@red:~/rman_demo]$ rman target / nocatalog Recovery Manager: Release 11.2.0.2.0 - Production on Thu May 19 00:40:19 2011 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORA (DBID=1356087945) using target database control file instead of recovery catalog RMAN> • Control File: control_file_record_keep_time (7) • Catalog (optional) = Metadata Repository 1.4 RMAN Architecture – RMAN Interface • RMAN client “rman” 2. RMAN Backup Disk Destination Database Backup Data File Backup Control File Backup Archive Log Backup List Backups 2. RMAN Backup 1. 2. 3. 4. 5. 6. 8 2.1 Disk Destination 1. Archive Log Mode Check 2.1 RMAN Backup – Disk Destination SYS@ORA[PRI]-125[11.2.0.2.0]:SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /arch-01/databases/ora/ Oldest online log sequence 68 Next log sequence to archive 71 Current log sequence 71 2. Allocate a channel to disk: “allocate channel d1 type disk;” 3. Flash Recovery Area: db_recovery_file_dest used by default. 9 2.2 Database Backup 1. Connect & Run 2.2 RMAN Backup – Database Backup $ rman target / nocatalog cmdfile=full_backup.cmd log=full_backup.log 2. Run Command run { allocate channel d1 type disk; backup database format '/rman/ora/rman-%d-%T-%U.db'; } 3. % format – Database %d – Data %T – Unique Identifier %U (files in destination) 10 2.2 Database Backup [oracle@red:~/rman_demo/non-catalog]$ rman target / nocatalog cmdfile=full_backup.cmd log=full_backup.log 2.2 RMAN Backup – Database Backup [oracle@red:~/rman_demo/non-catalog]$ cat full_backup.log Recovery Manager: Release 11.2.0.2.0 - Production on Thu May 19 01:00:36 2011 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORA (DBID=1356087945) using target database control file instead of recovery catalog RMAN> run { 2> allocate channel d1 type disk; 3> backup database format '/rman/ora/rman-%d-%T-%U.db'; 4> } 5> allocated channel: d1 channel d1: SID=19 device type=DISK Starting backup at 19-MAY-11 channel d1: starting full datafile backup set channel d1: specifying datafile(s) in backup set input datafile file number=00002 name=/fs-a01-a/databases/ora/sysaux-01.dbf input datafile file number=00001 name=/fs-a01-a/databases/ora/system-01.dbf input datafile file number=00003 name=/fs-a01-a/databases/ora/undo_t1-01.dbf input datafile file number=00004 name=/fs-a01-a/databases/ora/users-01.dbf channel d1: starting piece 1 at 19-MAY-11 channel d1: finished piece 1 at 19-MAY-11 piece handle=/rman/ora/rman-ORA-20110519-06mcm99l_1_1.db tag=TAG20110519T010037 comment=NONE channel d1: backup set complete, elapsed time: 00:01:35 channel d1: starting full datafile backup set channel d1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel d1: starting piece 1 at 19-MAY-11 channel d1: finished piece 1 at 19-MAY-11 piece handle=/rman/ora/rman-ORA-20110519-07mcm9cl_1_1.db tag=TAG20110519T010037 comment=NONE channel d1: backup set complete, elapsed time: 00:00:01 Finished backup at 19-MAY-11 released channel: d1 Recovery Manager complete. 11 2.3 Data File Backup 1. Run Command (by file number) 2.3 RMAN Backup – Data File Backup run { allocate channel d1 type disk; backup format '/rman/ora/rman-%d-%T-%U.db’ datafile 1; } 2. Run Command (by file names) run { allocate channel d1 type disk; backup format '/rman/ora/rman-%d-%T-%U.db' datafile '/fs-a01-a/databases/ora/users-01.dbf', '/fs-a01-a/databases/ora/undo_t1-01.dbf'; } 12 2.4 Control File Backup 1. Auto backup 2.4 RMAN Backup – Control File Backup RMAN> configure controlfile autobackup on; 2> new RMAN configuration parameters: CONFIGURE CONTROLFILE AUTOBACKUP ON; new RMAN configuration parameters are successfully stored 2. Run Command (FRA) run { allocate channel d1 type disk; backup current controlfile; } 3. Run Command (Disk) run { allocate channel d1 type disk; backup current controlfile format '/rman/ora/rman-%d-%T-%U.db'; } 13 2.5 Archive Log Backup 1. Validate files are not on disk 2.5 RMAN Backup – Archive Log Backup RMAN> run { allocate channel d1 type disk format '/rman/ora/rman-%d-%T-%U.db'; change archivelog all validate; } 2. Backup all archive logs RMAN> run { allocate channel d1 type disk format '/rman/ora/rman-%d-%T-%U.db'; backup archivelog all; } 3. Backup and Delete within a range RMAN> run { allocate channel d1 type disk format '/rman/ora/rman-%d-%T-%U.db'; backup archivelog until time 'sysdate-1'; delete copy of archivelog all completed before 'sysdate-3'; } 14 2.6 List Backups RMAN> list backup; 2.6 RMAN Backup – List Backups List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------2 Full 416.02M DISK 00:01:22 19-MAY-11 BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20110519T005827 Piece Name: /rman/ora/rman-ORA-20110519.db List of Datafiles in backup set 2 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---1 Full 1370281 19-MAY-11 /fs-a01-a/databases/ora/system-01.dbf 2 Full 1370281 19-MAY-11 /fs-a01-a/databases/ora/sysaux-01.dbf 3 Full 1370281 19-MAY-11 /fs-a01-a/databases/ora/undo_t1-01.dbf 4 Full 1370281 19-MAY-11 /fs-a01-a/databases/ora/users-01.dbf …. …. BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------15 Full 9.39M DISK 00:00:01 19-MAY-11 BP Key: 15 Status: AVAILABLE Compressed: NO Tag: TAG20110519T015045 Piece Name: /fra/ORA/autobackup/2011_05_19/o1_mf_s_751513845_6x8xvoyc_.bkp SPFILE Included: Modification time: 19-MAY-11 SPFILE db_unique_name: ORA Control File Included: Ckp SCN: 1372105 Ckp time: 19-MAY-11 15 3. RMAN Recovery Database Recovery Data File Recovery Control File Recovery Tablespace Recovery 3. RMAN Recovery 1. 2. 3. 4. 16 3.1 Database Recovery 3.1 RMAN Recovery – Database REcovery • Range: control_file_record_keep_time (7) • Catalog for further • Recover a database 17 3.1 Database Recovery [oracle@red:~/rman_demo/non-catalog]$ rman target / nocatalog 3.1 RMAN Recovery – Database REcovery Recovery Manager: Release 11.2.0.2.0 - Production on Thu May 19 03:08:22 2011 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) RMAN> startup mount; Oracle instance started database mounted … RMAN> run { 2> recover database; 3> } Starting recover at 19-MAY-11 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=133 device type=DISK starting media recovery media recovery complete, elapsed time: 00:05:20 Finished recover at 19-MAY-11 18 3.2 Data File Recovery (Backup) 3.2 RMAN Recovery – Data File REcovery • Pick a Data File SYS@ORA[PRI]-138[11.2.0.2.0]:SQL> select file#, name, bytes/power(2,20) mb from v$datafile; FILE# NAME MB ---------- -------------------------------------------------- ---------1 /fs-a01-a/databases/ora/system-01.dbf 350 2 /fs-a01-a/databases/ora/sysaux-01.dbf 400 3 /fs-a01-a/databases/ora/undo_t1-01.dbf 100 4 /fs-a01-a/databases/ora/users-01.dbf 20 • Backup Data File RMAN> run { allocate channel d1 type disk; backup format '/rman/ora/rman-%d-%T-%U.db' datafile 4; } … channel d1: backup set complete, elapsed time: 00:00:01 Finished backup at 19-MAY-11 19 3.2 Data File Recovery (Delete) 3.2 RMAN Recovery – Data File REcovery • Delete File SYS@ORA[PRI]-138[11.2.0.2.0]:SQL> !rm /fs-a01-a/databases/ora/users-01.dbf SYS@ORA[PRI]-138[11.2.0.2.0]:SQL> alter system checkpoint; ERROR: ORA-03114: not connected to ORACLE alter system checkpoint * ERROR at line 1: ORA-03113: end-of-file on communication channel Process ID: 3030 Session ID: 138 Serial number: 3 RMAN> run { allocate channel d1 type disk; backup format '/rman/ora/rman-%d-%T-%U.db' datafile 4; } … channel d1: backup set complete, elapsed time: 00:00:01 Finished backup at 19-MAY-11 20 3.2 Data File Recovery (Delete) 3.2 RMAN Recovery – Data File REcovery • Delete File – Alert Log Thu May 19 03:20:42 2011 Errors in file /dumps-01/diag/diag/rdbms/ora/ora/trace/ora_ckpt_2924.trc: ORA-63999: data file suffered media failure ORA-01116: error in opening database file 4 ORA-01110: data file 4: '/fs-a01-a/databases/ora/users-01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 Errors in file /dumps-01/diag/diag/rdbms/ora/ora/trace/ora_ckpt_2924.trc: ORA-63999: data file suffered media failure ORA-01116: error in opening database file 4 ORA-01110: data file 4: '/fs-a01-a/databases/ora/users-01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 CKPT (ospid: 2924): terminating the instance due to error 63999 Thu May 19 03:20:43 2011 System state dump requested by (instance=1, osid=2924 (CKPT)), summary=[abnormal instance termination]. System State dumped to trace file /dumps-01/diag/diag/rdbms/ora/ora/trace/ora_diag_2912.trc Dumping diagnostic data in directory=[cdmp_20110519032043], requested by (instance=1, osid=2924 (CKPT)), summary=[abnormal instance termination]. Instance terminated by CKPT, pid = 2924 21 3.2 Data File Recovery (Recover) 3.2 RMAN Recovery – Data File REcovery • Startup Mount [oracle@red:~/rman_demo/non-catalog]$ rman target / nocatalog Recovery Manager: Release 11.2.0.2.0 - Production on Thu May 19 03:28:06 2011 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) RMAN> startup mount; Oracle instance started database mounted Total System Global Area 1071333376 bytes Fixed Size Variable Size Database Buffers Redo Buffers 1348968 bytes 478153368 bytes 587202560 bytes 4628480 bytes 22 3.2 Data File Recovery (Restore) 3.2 RMAN Recovery – Data File REcovery • Restore Data File RMAN> run { 2> allocate channel d1 type disk; 3> restore datafile 4; 4> } allocated channel: d1 channel d1: SID=133 device type=DISK Starting restore at 19-MAY-11 channel d1: starting datafile backup set restore channel d1: specifying datafile(s) to restore from backup set channel d1: restoring datafile 00004 to /fs-a01-a/databases/ora/users-01.dbf channel d1: reading from backup piece /rman/ora/rman-ORA-20110519-0lmcmhal_1_1.db channel d1: piece handle=/rman/ora/rman-ORA-20110519-0lmcmhal_1_1.db tag=TAG20110519T031741 channel d1: restored backup piece 1 channel d1: restore complete, elapsed time: 00:00:01 Finished restore at 19-MAY-11 released channel: d1 23 3.2 Data File Recovery (Open DB) 3.2 RMAN Recovery – Data File REcovery • Open Database RMAN> alter database open; database opened 24 3.3 Control File Recovery (Backup) 3.3 RMAN Recovery – Control File REcovery [oracle@red:~/rman_demo/non-catalog]$ rman target=/ nocatalog connected to target database: ORA (DBID=1356087945) using target database control file instead of recovery catalog RMAN> run { allocate channel d1 type disk; backup current controlfile format '/rman/ora/rman-%d-%T-%U.db'; } allocated channel: d1 channel d1: SID=15 device type=DISK Starting backup at 19-MAY-11 channel d1: starting full datafile backup set channel d1: specifying datafile(s) in backup set including current control file in backup set channel d1: starting piece 1 at 19-MAY-11 channel d1: finished piece 1 at 19-MAY-11 piece handle=/rman/ora/rman-ORA-20110519-0nmcmikr_1_1.db tag=TAG20110519T034011 comment=NONE channel d1: backup set complete, elapsed time: 00:00:01 Finished backup at 19-MAY-11 Starting Control File and SPFILE Autobackup at 19-MAY-11 piece handle=/fra/ORA/autobackup/2011_05_19/o1_mf_s_751520413_6x9494lm_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 19-MAY-11 released channel: d1 25 3.3 Control File Recovery (Delete) SYS@ORA[PRI]-15[11.2.0.2.0]:SQL> !rm /ctl-01/databases/ora/control.ctl 3.3 RMAN Recovery – Control File REcovery SYS@ORA[PRI]-15[11.2.0.2.0]:SQL> create tablespace t1 datafile '/fs-a01-a/databases/ora/t101.dbf' size 10M; Tablespace created. SYS@ORA[PRI]-15[11.2.0.2.0]:SQL> shutdown immediate; Database closed. ORA-00210: cannot open the specified control file ORA-00202: control file: '/ctl-01/databases/ora/control.ctl' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 26 3.3 Control File Recovery (Nomount) 3.3 RMAN Recovery – Control File REcovery • Startup NOMOUNT [oracle@red:~/rman_demo/non-catalog]$ rman target=/ nocatalog connected to target database (not started) RMAN> startup nomount; Oracle instance started Total System Global Area 1071333376 bytes Fixed Size 1348968 bytes Variable Size 478153368 bytes Database Buffers 587202560 bytes Redo Buffers 4628480 bytes 27 3.3 Control File Recovery (Restore) 3.3 RMAN Recovery – Control File REcovery • Restore Control File RMAN> run { 2> allocate channel d1 type disk format '/rman/ora/rman-%d-%T-%U.db'; 3> restore controlfile from autobackup; 4> } allocated channel: d1 channel d1: SID=125 device type=DISK Starting restore at 19-MAY-11 recovery area destination: /fra database name (or database unique name) used for search: ORA channel d1: AUTOBACKUP /fra/ORA/autobackup/2011_05_19/o1_mf_s_751520413_6x9494lm_.bkp found in the recovery area AUTOBACKUP search with format "%F" not attempted because DBID was not set channel d1: restoring control file from AUTOBACKUP /fra/ORA/autobackup/2011_05_19/o1_mf_s_751520413_6x9494lm_.bkp channel d1: control file restore from AUTOBACKUP complete output file name=/ctl-01/databases/ora/control.ctl output file name=/ctl-02/databases/ora/control.ctl Finished restore at 19-MAY-11 released channel: d1 28 3.3 Control File Recovery (Recover DB) 3.3 RMAN Recovery – Control File REcovery • Recover Database RMAN> run { 2> allocate channel d1 type disk format '/rman/ora/rman-%d-%T-%U.db'; 3> recover database; 4> } allocated channel: d1 channel d1: SID=125 device type=DISK Starting recover at 19-MAY-11 Starting implicit crosscheck backup at 19-MAY-11 Crosschecked 17 objects Finished implicit crosscheck backup at 19-MAY-11 Starting implicit crosscheck copy at 19-MAY-11 Finished implicit crosscheck copy at 19-MAY-11 searching for all files in the recovery area cataloging files... cataloging done (cont’d) 29 3.3 Control File Recovery (Recover DB) (Continuation) 3.3 RMAN Recovery – Control File REcovery List of Cataloged Files ======================= File Name: /fra/ORA/autobackup/2011_05_19/o1_mf_s_751520413_6x9494lm_.bkp starting media recovery archived log for thread 1 with sequence 75 is already on disk as file /redo-01a/databases/ora/redo-03-b.log archived log file name=/redo-01-a/databases/ora/redo-03-b.log thread=1 sequence=75 creating datafile file number=5 name=/fs-a01-a/databases/ora/t1-01.dbf archived log file name=/redo-01-a/databases/ora/redo-03-b.log thread=1 sequence=75 media recovery complete, elapsed time: 00:00:03 Finished recover at 19-MAY-11 released channel: d1 30 3.3 Control File Recovery (Open DB) 3.3 RMAN Recovery – Control File REcovery • Open Database RMAN> alter database open resetlogs; database opened 31 3.4 Tablespace Recovery 3.4 RMAN Recovery – Tablespace Recovery • Backup Tablespace RMAN> run { 2> allocate channel d1 type disk format '/rman/ora/rman-%d-%T-%U.db'; 3> backup tablespace t1; 4> } allocated channel: d1 channel d1: SID=18 device type=DISK Starting backup at 19-MAY-11 channel d1: starting full datafile backup set channel d1: specifying datafile(s) in backup set input datafile file number=00005 name=/fs-a01-a/databases/ora/t1-01.dbf channel d1: starting piece 1 at 19-MAY-11 channel d1: finished piece 1 at 19-MAY-11 piece handle=/rman/ora/rman-ORA-20110519-0rmcmk0o_1_1.db tag=TAG20110519T040336 comment=NONE channel d1: backup set complete, elapsed time: 00:00:01 Finished backup at 19-MAY-11 Starting Control File and SPFILE Autobackup at 19-MAY-11 piece handle=/fra/ORA/autobackup/2011_05_19/o1_mf_s_751521818_6x95nt4x_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 19-MAY-11 released channel: d1 32 3.4 Tablespace Recovery (Delete) 3.4 RMAN Recovery – Tablespace Recovery • Lose Data File(s) SYS@ORA[PRI]-143[11.2.0.2.0]:SQL> !rm /fs-a01-a/databases/ora/t1-01.dbf SYS@ORA[PRI]-143[11.2.0.2.0]:SQL> create table t1 (a number) tablespace t1; create table t1 (a number) tablespace t1 * ERROR at line 1: ORA-01116: error in opening database file 5 ORA-01110: data file 5: '/fs-a01-a/databases/ora/t1-01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 33 3.4 Tablespace Recovery (Restore) 3.4 RMAN Recovery – Tablespace Recovery • Recover RMAN> startup mount; RMAN> run {restore tablespace t1; recover tablespace t1;} Starting restore at 19-MAY-11 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 00005 to /fs-a01-a/databases/ora/t1-01.dbf channel ORA_DISK_1: reading from backup piece /rman/ora/rman-ORA-201105190rmcmk0o_1_1.db channel ORA_DISK_1: piece handle=/rman/ora/rman-ORA-20110519-0rmcmk0o_1_1.db tag=TAG20110519T040336 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 Finished restore at 19-MAY-11 Starting recover at 19-MAY-11 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 19-MAY-11 RMAN> alter database open; database opened 34 4. RMAN Catalog Overview Creation Connecting & Registering a Database Script Example 4. RMAN Catalog • • • • 35 4.1 Overview Catalog in schema of other db Version at least the same as target db Longer retention of backup data Requires maintenance 4.1 RMAN Catalog - Overview • • • • 36 4.2 Creation 4.2 RMAN Catalog - Creation • Create a schema • Grant RECOVERY_CATALOG_OWNER role to schema • Connect to schema and create catalog via. RMAN [oracle@blue:~/rman_demo/catalog]$ rman Recovery Manager: Release 11.2.0.2.0 - Production on Thu May 19 04:31:14 2011 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. RMAN> connect catalog rcat/rcat@catdb connected to recovery catalog database RMAN> create catalog; recovery catalog created 37 4.3 Connecting & Registering 4.3 RMAN Catalog – Connecting & Registering • Connect [oracle@red:~/rman_demo/catalog]$ rman target / catalog rcat/rcat@catdb Recovery Manager: Release 11.2.0.2.0 - Production on Thu May 19 04:41:21 2011 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORA (DBID=1356087945) connected to recovery catalog database • Register Database RMAN> register database; database registered in recovery catalog starting full resync of recovery catalog full resync complete 38 4.4 Script Example • Create a script 4.4 RMAN Catalog – Script Example [oracle@red:~/rman_demo/catalog]$ rman target / catalog rcat/rcat@catdb RMAN> replace script full_backup { allocate channel d1 type disk format '/rman/ora/rman-%d-%T-%U.db'; backup database; backup archivelog all; backup current controlfile; release channel d1; } replaced script full_backup • Run script [oracle@red:~/rman_demo/catalog]$ rman target / catalog rcat/rcat@catdb RMAN> run { execute script full_backup; } executing script: full_backup allocated channel: d1 channel d1: SID=143 device type=DISK Starting backup at 19-MAY-11 channel d1: starting full datafile backup set … 39 5. RMAN Stored Scripts 5. RMAN Stored Scripts 1. Catalog required 2. Connect to target and Catalog 3. Create script “replace script”: RMAN> replace script allocate_disk_channel { allocate channel d1 type disk format '/rman/ora/rman-%d-%T-%U.db'; } 4. Run script “execute script”: RMAN> run { execute script allocate_disk_channel; } 5. Delete script “delete script”: RMAN> run { delete script allocate_disk_channel; } 6. View script “print script” 40 Thank You ahbaid@{a9.com|amazon.com|att.net} http://redoblog.wordpress.com http://ocpdba.net