Module 3 Database Management

33
MODULE 3 DATABASE MANAGEMENT Section 5 Database Backup and Recovery 1 I T E C 4 5 0 F a l l 2 0 1 2

description

Module 3 Database Management. Section 5 Database Backup and Recovery. Introduction to Backup and Recovery. Backup is the process of making some kind of copies of parts of a database, or an entire database - PowerPoint PPT Presentation

Transcript of Module 3 Database Management

Page 1: Module 3  Database Management

ITEC 450

1

MODULE 3 DATABASE MANAGEMENTSection 5 Database Backup and Recovery

Fall 2012

Page 2: Module 3  Database Management

2

ITEC 450INTRODUCTION TO BACKUP AND

RECOVERY Backup is the process of making some kind of

copies of parts of a database, or an entire database

Recovery is the process of rebuilding a database after some part of a database has been lost

Restoration is the process of copying files from a backup

Recovery is the process of executing procedures in Oracle Database to update the recovered backup files to an up to date state

Fall 2012

Page 3: Module 3  Database Management

3

ITEC 450

WHAT IS BACKUP?Fall 2012

Page 4: Module 3  Database Management

4

ITEC 450

WHAT IS RESTORATION? Fall 2012

Page 5: Module 3  Database Management

5

ITEC 450

CATEGORIES OF DATABASE FAILURES Instance failures – service interruption, no

data loss DBMS internal exception Operating system failure Hardware-related failures except storage media:

CPU, Memory board, disk controller Human error – hardest to prevent, data issue

Programs are run at the wrong time, wrong order, or wrong input

Media failure – data unavailable, recovery needed Disk damage, file system failures, data file

deletion Tape degradation or damage

Fall 2012

Page 6: Module 3  Database Management

6

ITEC 450

DATABASE BACKUP CHOICESBackup strategies are driven by the recovery

requirements. Full and incremental backups

Full – a complete copy at the time the backup was run. Incremental (differential) – the backup of changes

since the last full or incremental backup Consistent and inconsistent backups

Consistent – the data in the backup is from a same point in time

Inconsistent – the backup is done while the database is open and there are changes

Physical and logical backups Physical – copy physical data files to a backup device Logical – export of (selected) data from database to a

file or a backup device

Fall 2012

Page 7: Module 3  Database Management

7

ITEC 450

BACKUP GUIDELINESThe DBA must assure a recoverable environment. Make at least two copies of backup to avoid a

single point of failure such as a damaged tape Coordinate local backup strategy with disaster

recovery strategy Consider backups to disk, and then migrating to

tape Be sure to include the system catalog objects in

the backup Verify the correctness of the backup once a while Database data and application metadata should

be backed up at the same time.

Fall 2012

Page 8: Module 3  Database Management

8

ITEC 450

BACKUP LEVELS AND COVERAGE Backup levels

Level 0 (full) – a full backup of the database: all physical files associate the database

Level 1 (cumulative) – a backup of all of the data that has changed since the last level 0 backup

Level 2 (incremental) – a backup of all of the data that has changed since the last backup of any level (0, 1 or 2)

Backup coverage Log archiving – it is required for up-to-time recovery System catalog – containing backup and recovery

information Database object definition – It’s nice to have it over time

to track what changed, and be able to recreate objects if necessary

Fall 2012

Page 9: Module 3  Database Management

9

ITEC 450

RECOVERY STEPS Identify the failure Analyze the situation Determine what needs to be recovered Locate the required image copy backup Restore the image copy backup Roll forward through the database log

Fall 2012

Page 10: Module 3  Database Management

10

ITEC 450

RECOVER TO CURRENT Recovery to current usually responds to a media failure,

such as accidentally deleted, or disk crashed. Restored database can be from full, cumulative, and/or

incremental.

Fall 2012

Page 11: Module 3  Database Management

11

ITEC 450

POINT-IN-TIME RECOVERYThe PIT recovery responds non-media failures,

such as application-level problem or user error.

It will restore the whole database back to the time before the error. All changes between the time of the error and current will be rolled back.

Recovery description: Restore whole database backup Apply the database change logs from the

time of backup to the time just before the error

Open the database as the moment before the error

Fall 2012

Page 12: Module 3  Database Management

12

ITEC 450

WHAT IS RECOVERY? Redo logs and archive logs consist of records of

all transactions made to a database Controlfiles contain pointers to datafiles, dictating

where datafiles should be in relation to redo log entries If a datafile is restored from a backup, then the

controlfile will be ahead of the datafile in time Restoration of recovered backup is a simple

