Вы находитесь на странице: 1из 43

Backup & Recovery with RMAN

Ravi Poruri
June 10, 2008
Yahoo! Confidential 1

Agenda
Types of failures and backups in Oracle RMAN Architecture Manual vs. RMAN backups On-tape backups with RMAN RMAN Configuration RMAN backup strategies RMAN backup examples Reporting from RMAN Validate Backups
2

Yahoo! Confidential

Types of failures

Types of failures
Instance Failure Usually connected with an Oracle process failure Media Failure Disk failure, storage array controller failure etc. Block Corruption Usually caused by bugs in Oracle software Human error In most cases accidentally deleted/updated data Database user or DBA Disaster Fire, flood, earthquake, plane crash etc.

Yahoo! Confidential

Backup options in Oracle


Physical backups Cold (off-line) backups Full database only Require downtime Do not provide flexibility for point in time recovery (PiTR) Hot (on-line) backups Different types of backups: full, incr. (cumulative, differential), archivelogs Different scopes: full database, tablespace(s) or datafile(s) Do not require database downtime Can be used to recover full database, single/multiple tablespace(s)/datafile(s) or a corrupted block Database can be recovered to any point in time within assumed backup retention period
Yahoo! Confidential 5

Backup options in Oracle (2)


Logical backups Logical copy of data in the database Support for different backup granularity Can be taken either with legacy Export/Import tools or with Data Pump (10g) Standby systems (Data Guard) Physical and logical standby databases

Yahoo! Confidential

How hot backups are possible?


Hot Backup

SGA

Server proc. DBWR


Db file Db file Db file

Backup proc.

LGWR

Tapes or disks system

RedoLog

Log archiver

Db file

RedoLog

Archived redo logs

Yahoo! Confidential

RMAN architecture

Target Database

RMAN Client Target Database

Target Database

Auxiliary Database

Catalog Database

Yahoo! Confidential

Types of RMAN hot backups


Copy or backupset Full database backup Incremental backups (in 10g 2 levels available: 0 and 1) Cumulative, differential Can be used to update a copy of the database

Archivelog backups Tablespace(s), datafile(s) backups

Differential incremental
Yahoo! Confidential

Cumulative incremental
9

Manual vs. RMAN backups


RMAN advantages: Supports incremental backup strategies RMAN on-line backups are not so heavy for the system as manual on-line backups RMAN can detect corrupted blocks RMAN automatically track database structure changes Provides easy, automated backup, restore and recovery operations Keeps invenotory of taken backups Can seamlessly work with third party media managers Disadvantage: something new to learn RMAN concepts and command syntax sometimes are not intuitive
Yahoo! Confidential 10

On-tape backups with RMAN


RMAN allows to take on-disk backups out of the box Flash recovery area, if configured, further simplifies such backups On disk backups are interesting but usually not sufficient for a disaster recovery On-disk backups can be manually sent to tapes Recovery can be very troublesome RMAN can seamlessly work with third party Media Managers Media Manager Library (MML) is required Different configuration tasks for different MMLs

Yahoo! Confidential

11

Traditional Incremental Backup


RMAN reads every block Compares block SCN with checkpoint SCN of parent incremental backup If block SCN >= backup SCN than copy this block

Yahoo! Confidential

12

Block Change Tracking


RMAN retrieves checkpoint SCN of a parent incremental backup RMAN identifies blocks to read based on a bitmap in a BCT file Only available in the Enterprise Edition

Yahoo! Confidential

13

Bitmap Extents
1 header + 63 bitmap blocks (32 KB) Every bitmap block provides 488 bytes or 3904 bits; i.e. 3904 chunks covered 1 bitmap block serves 122 MB of space in datafile 1 bitmap extent can track 7686 MB of data Extents allocated when file resized 7 versions kept Every version occupies separate extents

Yahoo! Confidential

14

BCT File Sizing


