View
222
Download
3
Category
Preview:
Citation preview
RMAN From Beginner to Advanced
Marcin Przepiorowski November 2016
2 © 2016 Delphix Corporation
About me
Oracle consultant/DBA since 2000 co-developer of OraSASH – free ASH/AWR like repository Blogger
3 © 2016 Delphix Corporation
Application Files
Any Storage
Databases Dev QA Stage
Collect Control Consume
Mar. 15, 3:30:15 PM!
Non-disruptively sync with source data. Compress an initial copy and store only
change data.
Mask copies. Manage all changes to the source and its copies via a single
point of control.
Create ten copies in the space of one. Deliver data in minutes with powerful self-
service features. Mask
10:1 10:1 10:1
Compress Provision
Retain Branch Bookmark
Refresh Rewind Integrate
Delphix Data as a Service Platform
© 2016 Delphix Corporation 4
Agenda Concepts 1 RMAN commands 2 Examples 3
5 © 2016 Delphix Corporation
Concept
Online backup issues:
- database inconsistency
- block inconsistency (fractured block)
RMAN is database block aware and problem with fractured block doesn’t exist
6 © 2016 Delphix Corporation
Concept
Recovery Manager is a part of Oracle kernel
It’s has a PL/SQL API with some limited documentation
The Recovery Manager has a client which can connect locally or remotely
RMAN client is translating scripts into set of steps to execute
7 © 2016 Delphix Corporation
Concept
Channel – a connection between server process and target
Types of channels (targets):
disk – data are written to a existing file system
sbt_tape – data are written to a 3rd party library using an defined API
8 © 2016 Delphix Corporation
FRA
Channel
SBT_TAPE LIBRARY API
Channel
RMAN client
Server process
ASM or
File System
IPC
9 © 2016 Delphix Corporation
Concepts
Backup using backup set
- RMAN specific format
- compression (binary compression)
- deduplication (block compression)
Backup using image copy
- data files
- switch to data file
- incremental recovery
10 © 2016 Delphix Corporation
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
Concepts
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
Backup set
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
Image Copy
1 2 3 5 7
8 9 10 11 13
15
11 © 2016 Delphix Corporation
Concepts
§ RMAN backups are physical backups - database - tablespace - datafile
§ You can not recover a logical object (like table) directly from backup
§ You can perform a partial recovery of database to auxiliary location and then extract missing table or data
12 © 2016 Delphix Corporation
Scripts
Script called from command line rman target / <<EOF command1 command2 EOF
rman target / <<EOF run { command1; command2; } EOF
13 © 2016 Delphix Corporation
Scripts
Script called from cmdfile - rman target / cmdfile=script.bck script.bck command1 command2
script.bck run { command1; command2; }
Backups
15 © 2016 Delphix Corporation
Connection
Local rman target / Recovery Manager: Release 12.1.0.2.0 - Production on Sat Oct 29 06:05:02 2016 Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved. connected to target database: SINGPDB (DBID=362928159) Remote or PDB rman target sys/xxxxxx@pdb Recovery Manager: Release 12.1.0.2.0 - Production on Sat Oct 29 06:05:13 2016 Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved. connected to target database: SINGPDB (DBID=362928159)
16 © 2016 Delphix Corporation
First backup
RMAN> backup database;
17 © 2016 Delphix Corporation
First Backup (connected to non-PDB)
RMAN> backup database; Starting backup at 24-SEP-16 using channel ORA_DISK_1 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=/u01/oradata/rmantest/system01.dbf … channel ORA_DISK_1: starting piece 1 at 24-SEP-16 channel ORA_DISK_1: finished piece 1 at 24-SEP-16 piece handle=/u01/app/oracle/fast_recovery_area/RMANTEST/backupset/2016_09_24/o1_mf_nnndf_TAG20160924T181151_cyfdyr20_.bkp tag=TAG20160924T181151 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
18 © 2016 Delphix Corporation
First Backup (connected to root CDB)
RMAN> backup database; channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/oradata/singpdb/system01.dbf input datafile file number=00003 name=/u01/oradata/singpdb/sysaux01.dbf input datafile file number=00004 name=/u01/oradata/singpdb/undotbs01.dbf input datafile file number=00006 name=/u01/oradata/singpdb/users01.dbf channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00009 name=/u01/oradata/singpdb/pdb/sysaux01.dbf input datafile file number=00008 name=/u01/oradata/singpdb/pdb/system01.dbf input datafile file number=00010 name=/u01/oradata/singpdb/pdb/pdb_users01.dbf Finished backup at 29-OCT-16
19 © 2016 Delphix Corporation
First backup (connected to PDB)
RMAN> backup database; channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00009 name=/u01/oradata/singpdb/pdb/sysaux01.dbf input datafile file number=00008 name=/u01/oradata/singpdb/pdb/system01.dbf input datafile file number=00010 name=/u01/oradata/singpdb/pdb/pdb_users01.dbf channel ORA_DISK_1: starting piece 1 at 29-OCT-16 channel ORA_DISK_1: finished piece 1 at 29-OCT-16 piece handle=/u01/app/oracle/fast_recovery_area/SINGPDB/ 3D671467D1821AA9E05381B410AC2C40 /backupset/2016_10_29/o1_mf_nnndf_TAG20161029T061924_d18xxdc2_.bkp tag=TAG20161029T061924 Finished backup at 29-OCT-16
GUID
20 © 2016 Delphix Corporation
First backup of PDB from CDB
RMAN> backup pluggable database pdb;
21 © 2016 Delphix Corporation
First backup of PDB from CDB
RMAN> backup pluggable database pdb; channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00009 name=/u01/oradata/singpdb/pdb/sysaux01.dbf input datafile file number=00008 name=/u01/oradata/singpdb/pdb/system01.dbf input datafile file number=00010 name=/u01/oradata/singpdb/pdb/pdb_users01.dbf channel ORA_DISK_1: starting piece 1 at 29-OCT-16 channel ORA_DISK_1: finished piece 1 at 29-OCT-16 piece handle=/u01/app/oracle/fast_recovery_area/SINGPDB/ 3D671467D1821AA9E05381B410AC2C40 /backupset/2016_10_29/o1_mf_nnndf_TAG20161029T062412_d18y6f1r_.bkp tag=TAG20161029T062412 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 Finished backup at 29-OCT-16
GUID
22 © 2016 Delphix Corporation
First backup of archive logs
RMAN> backup archivelog all;
23 © 2016 Delphix Corporation
First backup of archive logs
RMAN> backup archivelog all; current log archived channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=18 RECID=12 STAMP=926491255 input archived log thread=1 sequence=19 RECID=13 STAMP=926491277 input archived log thread=1 sequence=20 RECID=14 STAMP=926491280 channel ORA_DISK_1: starting piece 1 at 29-OCT-16 channel ORA_DISK_1: finished piece 1 at 29-OCT-16 piece handle=/u01/app/oracle/fast_recovery_area/SINGPDB/backupset/2016_10_29/o1_mf_annnn_TAG20161029T064133_d18z6xfo_.bkp tag=TAG20161029T064133 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 29-OCT-16
24 © 2016 Delphix Corporation
First backup of control file
RMAN> backup current controlfile;
25 © 2016 Delphix Corporation
First backup of control file
RMAN> backup current controlfile; Starting backup at 29-OCT-16 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set channel ORA_DISK_1: starting piece 1 at 29-OCT-16 channel ORA_DISK_1: finished piece 1 at 29-OCT-16 piece handle=/u01/app/oracle/fast_recovery_area/SINGPDB/backupset/2016_10_29/o1_mf_ncnnf_TAG20161029T081520_d194ps7y_.bkp tag=TAG20161029T081520 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 29-OCT-16
26 © 2016 Delphix Corporation
Auto-backup of control file
Control file can be backup automatically at the end of EVERY backup
Stored by default in FRA
Location of auto backup of control file can be customized
Disabled by default in 11.2
Enabled by default in 12.1.0.2
27 © 2016 Delphix Corporation
Auto-backup of control file
RMAN> show CONTROLFILE AUTOBACKUP; RMAN configuration parameters for database with db_unique_name ORCL are: CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON; new RMAN configuration parameters: CONFIGURE CONTROLFILE AUTOBACKUP ON; new RMAN configuration parameters are successfully stored
28 © 2016 Delphix Corporation
Useful parameters
§ FORMAT - for disk based backups it’s a path and file name - for tape based backups it’s is a name of backup set on the tape - can use metadata like:
%s – number of backup set %d – database name %u – unique string
§ TAG - a descriptor of backup set
29 © 2016 Delphix Corporation
Backup script
run { backup database format '/backup/bck_%d_%s_%u' tag 'first backup'; backup archivelog all format '/backup/bckarch_%d_%s_%u' tag 'first arch'; backup spfile format '/backup/bckspfile_%d_%s_%u' tag 'parameter file'; backup current controlfile format '/backup/bckcontrol_%d_%s_%u' tag 'first control'; }
30 © 2016 Delphix Corporation
Backup script – Default OEM script
run { allocate channel oem_disk_backup1 type disk ; allocate channel oem_disk_backup2 type disk ; recover copy of database with tag 'ORA$OEM_LEVEL_0'; backup incremental level 1 copies=1 for recover of copy with tag 'ORA$OEM_LEVEL_0' database; }
Recovery
32 © 2016 Delphix Corporation
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/oradata/rmantest/system01.dbf’
But control files and redo logs are available
33 © 2016 Delphix Corporation
First restore
RMAN> restore database;
34 © 2016 Delphix Corporation
First restore
connected to target database: RMANTEST (DBID=3937007440, not open) RMAN> restore database; using target database control file instead of recovery catalog 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 00001 to /u01/oradata/rmantest/system01.dbf channel ORA_DISK_1: restoring datafile 00003 to /u01/oradata/rmantest/sysaux01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/RMANTEST/backupset/2016_10_29/o1_mf_nnndf_TAG20161029T135209_d196vs73_.bkp channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:15 Finished restore at 29-OCT-16
35 © 2016 Delphix Corporation
First recover
RMAN> recover database;
36 © 2016 Delphix Corporation
First recover
RMAN> recover database; starting media recovery archived log for thread 1 with sequence 47 is already on disk as file /u01/app/… channel ORA_DISK_1: starting archived log restore to default destination channel ORA_DISK_1: restoring archived log archived log thread=1 sequence=45 channel ORA_DISK_1: restoring archived log archived log thread=1 sequence=46 channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 archived log file name=/u01/app/oracle/fast_recovery_area/RMANTEST/archivelog/channel default: deleting archived log(s) media recovery complete, elapsed time: 00:00:00 Finished recover at 29-OCT-16
37 © 2016 Delphix Corporation
First recovery
RMAN> alter database open; using target database control file instead of recovery catalog Statement processed
38 © 2016 Delphix Corporation
First recovery - script
run { restore database; recover database; sql "alter database open"; }
39 © 2016 Delphix Corporation
First recovery – connected to PDB
RMAN> run { 2> restore database; 3> recover database; 4> sql "alter database open"; 5> } 6> Starting restore at 29-OCT-16 using target database control file instead of recovery catalog channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00008 to /u01/oradata/singpdb/pdb/system01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:07 Finished restore at 29-OCT-16
40 © 2016 Delphix Corporation
First recovery – connected to PDB
starting media recovery archived log for thread 1 with sequence 18 is already on disk as file /u01/app/ archived log for thread 1 with sequence 19 is already on disk as file /u01/app/ media recovery complete, elapsed time: 00:00:01 Finished recover at 29-OCT-16 sql statement: alter database open Recovery Manager complete.
41 © 2016 Delphix Corporation
Learned so far
backup database
backup archivelog all
backup current control file
restore database
recover database
Point in time recovery
43 © 2016 Delphix Corporation
Point in time recovery
set until logseq X thread Y
set until time “to_date(‘2016-11-11 13:13:13’,’yyyyy-mm-dd hh24:mi:ss’)”
set until sequence 12345678
recover tablespace users until …… auxiliary destination '/tmp/';
recover table "TEST"."TEST" until ……….. auxiliary destination '/tmp’;
44 © 2016 Delphix Corporation
Point in time recovery
• Easy for a whole database (non-cdb)
• Easy for CDB plus all PDB databases
45 © 2016 Delphix Corporation
Common table spaces
Data table spaces
46 © 2016 Delphix Corporation
Point in time recovery
For other cases: • Tables space • Table • Single PDB
There are common objects like system and undo table space and redo/archive log.
Additional resources ( disk space, CPU and memory ) are required
47 © 2016 Delphix Corporation
Common table spaces
Data table spaces
Common table spaces
Data table spaces
48 © 2016 Delphix Corporation
Learned so far
set until ….
recover tablespace …. until
recover table …… until
Bare metal full recovery
50 © 2016 Delphix Corporation
Recovery using bare metal
$ ls -l /backup/ total 1414536 -rw-r----- 1 oracle oinstall 78684160 Nov 3 10:40 bckarch_RMANTEST_59_1rrjvsga -rw-r----- 1 oracle oinstall 10125312 Nov 3 10:40 bckcontrol_RMANTEST_61_1trjvsgc -rw-r----- 1 oracle oinstall 1359568896 Nov 3 10:40 bck_RMANTEST_58_1qrjvsg3 -rw-r----- 1 oracle oinstall 98304 Nov 3 10:40 bckspfile_RMANTEST_60_1srjvsgb
51 © 2016 Delphix Corporation
Recovery using bare metal
cat helpme.ora db_name=rmantest sqlplus / as sysdba Connected to an idle instance. 10:44:30 SYS @ rmantest:> ORACLE instance started. Total System Global Area 234881024 bytes Fixed Size 2922904 bytes Variable Size 176162408 bytes Database Buffers 50331648 bytes Redo Buffers 5464064 bytes
startup nomount pfile=helpme.ora
52 © 2016 Delphix Corporation
Recovery using bare metal
RMAN> channel ORA_DISK_1: restoring spfile from AUTOBACKUP /backup/bckspfile_RMANTEST_60_1srjvsgb channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete 10:48:24 SYS @ rmantest:>startup nomount force 10:48:34 SYS @ rmantest:>show parameter control NAME TYPE VALUE --------------------------------- ----------- ------------------------------ control_files string /u01/oradata/rmantest/control01.ctl
restore spfile from '/backup/bckspfile_RMANTEST_60_1srjvsgb';
53 © 2016 Delphix Corporation
Recovery using bare metal
RMAN> channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 output file name=/u01/oradata/rmantest/control01.ctl RMAN> alter database mount; Statement processed released channel: ORA_DISK_1
restore controlfile from '/backup/bckcontrol_RMANTEST_61_1trjvsgc';
54 © 2016 Delphix Corporation
Recovery using bare metal
RMAN> list backupset of archivelog all; List of Archived Logs in backup set 52 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- --------- ---------- --------- 1 49 2261707 29-OCT-16 2461778 29-OCT-16 1 50 2461778 29-OCT-16 2668366 29-OCT-16 1 51 2668366 29-OCT-16 2771110 01-NOV-16 1 52 2771110 01-NOV-16 2781493 01-NOV-16 1 53 2781493 01-NOV-16 2884324 03-NOV-16 1 54 2884324 03-NOV-16 2885615 03-NOV-16 1 55 2885615 03-NOV-16 2886075 03-NOV-16
55 © 2016 Delphix Corporation
Recovery using bare metal
run { set until logseq 56 thread 1; restore database; recover database; sql "alter database open resetlogs"; }
56 © 2016 Delphix Corporation
Recovery using bare metal – full script
run { restore spfile from '/backup/bckspfile_RMANTEST_60_1srjvsgb'; startup nomount force restore controlfile from '/backup/bckcontrol_RMANTEST_61_1trjvsgc'; sql "alter database mount"; set until time "to_date('2016-11-03 10:40:10','yyyy-mm-dd hh24:mi:ss')"; restore database; recover database; sql "alter database open resetlogs"; }
57 © 2016 Delphix Corporation
Recovery using bare metal – full script – version 2
run { restore spfile from '/backup/bckspfile_RMANTEST_60_1srjvsgb'; startup nomount force restore controlfile from '/backup/bckcontrol_RMANTEST_61_1trjvsgc'; sql "alter database mount"; restore database; recover database; }
58 © 2016 Delphix Corporation
Recovery using bare metal – full script – version 2
archived log file name=/u01/app/oracle/fast_recovery_area/RMANTEST/archivelog/2016_11_03/o1_mf_1_55_d1p7h1x7_.arc RECID=68 STAMP=926940129 unable to find archived log archived log thread=1 sequence=56 RMAN-00571: ========================================================== RMAN-00569: ============ ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: ========================================================= RMAN-03002: failure of recover command at 11/03/2016 11:22:11 RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 56 and starting SCN of 2886075 11:22:38 SYS @ rmantest:>alter database open resetlogs; Database altered.
Who is testing backup and recovery process ?
60 © 2016 Delphix Corporation
Schrödinger’s Backup Law “The condition of any backup is unknown until a restore is ” Corollary: A backup that has never been restored is equally likely to be good or bad. Like Herr Schrodinger’s poor cat!
attempted validaded
Vinay Srihari
ISSUES
62 © 2016 Delphix Corporation
Syntax errors
RMAN> backup; RMAN-00571: ========================================================= RMAN-00569: =========== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: ========================================================= RMAN-00558: error encountered while parsing input commands RMAN-01009: syntax error: found ";": expecting one of: "archivelog, as, auxiliary, backuppiece, backupset, backup, channel, check, controlfilecopy, copies, copy, cumulative, current, database, database root, datafilecopy, datafile, datapump, db_file_name_convert, db_recovery_file_dest, device, diskratio, duration, filesperset, force, format, for, from, full, incremental, keep, maxsetsize, nochecksum, noexclude, nokeep, not, pluggable, pool, proxy, recovery, reuse, section, skip readonly, skip, spfile, tablespace, tag, to, validate, (”
63 © 2016 Delphix Corporation
FRA scan
Database can switch to a other incarnation by scanning a FRA area (MOS 965122.1) RMAN> restore database; RMAN-06023: no backup or copy of datafile 4 found to restore RMAN-06023: no backup or copy of datafile 3 found to restore RMAN-06023: no backup or copy of datafile 2 found to restore RMAN-06023: no backup or copy of datafile 1 found to restore RMAN> list incarnation of database; 1 1 ORCL 1445553826 ORPHAN 1 24-AUG-13 2 2 ORCL 1445553826 ORPHAN 925702 21-JUL-16 3 3 ORCL 1445553826 CURRENT 1082361 08-NOV-16
64 © 2016 Delphix Corporation
FRA scan
RMAN> list backup of datafile 1 recoverable; specification does not match any backup in the repository RMAN> reset database to incarnation 2; database reset to incarnation 2 RMAN> list backup of datafile 1 recoverable; List of Backup Sets =================== 50 Full 1.24G DISK 00:00:10 12-SEP-16 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---- 1 Full 1050339 12-SEP-16 /u01/oradata/orcl/system01.dbf
Marcin Przepiorowski
Thank you for attending my session Q&A
Recommended