process of applying redo log entries to the datafile, until the datafile “catches up” to the time indicated by controlfile

Archive logs are copies of old redo log files, copied just before redo log files are reused Restoration can utilize entries in both redo log files

and archive log files to complete a recovery

Fall 2012

Page 13: Module 3  Database Management

13

ITEC 450

TRANSACTION RECOVERYTransaction recovery addresses an error from a

specific transaction. respond non-media failures, such as application-level problem or user error.

Recovery options are: PIT recovery – remove all changes including

the error and other transactions UNDO recovery – remove only the effects of

the bad transaction REDO recovery – PIT recovery and then redo

the good transactions only

Fall 2012

Page 14: Module 3  Database Management

14

ITEC 450ALTERNATIVES TO BACKUP AND RECOVERYOther high-availability alternatives can be

used: Standby database or database mirroring – an

identical copy of an online production database that is close to being up-to-date.

Data replication or transactional replication – storing and maintaining redundant data in a separate database

Hardware redundancy with disk replication locally or remotely – allocating a secondary device that contains a duplicate copy of the primary device

Fall 2012

Page 15: Module 3  Database Management

15

ITEC 450

DISASTER PLANNINGDisaster recovery planning, also called

contingency planning is the process for: Any unplanned, extended loss of critical

business applications due to lack of computer processing capabilities for more than a 48-hour period.

Any event that has a small chance of transpiring, a high-level of uncertainty, and a potentially devastating outcome.

Examples: floods, earthquakes, hurricanes, fires, terrorist attacks

Fall 2012

Page 16: Module 3  Database Management

16

ITEC 450

DISASTER RECOVERY GUIDELINESThe goals are to minimize downtime and loss

of data. Analyze business risks, and not technical

needs and issues Rank applications into groups Plan for enterprise wide business functions

and operational activities Build an off-site location Establish a written plan and distribute to all

key personnel Testing disaster plans

Fall 2012

Page 17: Module 3  Database Management

17

ITEC 450DATABASE PLANNING FOR DISASTER RECOVERYDatabase strategies for disaster recovery: Tape backups, and ship them to the remote

site Storage management software to make

point-in-time copies of entire disk packs Remote mirroring of data to the alternate

site over the network Standby or database mirroring at a different

physical site from the primary database location

Fall 2012

Page 18: Module 3  Database Management

ITEC 450

18

MODULE 3 DATABASE MANAGEMENTSection 6 Oracle Backup and Recovery

Fall 2012

Page 19: Module 3  Database Management

19

ITEC 450BACKUP AND RECOVERY CONCEPTS Archivelog and noarchivelog modes

Archivelog – Oracle saves the filled redo logs as archivelogs. You may recover the database to any point in time.

Noarchivelog – Oracle overwrites the filled redo logs. You can’t recover the database changes since the last cold backup took place.

Restoring and Recovery Restoring a database means copying the physical files

from a backup medium. Recovery is the process of updating database files

restored from a backup with the changes made to the database after the backup, typically using redo log files.

Fall 2012

Page 20: Module 3  Database Management

20

ITEC 450CONSISTENT AND INCONSISTENT BACKUPS Consistent Backups (closed, cold)

To make a consistent backup, the database is shutdown cleanly and remain closed for the duration of the backup.

All committed changes are written to the datafiles, so the datafiles are in a transaction-consistent sate.

When you restore your datafiles from a consistent backup, you can open the database immediately.

Inconsistent Backups (open, online, hot) If a database is in ARCHIVELOG mode, then you can make

inconsistent backups that are recoverable using archived redo log files.

The redo logs must be archived and then backed up with the datafiles to ensure recoverability.

An inconsistent backup is robust a form of backup as a consistent backup. It is common for production environments.

Fall 2012

Page 21: Module 3  Database Management

21

ITEC 450METHODS OF BACKUP AND

RECOVERY Two basic methods of backup and recovery:

Cold backups Hot backups

Fall 2012

Page 22: Module 3  Database Management

22

ITEC 450TOOLS FOR BACKUP AND

RECOVERY Tools used for backup and recovery of an

Oracle database are as follows:Export and Import UtilitiesBackup Mode Tablespace CopiesRMAN (Recovery Manager)Oracle Enterprise Manager and the

Database Control

Fall 2012

Page 23: Module 3  Database Management

23

ITEC 450

WHAT IS A COLD BACKUP? Fall 2012

Page 24: Module 3  Database Management

24

ITEC 450

COLD BACKUPS For a cold backup, shut down the database