Initial size is 1 MB + 10 MB for bitmaps 2176 initial blocks 320 extents * 32 KB = 10 MB At least one for datafile descriptors 318 bitmap extents 39 datafiles with 8 versions Max ~300 GB of data tracked by 10 MB chunk of BCT file In RAC every instance uses its own extents so multiply by number of nodes

Yahoo! Confidential

15

BCT File Evolution


New datafile, drop tablespace Changing data Incremental backup Level 0, 1, 2 cumulative Restore

Yahoo! Confidential

16

Purging Oldest Version


If more than 7 versions exist (including current) Which version to purge on backup? Version 1 Which version to purge on backup? Version 2 No merge How many blocks does RMAN read on backup 10? All blocks
- Level 0 backup - Level 1 backup 1 2 3 4 5 6 7 8 9 10

Yahoo! Confidential

17

RMAN Configuration
RMAN can be preconfigured Configuration is stored in the control file and in the recovery catalog (if used) Can facilitate backup automation

Most useful settings:

Setting Controlfile autobackup Retention policy Device type

Default off to redundancy 1 disk parallelism 1 ...

Recommended on to recovery window of 31 days disk|sbt prallelism 2 ...

Default device type


Backup optimization Channel device type Maxsetsize
Yahoo! Confidential

to disk
off none unlimited

to sbt
off sbt parms=... depends on your database size
18

RMAN Configuration (2)


Example:
configure RETENTION POLICY TO RECOVERY WINDOW OF 31 DAYS; configure DEFAULT DEVICE TYPE TO 'sbt'; configure DEVICE TYPE 'sbt' PARALLELISM 2; configure CHANNEL DEVICE TYPE sbt parms='ENV= (TDPO_OPTFILE=/opt/tivoli/tsm/client/oracle/bin/tdpo.opt)'; configure DEVICE TYPE DISK PARALLELISM 2; configure MAXSETSIZE TO 200 G; configure archivelog backup copies for device type 'sbt' to 1; configure controlfile autobackup on;

The SHOW ALL command lists all RMAN configuration settings To clear a given settings append CLEAR at the end of the CONFIGURE command

Yahoo! Confidential

19

RMAN backup strategies


RMAN allows many types of backups It possible to build own backup strategy that suits given database best There are also Oracle recommended backup strategies: Incremental backup strategy: level 0 backups + level 1 backups (cumulative and/or differential) and archivelog backups inbetween. Incrementally updated database copy: 1 backup as copy of the whole database + incremental backups used to update the copy + archived redo logs.

Yahoo! Confidential

20

Backup strategy example


Both Oracle-recommended strategies implemented for all production systems Incremental backup strategy: Backups go to tapes Weekly or biweekly level 0 backups (depending on the DB size) A level 1 cumulative backup inbetween Daily incremental level 1 differential backups Archivelog backup every 30 minutes Incrementally updated DB copy strategy: daily incremental differential backups applied with 2 days of delay Copies, incremental backups and archived redo logs stored in the Flash Recovery Area
Yahoo! Confidential 21

Backup operations example


Central machine to schedule and run all the backups Central RMAN catalog exported on regular basis Examples of RMAN commands being used:

run { crosscheck archivelog all; backup force tag some_tag_0T' incremental level 0 check logical database force format '%d_%T_%U_lvl0T' plus archivelog format '%d_%T_%U_lvl0Tarch'; delete noprompt force archivelog all completed before sysdate - 2"; } run { crosscheck archivelog all; backup tag some_tag_1D' incremental level 1 database format '%d_%T_%U_lvl1D' plus archivelog format '%d_%T_%U_lvl1Darch'; delete noprompt force archivelog all completed before sysdate 2; }

Yahoo! Confidential

22

Backup operations example (2)


