The Codex of Business Writing Software for Real-World Solutions 2.pptx
RMAN – The Pocket Knife of a DBA
1. RMAN – The Pocket Knife of a DBA
■ Presenter: Anton Els
Session Details:
@aelsnz
2. Introduction
■ Vice President Product Development
■ NZOUG Committee (VP)
■ Working with Oracle database since version 7
■ Interests Include:
▪ Linux, Docker, Oracle Databases, Oracle Backup and Recovery
■ Qualifications:
▪ Oracle Database 11g Certified Master
▪ Oracle 8i, 9i, 10g and 11g OCP
▪ Solaris 10 SCSA and Red Hat 5 RHCSA
▪ B.Sc. Mathematical Sciences and B.Sc. Hons Informatics
■ Presented at Collaborate, NZOUG and db tech showcase
2
Anton
Els
-‐ @aelsnz
4. Who do I work for – Dbvisit Software Limited
■ Software Development Company
■ HQ in New Zealand
▪ US subsidiary and office in Czech Republic
■ Database Replication is our playground!
■ Worldwide leader in DR solutions for Oracle Standard Edition
■ Used in 110+ countries!
■ Product Engineers with “real world” DBA Experience
■ Regular presenters at OOW, Collaborate and NZOUG
■ Passionate about Oracle Technology
4
5. Agenda
■ What is RMAN, and some history
■ The RMAN environment
■ Recovery Catalog vs. Controlfile
■ Backupset vs. Image Copy
■ Backup, Restore and Recover commands
■ Incremental Backups
■ Advanced options
■ 12c… how great are those new features!
■ Recovery Advisor
■ Reporting monitoring tips
6. What is RMAN?
■ Oracle Recovery Manager – RMAN
■ I see it as a “safety net” for DBAs
■ Helps you to be prepared for disasters
▪ Natural
▪ Human
▪ Hardware
■ Even if you have a standby database you still need backups!
▪ What-if:
— Both primary / standby is lost
— Logical corruption replicates through to your standby
7. RMAN helps you protect what is important
■ Database Files
■ Archive Logs
■ Control Files
■ Server Parameter Files
Do not forget about Oracle So9ware and Opera=ng System!
8. A bit of RMAN History
■ “Traditional backup and recovery”
▪ using BEGIN / END backup commands
alter tablespace … begin backup;
-> copy files somewhere
alter tablespace … end backup;
■ RMAN introduced in Oracle 8-8.1.7
▪ Support open / mounted database backups
▪ Incremental backup support (only modified blocks)
▪ Corrupt block detection
▪ Recovery catalog
▪ Support disk and tape backups
9. A bit of RMAN History
■ Improved in 9i
▪ Block media recovery
▪ Backup of spfile
▪ Improved controlfile auto backup
▪ FORCE option in the delete command
▪ Introduction of the DBNEWID
10. A bit of RMAN History
■ Key improvements in Oracle 10g
▪ Improved reporting
▪ Backup Compression (backup sets) (10.1)
▪ Backup Encryption (10.2)
▪ Unused Block Compression (10.2)
▪ Using incremental backup to roll a
standby database forward (10.2)
11. A bit of RMAN History
■ Key Improvements in 11g
▪ Fast Incremental Backups (block change tracking)
▪ Data Recovery Advisor
▪ Network-Aware Duplication
▪ Automatic Block Repair (11.2)
▪ Duplicate without target database connection (11.2)
12. A bit of RMAN History
■ Key Improvements in 12c
▪ SQL Commands in RMAN !!!
▪ Table Recovery (Auxiliary instance used)
▪ Improved Active Duplication (backup sets)
▪ Network-Enabled Restore (restore datafile from standby or primary)
▪ Improved multisection backup options (Incremental Backups and
Image Copies)
▪ Fast Standby database synchronization (Using Services)
▪ Multi-tenancy support
▪ Cross-Platform Backup/Restore
13. A bit of RMAN History
■ Key Improvements in 12c
▪ SQL Commands in RMAN !!!
▪ Table Recovery (Auxiliary instance used)
▪ Improved Active Duplication (backup sets)
▪ Network-Enabled Restore (restore datafile from standby or primary)
▪ Improved multisection backup options (Incremental Backups and
Image Copies)
▪ Fast Standby database synchronization (Using Services)
▪ Multi-tenancy support
▪ Cross-Platform Backup/Restore
14. Archivelog vs. No-Archivelog Mode
■ No-Archivelog Mode:
▪ Only Cold backups
— Database is shutdown when performing backup – downtime!!
▪ Other … kind of backup methods include:
— export/import
— datapump
15. Archivelog vs. No-Archivelog Mode
■ Archivelog Mode
▪ Online Redo logs are archived
following a log switch
▪ Required for Online Backups
— No Downtime
▪ Note: Does require extra disk space!
▪ Make sure you have sufficient redo log groups
SQL> connect / as sysdba
SQL> archive log list;
SQL> select log_mode from v$database;
SQL> show parameter recovery
SQL> shutdown immediate;
SQL> startup mount
SQL> alter database archivelog;
SQL> shutdown immediate;
SQL> startup
SQL> archive log list
SQL> select log_mode from v$database;
17. The RMAN Environment
■ The “rman” command: rman nocatalog target /
Argument Value Description
-----------------------------------------------------------------------------
target quoted-string connect-string for target database
catalog quoted-string connect-string for recovery catalog
auxiliary quoted-string connect-string for auxiliary database
nocatalog none if specified, then no recovery catalog
cmdfile quoted-string name of input command file
log quoted-string name of output message log file
trace quoted-string name of output debugging message log file
append none if specified, log is opened in append mode
debug optional-args activate debugging
msgno none show RMAN-nnnn prefix for all messages
send quoted-string send a command to the media manager
pipe string building block for pipe names
script string name of catalog script to execute
using list of args arguments for rman variables
timeout integer number of seconds to wait for pipe input
checksyntax none check the command file for syntax errors
-----------------------------------------------------------------------------
Both single and double quotes (' or ") are accepted for a quoted-string.
Quotes are not required unless the string contains embedded white-space.
TIP
–
on
Unix
use
“oraenv”
oracle@dbvlin103[/home/oracle]: .
oraenv
ORACLE_SID = [oracle] ? proddb
The Oracle base remains unchanged with value /u01/app/oracle
oracle@dbvlin103[/home/oracle]: env
|
grep
ORA
ORACLE_SID=proddb
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1
18. The RMAN Environment
■ What is “kind of” wrong with example below?
RMAN> backup datafile 1;
Starting backup at 03-OCT-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=261 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA/PRODDB/DATAFILE/system.260.858601171
channel ORA_DISK_1: starting piece 1 at 03-OCT-14
channel ORA_DISK_1: finished piece 1 at 03-OCT-14
…
…
Finished backup at 03-OCT-14
19. Why make things difficult?
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21 Full 683.20M DISK 00:00:06 03-OCT-14
BP Key: 21 Status: AVAILABLE Compressed: NO Tag: TAG20141003T174234
Piece Name: /u02/backups/rman/proddb/15pk56ka_1_1
List of Datafiles in backup set 21
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 2785085 03-OCT-14 +DATA/PRODDB/DATAFILE/system.260.858601171
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
25 Full 683.20M DISK 00:00:14 03-OCT-14
BP Key: 25 Status: AVAILABLE Compressed: NO Tag: TAG20141003T174952
Piece Name: /u02/backups/rman/proddb/19pk5721_1_1
List of Datafiles in backup set 25
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 2785924 03-OCT-14 +DATA/PRODDB/DATAFILE/system.260.858601171
20. Make it easier! – set NLS_DATE_FORMAT
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
21 Full 683.20M DISK 00:00:06 03/10/2014:17:42:40
BP Key: 21 Status: AVAILABLE Compressed: NO Tag: TAG20141003T174234
Piece Name: /u02/backups/rman/proddb/15pk56ka_1_1
List of Datafiles in backup set 21
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 2785085 03/10/2014:17:42:34 +DATA/PRODDB/DATAFILE/system.260.858601171
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
25 Full 683.20M DISK 00:00:14 03/10/2014:17:50:07
BP Key: 25 Status: AVAILABLE Compressed: NO Tag: TAG20141003T174952
Piece Name: /u02/backups/rman/proddb/19pk5721_1_1
List of Datafiles in backup set 25
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 2785924 03/10/2014:17:49:53 +DATA/PRODDB/DATAFILE/system.260.858601171
NLS_DATE_FORMAT="dd/mm/yyyy:hh24:mi:ss"
21. The Default Configuration
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name PRODDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/backups/rman/proddb/cfc_%F';
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u02/backups/rman/proddb/%U';
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 RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/12.1.0/db_1/dbs/snapcf_proddb.f'; # default
22. The Default Configuration
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name PRODDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/backups/rman/proddb/cfc_%F';
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u02/backups/rman/proddb/%U';
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 RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/12.1.0/db_1/dbs/snapcf_proddb.f'; # default
23. Recovery Catalog vs. Controlfile
■ Which one is the correct one to use….
■ Advantages or reasons to consider a Recovery Catalog:
▪ More backup history can be stored
▪ Multiple databases
▪ When using Standby Databases
▪ When looking at using centralized stored scripts
▪ Monitoring
▪ Reporting
■ Using the Controlfile, keep in mind:
▪ CONTROLFILE_RECORD_KEEP_TIME
24.
25. Backup Sets and Image Copies
■ Backup Set
▪ Default option
▪ Logical container
▪ Can contain one or more files
▪ Proprietary RMAN format
▪ Can be compressed
▪ Physical files on disk – called backup pieces
■ Image Copies
▪ Powerful… but not as widely used
▪ Bit-by-Bit copy of the original file (They are Exactly the same!)
▪ Can be updated with incremental backups
▪ Can easily be switched to, reducing recovery time!!
26. Example using Backup Set
RMAN> run
{
backup
as compressed backupset
filesperset 10
database
format '/u02/backups/rman/proddb/db-%U';
backup as compressed backupset filesperset 30 archivelog all
format '/u02/backups/rman/proddb/arc-%U';
backup current controlfile format '/u02/backups/rman/proddb/ctl-%d-%I';
}
Starting backup at 04/10/2014:21:46:45
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00003 name=+DATA/PRODDB/DATAFILE/sysaux.294.858601125
input datafile file number=00001 name=+DATA/PRODDB/DATAFILE/system.260.858601171
input datafile file number=00006 name=+DATA/PRODDB/DATAFILE/users.259.858601227
input datafile file number=00005 name=+DATA/PRODDB/DATAFILE/data.263.859037565
input datafile file number=00004 name=+DATA/PRODDB/DATAFILE/undotbs1.258.858601227
channel ORA_DISK_1: starting piece 1 at 04/10/2014:21:46:46
channel ORA_DISK_1: finished piece 1 at 04/10/2014:21:48:21
piece handle=/u02/backups/rman/proddb/db-1spk89a6_1_1 tag=FULLDBBKP comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35
Finished backup at 04/10/2014:21:48:21
…
…
1
2
27. Example using Backup Copy
RMAN> run
{ backup as copy database TAG 'FRA_DBCOPY'; }
Note:
This example run on 3 Node 11.2.0.4 RAC database with sufficient space in FRA to keep a copy of the database.
Starting backup at 04/10/2014:21:48:44
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 instance=DEV1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=+DATA/dev/datafile/sysaux.275.858702333
output file name=+FRA/dev/datafile/sysaux.2874.860104127 tag=FRA_DBCOPY RECID=1 STAMP=860104162
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
…
RMAN> list copy of database;
List of Datafile Copies
=======================
Key File S Completion Time Ckp SCN Ckp Time
------- ---- - ------------------- ---------- -------------------
2 1 A 04/10/2014:21:50:05 48308543 04/10/2014:21:49:30
Name: +FRA/dev/datafile/system.2757.860104173
Tag: FRA_DBCOPY
1 2 A 04/10/2014:21:49:22 48308515 04/10/2014:21:48:45
Name: +FRA/dev/datafile/sysaux.2874.860104127
Tag: FRA_DBCOPY
1
2
3
28. Restoring is easy… if you have good backups
Restore
one
datafile
RMAN> alter database datafile 5
offline;
RMAN> restore datafile 5;
RMAN> recover datafile 5;
RMAN> alter database datafile 5 online;
Restore
and
recover
database
RMAN> startup nomount;
RMAN> set dbid 598649033
RMAN> restore controlfile
from '/u02/backups/rman/proddb/ctl-PRODDB-598649033';
RMAN> alter database mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open resetlogs;
29. But what about Image Copies?
Switch
to
datafile
copy
RMAN> alter database datafile 5
offline;
RMAN> switch datafile 5 to copy;
RMAN> recover datafile 5;
RMAN> alter database datafile 5
online;
Switch
database
to
Image
Copies
RMAN> startup mount;
RMAN> list copy of database;
RMAN> switch database to copy;
RMAN> recover database;
If complete recovery:
RMAN> alter database open;
If incomplete recovery:
RMAN> alter database open resetlogs;
32. Remember control files… (continue from Demo)
■ Start database in nomount
■ Restore “copy” the controlfile into ASM:
RMAN> restore controlfile to '+DATA' from '/u02/oracle/oradata1/DEV2/control01.ctl';
■ Update spfile
ASMCMD> find +DATA/DEV2/ *
…
+DATA/DEV2/CONTROLFILE/current.281.887984443
…
SQL> alter system set control_files='+DATA/DEV2/CONTROLFILE/current.281.887984443'
scope=spfile;
■ Enable OMF and recovery area in ASM
SQL> alter system set db_create_file_dest='+DATA' scope=spfile;
SQL> alter system set db_recovery_file_dest='+FRA’ scope=spfile;
33. RMAN Channels
■ The RMAN Client does not:
▪ Perform backups, restores or recovery operations!
■ Database Server sessions perform this work
▪ Linux – Server process
▪ Windows – Thread within database service
■ Two Supported Device Types:
▪ DISK
▪ SBT (Tape Based Backups)
36. Two Advanced Options (of many)
■ Updating Image Copies using Incremental Backups
▪ Create Backup:
rman> backup as copy incremental level 0 database format
'/u02/oracle/oradata2/DEV2/%N-%f.dbf' TAG=‘inc_bkp_copy';
rman> backup incremental level 1
for recover of copy with tag 'inc_bkp_copy’ database;
▪ Apply incremental backup to image copy:
rman> recover copy of database with tag ’ inc_bkp_copy';
39. Two Advanced Options (of many)
■ Block Change Tracking (10g+ and EE only)
▪ Default location DB_CREATE_FILE_DEST (OMF File)
▪ Minimum 10M (grows in 10M chunks)
▪ Enable:
sql> alter database enable block change tracking;
sql> alter database enable block change tracking
using file ‘/u01/oradata/blck-tracking’;
▪ Disable:
sql> alter database disable block change tracking;
40. 12c… how great are those new features!
■ Four New Features that stood out for me:
▪ SQL Commands in RMAN
▪ Table Recovery
▪ Network-Enabled Restore / Recovery
▪ Rolling forward / synchronizing a Standby Database - Using Services
41. 12c – SQL Commands in RMAN
No more: rman> sql ‘alter system switch logfile’;
Now: rman> alter system switch logfile;
RMAN> create table test (id number);
Statement processed
RMAN> select * from test;
no rows selected
RMAN> begin
2> for c1 in 1..20 loop
3> insert into test values (c1);
4> end loop;
5> end;
6> /
Statement processed
RMAN> select count(1) from test;
COUNT(1)
----------
20
RMAN> rollback;
Statement processed
RMAN> drop table test purge;
Statement processed
42. 12c – Table Recovery
Pre-requisites:
■ Backups must be available
■ Target database must be:
▪ open Read / Write and in archivelog mode
Things to take into account
■ An Auxiliary Instance
■ Tablespace containing table is restored
■ Datapump used for table export/import
■ Disable table import using: NOTABLEIMPORT keyword
■ Make sure you have sufficient storage – auxiliary instance
45. 12c – Network-Enabled Restore/Recovery
■ Restore a datafile from a Primary / Standby
■ Using Services
■ Configure and Test Networking:
▪ listener.ora
▪ tnsnames.ora
■ SECTIONSIZE, encryption, compressed backupsets can be used
■ Improved restore | recover datafile Commands
rman> restore datafile n from service <service>;
rman> recover datafile n from service <service>;
46. 12c – Network-Enabled Restore/Recovery
RMAN> alter database datafile 5 offline;
Statement processed
RMAN> restore datafile 5 from service proddb_dr;
Starting restore at 07/10/2014:13:06:28
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: using network backup set from service proddb_dr
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00005 to +DATA/PRODDB/DATAFILE/data.304.860260051
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 07/10/2014:13:06:32
RMAN> recover datafile 5;
Starting recover at 07/10/2014:13:06:39
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 07/10/2014:13:06:40
RMAN> alter database datafile 5 online;
Statement processed
47. 12c – Rolling Forward / Sync a Standby Database
Quick and easy recovery from:
■ Unrecoverable archive log gaps
■ No-logging operations
When using this method
• Standby = Target
• Primary = Auxiliary
Behind the scenes:
■ Standby database “current SCN” is obtained
■ Primary database incremental backup from this SCN
■ Incremental backup copied across network and applied to standby
48. 12c – Rolling Forward / Sync a Standby Database
Example: (executed from standby server)
rman> connect target /
rman> connect auxiliary sys/<syspassword>@<your_primary_db_service>
rman> recover database from service <your_primary_db_service>
using compressed backupset;
Important last step
▪ Recreate the standby controlfile
— Required as standby controlfile SCN lower than datafile SCN
— Update datafile and tempfile names if required
49. Tip - Don’t forget about Data Recovery Advisor
■ Introduced in Oracle 11g
■ Three key commands:
rman> LIST failure
rman> ADVISE failure
rman> REPAIR failure
■ Not available when using Multi-tenancy - CDB/PDB
▪ Expected in 12.2
50. Reporting and Monitoring
■ Using RMAN:
▪ LIST command
▪ REPORT command
■ Using Database Queries:
▪ Monitor current running jobs:
— v$session
— v$session_longops
▪ Monitoring history:
— v$rman_backup_job_details
— v$rman_output
51. Reporting and Monitoring
SELECT command_id
, status
, start_time
, end_time
, time_taken_display
, input_type
, output_device_type
, input_bytes_display
, output_bytes_display
, output_bytes_per_sec_display
from v$rman_backup_job_details
where start_time > (sysdate-5)
order by start_time;
Rman> list backup;
Rman> list copy;
Rman> list copy of database;
Rman> list copy of datafile n;
Rman> report schema;
Rman> report need backup;
Rman> report obsolete;
52. RMAN is easy!
Start with the basics before making things too complex:
■ set NLS_DATE_FORMAT
■ SHOW ALL
■ CONFIGURE
■ BACKUP DATABASE
■ RESTORE | RECOVER DATABASE
■ RESTORE | RECOVER DATAFILE
Don’t forget about the VALIDATE options!!
53. Recommended Reading
• Oracle Online Documentation
• Oracle Database 12c Backup and Recovery Survival Guide
• RMAN Recipes for Oracle Database 11g, A Problem-Solution Approach
• Dbvisit Blog – http://blog.dbvisit.com
54. ■ Change Control is there for a reason!
■
■ Document your Backup and Recovery procedures!!!
But most important!
55. Questions?
Presented By: Anton Els
Company: Dbvisit Software Limited
Email: anton.els@dbvisit.com
Twitter: @aelsnz
Blog: http://blog.dbvisit.com/author/anton-els/