completely and then copy all the files All datafiles All redo log files All archive log files All controlfiles Optionally you can also back up parameter files

and any networking configuration files Restore at least all the datafiles and

controlfiles Optionally use more current redo log files,

archive log files, and controlfiles—allowing a recovery by applying redo log entries to datafiles

Fall 2012

Page 25: Module 3  Database Management

25

ITEC 450

WHAT IS A HOT BACKUP? Hot backup: performed when DB is online, active, and

available for use Many tools and methods for performing hot

backups Takes a snapshot of a database one file or type of

file at a time Not necessarily consistent across all files in

backup Made of pieces of a DB, where those files making

up a complete DB backup are not recoverable to a working database as a group Individual files can be slotted into a running DB,

and can be recovered individually, or as a group

Fall 2012

Page 26: Module 3  Database Management

26

ITEC 450SETTING THE DATABASE IN

ARCHIVE LOG MODE In archive log mode, the database will create

archive logs for you Archive logs are files that are copied from

redo logs when a redo log file is switched out for recycling

Redo logs contain entries of all transactional activity in a database as transactions occur Redo logs are recycled

If a redo log is recycled, unless the redo log is copied to an archive log, all entries in that redo log group are effectively lost

A database must be in archive log mode to duplicate redo logs to archive logs

Fall 2012

Page 27: Module 3  Database Management

27

ITEC 450SETTING THE DATABASE IN

ARCHIVE LOG MODEARCHIVE LOG LIST;

ARCHIVE LOG STOP;

SHUTDOWN IMMEDIATE;STARTUP MOUNT;ALTER DATABASE NOARCHIVELOG;ALTER DATABASE OPEN;

SHUTDOWN IMMEDIATE;STARTUP MOUNT;

ALTER DATABASE ARCHIVELOG;ALTER DATABASE OPEN;

Fall 2012

Page 28: Module 3  Database Management

28

ITEC 450CONSISTENT BACKUPS USING

EXPORTS Export can be used to create a consistent

backup Export can scan through all types of data,

including tables, redo and archive logs, and undo data Allows for a consistent backup (export) based on a

snapshot of data In other words, regardless of any changes occurring to

DB, during an export, the export utility will read datafiles and undo space to get a consistent backup

Examples:exp system/<password>@oraclass file=classmate.dat owner=classmate consistent=Y

exp classmate/classpass@oraclass file=classmatetables.dat tables=(client,customer)

Fall 2012

Page 29: Module 3  Database Management

29

ITEC 450

TABLESPACE BACKUPS In a tablespace backup, you switch a

tablespace into a special mode called backup mode This allows a physical operating system-level

copy of that tablespace In Oracle 10g, allows a backup mode setting to

be applied to all tablespaces at once Problem with backup mode is a performance

issue Forces all change activity for that tablespace to be

copied to the redo logs If there are enough redo entries produced to

recycle a redo log group, then archive log files will be used too

The longer a tablespace remains in backup mode, the more performance is affected, the longer any potential recovery is, and more redo log data is produced

Fall 2012

Page 30: Module 3  Database Management

30

ITEC 450OTHER APPROACHES TO BACKUP

AND RECOVERY Fall 2012

Page 31: Module 3  Database Management

31

ITEC 450CONFIGURATION OF BACKUP AND RECOVERY Configure a flash recovery area –

storing most backup related files Run database in ARCHIVELOG mode

It is required for online backup It enables recovery options such as compete and

point-in-time media recovery RMAN is the backup and recovery tool for

Oracle database.

Fall 2012

Page 32: Module 3  Database Management

32

ITEC 450

ORACLE RECOVERY STRATEGY Response to media failure – recovery to

current Response to non-media failure – PIT recovery,

flash back Instance failure – Oracle performs instance

recovery automatically: all you need to do is restart the database. A power outage causes the server to crash The server becomes unavailable because of hardware

problems The operating system crashes One of the Oracle background processes fails. You issue a SHUTDOWN ABORT statement

Fall 2012

Page 33: Module 3  Database Management

33

ITEC 450

WRAP UP Assignment 8-1

Using a specific DBMS example to present database security management

Hands-on practice to understand Oracle security: create a user, try to login and create a table

Detailed steps are on the course website Assignment 3-1-3: Lab3 – Backup and

Recovery Reference to “assginment3-1-3 help.pdf”,

otherwise take you a lot of effort to read Oracle documents

Hands-on practice: Cold backup Hands-on practice: Hot backup Challenges and technical

Fall 2012