run { backup tag some_tag_AR' archivelog all format '%d_%T_%U_arch'; delete noprompt force archivelog all completed before sysdate - 2; }

run { backup maxsetsize 2047G tag ' DB_Copy_tag' device type disk incremental level 1 for recover of copy with tag DB_Copy_tag database; recover device type disk copy of database with tag DB_Copy_tag until time sysdate -2 ; delete force noprompt backupset device type disk tag DB_Copy_tag completed before sysdate -2; }

Yahoo! Confidential

23

Complete database recovery


Needed when: All datafiles are lost or the SYSTEM tablespace datafiles are lost At least one member of each redo log group survived Requires: Control file recovery (if its lost) Datafile restore from a backup Database recovery using incremental backups and/or archived redo logs and online redo logs
startup mount run { allocate channel c1 device type disk|sbt; allocate channel c2 device type disk|sbt; restore database check readonly; recover database; alter database open; }

Yahoo! Confidential

24

Database point-in-time recovery


Needed when:
all datafiles are lost All copies of the current control file are lost Or all online redo log group members are lost

The most typical recovery in case of systems implementing SAME approach If done after a disaster it has to be preceded by:
Hardware configuration OS and Oracle software installation Re-creation or restore from non-RMAN backup of listener.ora, tnsnames.ora and other important configuration files ASM instance and diskgroup configuration (if needed) MML installation and configuration ...

Requires
Spfile restore Controlfile restore Datafiles restore and recovery

Yahoo! Confidential

25

set dbid=xxxxxxx startup nomount; run { allocate channel c1 device type disk|sbt; restore spfile to some_location from autobackup; recover database; alter database open resetlogs; } shutdown immediate; startup nomount; run { allocate channel c1 device type disk|sbt; restore controlfile from autobackup; alter database mount; } run { set until time = "to_date(09-Jun-2008 00:00:00','dd-mon-yyyy hh24:mi:ss')"; allocate channel c1 device type disk|sbt; allocate channel c2 device type disk|sbt; restore database check readonly; recover database; alter database open resetlogs; }
Yahoo! Confidential 26

Tablespace point-in-time recovery


Needed Mainly to address a human error Oracle makes efforts to automate it Can be done with few clicks in OEM Requires Point in time recovery of the whole database (an auxiliary instance is created) Export/import of selected tablespaces schemas or objects

Yahoo! Confidential

27

Block media recovery


Needed when: Database reports either single or multi block corruption Can be done with an open database Only the table(s) containing corrupted blocks are not available Database corruptions can be discovered with RMAN backup validate database command Corrupted blocks can be found in V$DATABASE_BLOCK_CORRUPTION

ORA-01578: ORACLE data block corrupted (file # 19, block # 44) ORA-01110: data file 19: d:\oracle\oradata\data\mydb_maintbs_01.dbf run { allocate channel c1 device type disk|sbt; blockrecover datafile 19 block 44; }

Yahoo! Confidential

28

Single/multiple datafile/tablespace recovery


Needed when Single/multiple tablespaces or datafiles have been lost SYSTEM tablespace is intact Controlfiles and online redo logs are intact Requires To put offline datafiles and tablespaces being recovered The database can be open and available to users

run { sql alter tablespace users offline; allocate channel c1 device type disk|sbt; restore tablespace users; recover tablespace users; sql alter tablespace users online; }

Yahoo! Confidential

29

Reporting from RMAN


CATALOG command CHANGE command DELETE command CROSSCHECK command RESYNC command LIST command REPORT command

Yahoo! Confidential

30

CATALOG command
Add backup pieces and image copies on disk to repository so they can be used in restores and recoveries Record backup images (i.e. COPY command in RMAN) as INCREMENTAL LEVEL = 0 backups

Yahoo! Confidential

31

CHANGE command
To change the status of backups, copies, and archived logs in the repository to AVAILABLE or UNAVAILABLE. This feature is useful when a previously unavailable file is made available again, or you do not want a specific backup or copy to be eligible to be restored but also do not want to delete it. To alter the repository status of usable backups and copies from prior incarnations (i.e. prior to RESETLOGS) To remove catalog records for backups and copies, and update the corresponding records in the target control file to status DELETED. This feature is useful when you remove a file by using an operating system command rather than the RMAN DELETE command, and want to remove its repository record as well.

Yahoo! Confidential

32

DELETE command
Delete backupsets and/or image-copies on disk or tape
DELETE [ OBSOLETE | EXPIRED ]

Update backupset piece records in the target control file to status DELETED, regardless of the state of the backupset piece
DELETE FORCE

Remove their repository records from the recovery catalog (if you use a catalog)
DELETE FORCE

Yahoo! Confidential

33

CROSSCHECK command
Verify the status of backups and copies recorded in the RMAN repository against media such as disk or tape 1. Read entries in the repositories
Connect NOCATALOG or CATALOG

2. Try to touch each relevant entry on the allocated channel


Allocate channel for DISK or SBT_TAPE

Command CROSSCHECK BACKUP OF DATABASE CONTROLFILE ARCHIVELOG

Yahoo! Confidential

34

RESYNC command
Synchronize information between control files and recovery catalog Can also be used to completely repopulate the recovery catalog from a backup controlfile, if desired When you run RESYNC CATALOG, RMAN creates a snapshot control file in order to obtain a read-consistent view of the control file, then updates the recovery catalog with any new information from the snapshot.

Yahoo! Confidential

35

LIST command
To display information about backup sets, proxy copies, and image copies recorded in the repository Displays files against which you can run CROSSCHECK and DELETE
commands

Use this command to list:


Backups and copies that do not have the status AVAILABLE in the RMAN repository Backups and copies of datafiles that are AVAILABLE and can possibly be used in a RESTORE operation Specified archived logs, backup sets, backup pieces, control file copies, datafile copies, and proxy copies Backups and copies restricted by tag, completion time, recoverability, or device Incarnations of a specified database or of all databases known to the repository Stored scripts in the recovery catalog

Yahoo! Confidential

36

REPORT command
Use the REPORT command to answer questions such as the following: Which datafiles need a backup?
REPORT NEED BACKUP;

Which datafiles have not had a backup for some time?


REPORT NEED BACKUP [ DAYS | INCREMENTAL | RECOVERY WINDOW | REDUNDANCY ]

Which datafiles are not recoverable due to unrecoverable operations?


REPORT UNRECOVERABLE

Which backupset and image-copy files can be deleted?


REPORT OBSOLETE

What was the physical schema (i.e. datafiles and tablespaces) of the database at a previous time?
REPORT SCHEMA AT [ SCN | SEQUENCE | TIME ]
Yahoo! Confidential 37

Examples

Back up the database, and then the control file: (which contains a record of the backup) RMAN> BACKUP DATABASE; RMAN> BACKUP CURRENT CONTROLFILE; Backup datafiles: RMAN> BACKUP AS BACKUPSET DATAFILE 'ORACLE_HOME/oradata/trgt/users01.dbf', 'ORACLE_HOME/oradata/trgt/tools01.dbf'; Backup all datafiles in the database: (bit-for-bit copies, created on disk) RMAN> BACKUP AS COPY DATABASE;

Yahoo! Confidential

38

Examples
Backup archive logs
RMAN> BACKUP ARCHIVELOG COMPLETION TIME BETWEEN 'SYSDATE-28' AND 'SYSDATE-7';

Backup tablespace
RMAN> BACKUP TABLESPACE system, users, tools;

Backup controlfile
RMAN> BACKUP CURRENT CONTROLFILE TO '/backup/cntrlfile.copy';

Backup parameter file


RMAN> BACKUP SPFILE;

Backup everything:
RMAN> BACKUP BACKUPSET ALL;

Yahoo! Confidential

39

Validate Backups
Backup Validation confirms that a backup could be run, by confirming that all database files exist and are free of physical and logical corruption, this does not generate any output
RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;

Yahoo! Confidential

40

Restore Validate
RESTORE... VALIDATE causes RMAN to check whether the set of available backups is sufficient to restore the specified database objects.

Example: RESTORE TABLESPACE TBS_1 VALIDATE selects backups sufficient to restore the named tablespace, just as RMAN does in a real restore operation, and reads the backups to ensure that they are present and not corrupted.

Yahoo! Confidential

41

Enjoy the afternoon !

42

Yahoo! Confidential

43

Вам также может понравиться