Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Collaborate 2012 - RMAN Eliminate the mystery


Published on

Presentación dada en Collaborate 2012 -

Published in: Technology, News & Politics
  • Be the first to comment

Collaborate 2012 - RMAN Eliminate the mystery

  1. 1. 1/53
  2. 2. High Availability Boot Camp:RMAN - Eliminate the MysteryEng. Nelson Calero, OCPUYOUG 2/53
  3. 3. High Availability Boot Camp: RMAN - Eliminate the MysteryAbout me: Working with Oracle tools and Linux environments since 1996 DBA Oracle (since 2001) & MySQL (since 2005) Oracle University Instructor since 2011 Co-founder and President of the Oracle user Group of Uruguay (UYOUG) since 2009 Computer Engineer. OCP DBA 10g 3/53
  4. 4. Uruguay 4/53
  5. 5. AGENDA• Introduction• RMAN Concepts• Backups• Recovery• Integrity validation• Monitoring• Maintenance• When errors• Optimization• Examples – time permitted 5/53
  6. 6. What is RMAN? Utility with many features to use in backup and recovery tasks. Included for free with Oracle database installation ($ORACLE_HOME/bin) Command line interface.  some functionality available inside Enterprise Manager Written in Pro * C, executes PL / SQL Since Oracle 8 – 1997 Documented bugs in all versions: less than 1283, more than 170. Known RMAN Performance Problems (MOS note 247611.1)  32 bugs, all fixed by 11g (some even before) 6/53
  7. 7. Best practices of backup & recovery Today? Some. Those using RMAN More technology is needed apart from RMAN in a DR/HA policy: • Datapump • Flashback • Secure backup • …. RMAN is one solution among 20 from Oracle for unplanned downtime, used for site and storage failures, and data corruption 7/53
  8. 8. Backups without Rman (user managed)Consistent (cold): cp path/* dest-bkpInconsistent (hot): alter tablespace nnn begin backup; cp path/datafile.dbf destbkp alter tablespace nnn end backup; cp /archivelogs-path/* dest-bkp 8/53
  9. 9. RMAN backupsConsistent (cold):          rman target /          startup mount;          backup database plus archivelog;Inconsistent (hot):          rman target /          backup database plus archivelog; 9/53
  10. 10. RMAN Backup - files• Which files were generated by a backup? – list backup;• Which files are copied? – datafiles – controlfiles – archived logs – spfile• Which files are not copied? – temporary files (tempfiles) and online redo logs (not needed for recovery) – files from external tabes or bfiles – database binary files – database network configuration files 10/53
  11. 11. RMAN backupsDifferences between RMAN and user-managed backups: – RMAN sets the rules, but is flexible – RMAN commands implement sophisticated tasks, which lead to less code to be written to perform the same tasks, when possible. – RMAN has many functionalities – RMAN requires training to use effectively 11/53
  12. 12. RMAN Concepts– Device– Channel– Backupset and Copies • Backup pieces • Status: expired/available– Retention policy • Obsolete– Incarnation 12/53
  14. 14. RMAN ConfigurationPer target (in controlfile or Catalog):  Device  Parallelism  Retention Policy  Backup optimization  EncryptionIf using Fast Recovery Area, database parameters:  DB_RECOVERY_FILE_DEST_SIZE ( DB_RECOVERY_FILE_DEST is set)If not using a recovery Catalog, set according to your policy  CONTROL_FILE_RECORD_KEEP_TIMENOTE: Since destination can be ASM Cluster File System (ACFS) 14/53
  15. 15. Back to RMAN BackupsSee what has been backed up:  oracle@oraculo:~> rman  Recovery Manager: Release - Production on Fri Feb 17 11:00:13 2012  Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.  RMAN> connect target  connected to target database: ENT11G (DBID=410442782)  RMAN> list backup summary;  List of Backups  ===============  Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag  ------- -- -- - ----------- --------------- ------- ------- ---------- ---  1       B  F  A DISK        13-FEB-12       1       1       NO         TAG20120213T122058  2       B  F  A DISK        13-FEB-12       1       1       NO         TAG20120213T122238  3       B  F  A DISK        13-FEB-12       1       1       NO         TAG20120213T122421  4       B  F  A DISK        13-FEB-12       1       1       NO         TAG20120213T122440 15/53
  16. 16. RMAN BackupsDetails:  RMAN> list backup tag TAG20120213T122058;                 using target database control file instead of recovery catalog  List of Backup Sets  ===================  BS Key  Type LV Size       Device Type Elapsed Time Completion Time  ------- ---- -- ---------- ----------- ------------ ---------------  1       Full    1.03M      DISK        00:00:01     13-FEB-12         BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20120213T122058   Piece Name: /u01/app/oracle/fast_recovery_area/ENT11G/backupset/2012_02_13/o1_mf_nnndf_TAG20120213T122058_7ml72cnz_.bkp    List of Datafiles in backup set 1    File LV Type Ckp SCN    Ckp Time  Name    ---- -- ---- ---------- --------- ----    5       Full 1044143    13-FEB-12 /u02/oradata/ent11g/prueba.dbf 16/53
  17. 17. RMAN BackupsTIP - change date format inside RMAN  [oracle@oraculo ~]$ export NLS_DATE_FORMAT=DD/MON/YYYY HH24:MI:SS  [oracle@oraculo ~]$ rman target /  Recovery Manager: Release - Production on Wed Dec 21 20:31:46 2011  Copyright (c) 1982, 2005, Oracle.  All rights reserved.  connected to target database: Ent11g (DBID=943234298)  RMAN> list backup summary tag bkp_prod_121511060003;  using target database control file instead of recovery catalog  List of Backups  ===============  Key     TY LV S Device Type Completion Time      #Pieces #Copies Compressed Tag  ------- -- -- - ----------- -------------------- ------- ------- ---------- ---  1       B  F  A DISK        13/FEB/2012 03:21:03 1       1       NO         TAG20120213T122058  2       B  F  A DISK        13/FEB/2012 03:25:42 1       1       NO         TAG20120213T122238  3       B  F  A DISK        13/FEB/2012 03:29:28 1       1       NO         TAG20120213T122421 17/53
  18. 18. RMAN backupsUsing Oracle XE: $ORACLE_HOME/config/scripts/ • • 18/53
  19. 19. RMAN backups - Incremental  Differential: copy only the changes since the last incremental backup  Cumulative: copy all changes from the last full backup.Incremental backups are differential by defaultTo restore a database one of this is needed:  all differential backups since the last full backup, or  last cumulative backup following the last full backup 19/53
  20. 20. RMAN incremental backupsExamples First incremental backup must be complete, and is identified with the level 0. backup incremental level 0 tablespace users;  Next is level 1. If no level 0 backup exists,it creates a level 0 backup: backup incremental level 1 tablespace users; Cumulative backup: backup incremental level 1 cumulative tablespace users; 20/53
  21. 21. RMAN incremental backups(more) Incremental updated Backups (or merged) apply an incremental backup to the last full backup to get a new full backup  run {    backup incremental level 1 for recover of copy with tag BKP_L0 database;    recover copy of database with tag BKP_L0;  } requires more disk space to have more than redundancy 1, add UNTIL TIME – MOS note 745798.1 21/53
  22. 22. RMAN space usageBuilt in functionality, no need to enable  NULL BLOCK COMPRESSION (8i) - does not copy empty blocks never used (ie: unformatted above High Water Mark (HWM))  UNUSED BLOCK COMPRESSION (10.2) - does not copy unused blocks (ie: empty under HWM)  UNDO OPTIMIZATION (11.1) – does not copy undo segments not neededMust be explicitly enabled – BINARY COMPRESSION (10g) Compress data before sending it to the destination. Supports incremental backups. Algorithm can be changed using the Advanced compression option (11.2) 22/53
  23. 23. NULL COMPRESSION in actionoracle@oraculo:~> du -hs oradata/XE    1.5G    .oradata/XEoracle@oraculo:~> ls -lrt $ORACLE_BASE/flash_recovery_area/XE/backupset/2010_06_03/total 1176688-rw-r----- 1 oracle dba 1203748864 2010-06-03 00:57 o1_mf_nnndf_TAG.._60g9xpkz_.bkpFree space on the database: 01:41:16 XE> select sum(bytes)/1024/1024 mb from dba_free_space;       MB     ----------       135.8125 23/53
  24. 24. RMAN COMPRESSIONTwo ways to enable:backup as compressed backupset ...CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET;Files generated:-rw-r----- 1 oracle dba 1203986432 2010-06-03 01:31 o1_mf_nnndf_TAG.._60gcywnl_.bkp-rw-r----- 1 oracle dba  235642880 2010-06-03 01:38 o1_mf_nnndf_TAG.._60gdd066_.bkpAlmost 1GB saved and more CPU used 24/53
  25. 25. RMAN COMPRESSION – XECan we configure compression as the default backup method?    rman target /    CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET;     exit;   ./ -rw-r----- 1 oracle dba 1203748864 o1_mf_nnndf_TAG.._60g9xpkz_.bkp    rman target /    CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET;     exit   ./ -rw-r----- 1 oracle dba 120398643 o1_mf_nnndf_TAG.._60gcywnl_.bkp 25/53
  26. 26. RMAN COMPRESSION – code:           echo "Backup in progress..."           rman target / >> $rman_backup << EOF              set echo on;              shutdown immediate;              startup mount;              configure retention policy to redundancy 2;              configure controlfile autobackup format for device type disk clear;              configure controlfile autobackup on;              sql "create pfile=$rman_spfile2init from spfile";              backup as backupset device type disk database;              configure controlfile autobackup off;              alter database open;              delete noprompt obsolete; 26/53
  27. 27. RMAN COMPRESSION – needs to be modified to enable compression:           echo "Backup in progress..."           rman target / >> $rman_backup << EOF              set echo on;              shutdown immediate;              startup mount;              configure retention policy to redundancy 2;              configure controlfile autobackup format for device type disk clear;              configure controlfile autobackup on;              sql "create pfile=$rman_spfile2init from spfile";              backup as compressed backupset device type disk database;              configure controlfile autobackup off;              alter database open;              delete noprompt obsolete; 27/53
  28. 28. RMAN COMPRESSION – XEReally necessary? – maximum amount of user data is 11G in XE 11.2 (was 4Gb in 10.2) – uses redundancy 2 28/53
  29. 29. Corruption detectionBackup validates block checksum when writing (physical) by defaultTo detect logical corruption while taking the backup: – backup blocks all check logical database;To validate already taken backups, and their availability for the restore operation – restore validate database; – restore validate controlfile to c:tempcontrol01.ctl; – restore validate archivelog from sequence N1 until sequence N2; 29/53
  30. 30. Validation – integrity and corruptionVALIDATE command (11.1) – independent of backup/recovery validate database; VALIDATE BACKUPSET 5; validate datafile 3; validate datafile 3 BLOCK 5 TO 20;If some detected, see which ones: select * from V$DATABASE_BLOCK_CORRUPTION;NOTE: This view is also populated by other Oracle process (11.2) 30/53
  31. 31. Corruption preventionTo prevent and detect corruption, these initialization parameters must be used: – DB_BLOCK_CHECKING – in memory checks. Overhead up to 10%. OFF / LOW / MEDIUM / FULL – DB_BLOCK_CHECKSUM – calculated and stored checksum of data and logs. Overhead up to 5%. OFF / TYPICAL / FULL – DB_LOST_WRITE_PROTECT – detect lost writes on standby. NONE / TYPICAL / FULL – DB_ULTRA_SAFE: set the proper combination of the previous three. • NONE: no changes are made • DATA_ONLY: MEDIUM / FULL / TYPICAL • DATA_AND_INDEX: FULL / FULL / TYPICAL 31/53
  32. 32. Recovery scenariosbasic – 2: – complete and tablespaceadvanced – 12: – Recovering After the Loss of Datafiles: Scenarios – Recovering Through an Added Datafile with a Backup Control File: Scenario – Re-Creating Datafiles When Backups Are Unavailable: Scenario – Recovering Through RESETLOGS with Created Control File: Scenario – Recovering NOLOGGING Tables and Indexes: Scenario – Recovering Read-Only Tablespaces with a Backup Control File: Scenario – Recovering Transportable Tablespaces: Scenario – Recovering After the Loss of Online Redo Log Files: Scenarios – Recovering After the Loss of Archived Redo Log Files: Scenario – Recovering from a Dropped Table: Scenario – Performing Media Recovery in a Distributed Environment: Scenario 32/53
  33. 33. Basic recovery examplesRecover the last full backup, using the existing controlfile   RMAN> STARTUP MOUNT;    RMAN> RESTORE DATABASE;   RMAN> RECOVER DATABASE;   RMAN> ALTER DATABASE OPEN;Recover only one tablespace in an open instance   RMAN> SQL ALTER TABLESPACE mytbs OFFLINE IMMEDIATE;   RMAN> RESTORE TABLESPACE mytbs;   RMAN> RECOVER TABLESPACE mytbs;   RMAN> SQL ALTER TABLESPACE mytbs ONLINE; 33/53
  34. 34. Summary of RMAN benefits– Incremental backups– automated recovery • block media recovery– compression • skipping blocks and binary– encryption– backup history and catalog– logical and physical corruption detection– backup optimization– improved and new features in new releases • 11 in version 11.2, 21 in version 11.1 (from Backup and Recovery Users Guide, “Whats New in Backup and Recovery?”) 34/53
  35. 35. using RMAN for the first time – Learn RMAN functionality and usage – Practice recovery scenariosNOTE: RMAN generated files are not portable between platforms. – Intel 32-bit (x86) backup cannot be restored on Intel 64-bit (x86_64). – CONVERT DATABASE command can be used over platforms which share endian format. 35/53
  36. 36. using RMAN for the first timeDefine the backup policy – acceptable level of service • time frame for implementation and execution • disk consumption and CPU usage to define using of compression – retention – destination – file names, size limits – parallelism – use of encryption 36/53
  37. 37. using RMAN for the first timeCreate complete scripts – Configuration can be used to recreate the database – Delete obsolete backups – List catalog (documentation) – Validate logical integrity – Detect errors in the execution of the script and notify operatorsTest recovery periodically – automated to validate health of backup media – manually to practice different recovery scenarios • one team to break, one to recover 37/53
  38. 38. Monitoring RMAN operations Running tasks: V$SESSION_LONGOPS SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK,        ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE" FROM   V$SESSION_LONGOPS WHERE  OPNAME LIKE RMAN% AND    OPNAME NOT LIKE %aggregate% AND    TOTALWORK != 0 AND    SOFAR <> TOTALWORK; History: – V$BACKUP_* – V$RMAN* If using catalog: – RC_* 38/53
  39. 39. Maintenance CrossCheck Delete obsolete If using standby  Above 11.1:    ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY  Older versions: Split backup from delete obsolete tasks 39/53
  40. 40. Features not available in Standard Edition:– allocate disk parallel channels– block change tracking– encryption -- Advanced Security option (disk) or Oracle Secure Backup license (tape) 40/53
  41. 41. When errors• Manuals:• Support:• Debug:           rman target / log rman.log trace rman.trc           run{             allocate channel t1 type sbt………trace=2;             allocate channel t2 type sbt………trace=2;             allocate channel t3 type sbt………trace=2;             debug on;             restore database;             debug off;           } 41/53
  42. 42. When errors Media manager libraries (MML) are from third parties Trace generates sbtio.log file Simulate and compare:          run {            allocate channel t1 type sbt parms            SBT_LIBRARY=oracle.disksbt,ENV=(BACK            UP_DIR=d:temp) trace=2;            backup database;          } 42/53
  43. 43. Optimizing backup operations mainly I/O activity detailed process architecture: MOS note 360443.1 use async I/O (O.S. Configuration) channels adequate to the hardware in use performance of the MML comparing the time of "backup validate" (read-only operation) with the time of backup. enable block change tracking for incremental backups (Enterprise Edition) use standby database if Active DataGuard is available. 43/53
  44. 44. Optimizing Recovery• Scripts commands are executed serially• This does not work in parallel:            run {             allocate channel t1 type sbt....;             allocate channel t2 type sbt....;             allocate channel t3 type sbt....;             restore datafile 2;             restore datafile 3;             restore datafile 5;             restore datafile 7;             restore datafile 11; } 44/53
  45. 45. Optimizing Recovery• This works:        run {           allocate channel t1 type sbt....;           allocate channel t2 type sbt....;           allocate channel t3 type sbt....;           restore datafile 2,3,5,7,11; }• For big datafiles, from 11.1, use SECTION SIZE: CONFIGURE DEVICE TYPE sbt PARALLELISM 3; CONFIGURE DEFAULT DEVICE TYPE TO sbt; RUN {   BACKUP SECTION SIZE 300M TABLESPACE prueba; } 45/53
  46. 46. Next steps?– Exercise recovery scenarios– Use Enterprise Manager whenever possible– Use Data Recovery Advisor– Incorporate the use of Dataguard and Flashback 46/53
  47. 47. Questions? 47/53
  48. 48. Some time for examples?– Instance cloning • Classic (10g) • From active instance (11.1) • RAC– Using Data Recovery Advisor – only on the white paper 48/53
  49. 49. Instance cloningClassic (10g) using pre-existing backups1) Set destination database environment: parameter file, password file and directories – db_file_name_convert y log_file_name_convert if using different directory structure2) Reboot the destination database in nomount mode3) Get the SCN to which you want to restore from source. There are several ways to do it. One is:          select next_change#          from v$archived_log          where recid = (select max(recid) from v$archived_log                         where backup_count>0); 49/53
  50. 50. Instance cloningClassic (10g) using pre-existing backups4) execute the duplication on destination server :          rman catalog rman/clave@rman target sys/clave@origen          connect auxiliary /          run {            allocate auxiliary channel dupdb1 type disk;            set until scn $MAX_SCN;            duplicate target database to COPIA NOFILENAMECHECK;          }5) disable archivelog on the cloned database 50/53
  51. 51. Instance cloningFrom active instance (11.1)Same steps 1 and 2, then 4th is:          rman nocatalog target sys/clave@origen          connect AUXILIARY sys/clave@copia          run {             DUPLICATE TARGET DATABASE TO COPIA               FROM ACTIVE DATABASE;          }          exit; 51/53
  52. 52. Instance cloningRAC databases MOS notes 452868.1 and 461479.1 changes to single instance duplication:  destination database configured as single instance (removing RAC configuration)  clone the same way as single instance  pfile parameters are adjusted, adding RAC settings removed before:  correct names for control files and the new database.  restart the database to use the new parameters  configure the new database in all the remaining RAC nodes:  pfile, pwfile, tnsnames.ora  register the new database in CRS 52/53
  53. 53. 53/53