Presentation is loading. Please wait.

Presentation is loading. Please wait.

6 Copyright © 2007, Oracle. All rights reserved. Performing User-Managed Backup and Recovery.

Similar presentations


Presentation on theme: "6 Copyright © 2007, Oracle. All rights reserved. Performing User-Managed Backup and Recovery."— Presentation transcript:

1 6 Copyright © 2007, Oracle. All rights reserved. Performing User-Managed Backup and Recovery

2 Copyright © 2007, Oracle. All rights reserved. 6 - 2 Objectives After completing this lesson, you should be able to: Describe the difference between user-managed and server- managed backup and recovery Manually back up a data file, tablespace, and database Back up and recover a control file Perform user-managed complete database recovery Perform user-managed incomplete database recovery Recover from a lost TEMP file Recover from a lost redo log group

3 Copyright © 2007, Oracle. All rights reserved. 6 - 3 Restoring and Recovering Restore Recover Redo log

4 Copyright © 2007, Oracle. All rights reserved. 6 - 4 Causes of File Loss File loss can be caused by: User error Application error Media failure

5 Copyright © 2007, Oracle. All rights reserved. 6 - 5 Critical Versus Noncritical A noncritical file loss is one where the database can continue to function. You fix the problem by taking one of these actions: Create a new file. Rebuild the file. Recover the lost or damaged file.

6 Copyright © 2007, Oracle. All rights reserved. 6 - 6 Losing a TEMPFILE SQL statements that require TEMP space to execute fail if one of the tempfiles is missing. SQL> select * from big_table order by 1,2,3,4,5,6,7,8,9,10,11,12,13; select * from big_table order by 1,2,3,4,5,6,7,8,9,10,11,12,13 * ERROR at line 1: ORA-01565: error in identifying file '/u01/app/oracle/oradata/orcl/temp01.dbf' ORA-27037: unable to obtain file status Linux Error: 2: No such file or directory

7 Copyright © 2007, Oracle. All rights reserved. 6 - 7 Recovering from a TEMPFILE Loss Password file Parameter file SYSTEM SYSAUX UNDO USERS INDEX Redo log file 1B Redo log file 1A Redo log file 2B Redo log file 2A Control files TEMP

8 Copyright © 2007, Oracle. All rights reserved. 6 - 8 Log Group Status: Review A redo log group has a status of one of the following values at any given time: CURRENT : The LGWR process is currently writing redo data to it. ACTIVE : It is no longer being written to, but it is still required for instance recovery. INACTIVE : It is no longer being written to, and it is no longer required for instance recovery.

9 Copyright © 2007, Oracle. All rights reserved. 6 - 9 Recovering from the Loss of a Redo Log Group Group status Inactive Active Fix media? Yes No Clear log file Perform checkpoint CKPT successful? Yes Done No Restore and recover until cancel Start Current

10 Copyright © 2007, Oracle. All rights reserved. 6 - 10 Clearing a Log File Log file archived? Yes No Start ALTER DATABASE CLEAR LOGFILE... ALTER DATABASE CLEAR LOGFILE UNARCHIVED... Needed for data file? No ALTER DATABASE CLEAR LOGFILE UNARCHIVED... UNRECOVERABLE DATAFILE Yes

11 Copyright © 2007, Oracle. All rights reserved. 6 - 11 Re-Creating Indexes Use options to reduce the time it takes to create the index: PARALLEL NOLOGGING SQL> CREATE INDEX rname_idx 2 ON hr.regions (region_name) 3 PARALLEL 4;

12 Copyright © 2007, Oracle. All rights reserved. 6 - 12 Recreating Indexes Full Notes Page

13 Copyright © 2007, Oracle. All rights reserved. 6 - 13 Recovering from a Lost Index Tablespace A tablespace that contains only indexes may be recovered without performing a RECOVER task. If a data file that belongs to an index-only tablespace is lost, it may be simpler to re-create the tablespace and re-create the indexes.

14 Copyright © 2007, Oracle. All rights reserved. 6 - 14 Remote database administration Local database administration Yes No Do you have a secure connection? Use OS authentication. Use a password file. Authentication Methods for Database Administrators Do you want to use OS authentication?

15 Copyright © 2007, Oracle. All rights reserved. 6 - 15 Re-Creating a Password Authentication File $ orapwd file=$ORACLE_HOME/dbs/orapworcl password=ora entries=5 SQL> grant sysdba to admin2; grant sysdba to admin2 * ERROR at line 1: ORA-01994: GRANT failed: password file missing or disabled To recover from the loss of a password file: 1.Re-create the password file by using orapwd. 2.Add users to the password file and assign appropriate privileges to each user.

16 Copyright © 2007, Oracle. All rights reserved. 6 - 16 Re-Creating a Password Authentication File Full Notes Page

17 Copyright © 2007, Oracle. All rights reserved. 6 - 17 Comparing Complete and Incomplete Recovery Recovery can have two kinds of scope: Complete recovery: Brings the database up to the present, including all committed data changes made to the point in time when the recovery was requested Incomplete recovery: Brings the database up to a specified point in time in the past, before the recovery operation was requested Recovery task started at this time Complete recovery Incomplete recovery Missing transactions after incomplete recovery Restore from this backup Time of crash

18 Copyright © 2007, Oracle. All rights reserved. 6 - 18 Complete Recovery Process Restored data files Data files containing committed and uncommitted transactions Recovered data files Changes applied Undo applied 6 5 3 2 1 Archived log Online Redo log 4 Database opened

19 Copyright © 2007, Oracle. All rights reserved. 6 - 19 Incomplete Recovery Process Data files containing committed and uncommitted transactions up to PIT PIT-recovered data files Archived log Online Redo log X X Changes applied to point in time (PIT) Restored data files from as far back as necessary Undo applied 6 5 3 1 2 4 Database opened

20 Copyright © 2007, Oracle. All rights reserved. 6 - 20 Incomplete Recovery Process Full Notes Page

21 Copyright © 2007, Oracle. All rights reserved. 6 - 21 Types of Backup and Recovery Practices Types of database backup and recovery are: User-managed: Does not use RMAN. –Uses OS commands to move files around –Keeps some records of backup activity manually Server-managed: Uses RMAN

22 Copyright © 2007, Oracle. All rights reserved. 6 - 22 Performing a User-Managed Backup of the Database ARCHIVELOG mode? ShutdownPut tablespaces into backup mode Copy files NoYes

23 Copyright © 2007, Oracle. All rights reserved. 6 - 23 The Need for Backup Mode Database block A DML statement updates a database block: Different parts of the block are written to at different times: t2t2 t1t1 t3t3 Copy data file while online If the block is copied at time t 2, then the block is fractured.

24 Copyright © 2007, Oracle. All rights reserved. 6 - 24 Identifying Files to Manually Backup SQL> select name from v$datafile; NAME ------------------------------------------------------------------------ /u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_36mky81f_.dbf /u01/app/oracle/oradata/ORCL/datafile/o1_mf_sysaux_36mky81p_.dbf /u01/app/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_36mky857_.dbf /u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_36mky876_.dbf /u01/app/oracle/oradata/ORCL/datafile/o1_mf_example_36ml2cmh_.dbf /u01/app/oracle/oradata/ORCL/datafile/survey01.dbf SQL> select name from v$controlfile; NAME ------------------------------------------------------------------------ /u01/app/oracle/oradata/ORCL/controlfile/o1_mf_36ml1f8x_.ctl /u01/app/oracle/flash_recovery_area/ORCL/controlfile/o1_mf_36ml1fkk_.ctl

25 Copyright © 2007, Oracle. All rights reserved. 6 - 25 Manually Backing Up a NOARCHIVELOG Database Shut down the database: SQL> SHUTDOWN IMMEDIATE $ cp $ORACLE_BASE/ORCL/datafile/*.dbf \ > /u02/backup/datafile SQL> STARTUP Copy the data files to the backup location: Start up the database:

26 Copyright © 2007, Oracle. All rights reserved. 6 - 26 Manually Backing Up an ARCHIVELOG Database SQL> ALTER TABLESPACE users BEGIN BACKUP; Identify tablespaces and their datafiles: $ cp $ORACLE_HOME/oradata/orcl/users*.dbf /u02/backup/datafile Copy the data files for that tablespace to the backup location: Bring the tablespace out of backup mode: SQL> ALTER TABLESPACE users END BACKUP; SQL> select file_name, tablespace_name from dba_data_files; FILE_NAME TABLESPACE_NAME --------------------------------------------- --------------- /u01/app/oracle/oradata/orcl/users01.dbf USERS /u01/app/oracle/oradata/orcl/users02.dbf USERS /u01/app/oracle/oradata/orcl/undotbs1.dbf UNDOTBS1 /u01/app/oracle/oradata/orcl/sysaux01.dbf SYSAUX /u01/app/oracle/oradata/orcl/system01.dbf SYSTEM /u01/app/oracle/oradata/orcl/example01.dbf EXAMPLE For each tablespace: Put the tablespace into backup mode:

27 Copyright © 2007, Oracle. All rights reserved. 6 - 27 Backing Up the Control File SQL> ALTER DATABASE BACKUP CONTROLFILE TO 2> '/u01/backup/controlfile.bak'; Database altered. Back up the control file: As an image copy, to a specifically named file: By generating a script that re-creates it, in a trace file: SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE; Database altered.

28 Copyright © 2007, Oracle. All rights reserved. 6 - 28 Performing User-Managed Complete Database Recovery: Overview User-managed complete database recovery: Recovers the database to the most recent SCN Can be done with the entire database at once, or a data file or tablespace at a time Requires a current control file Requires backups of all files to be recovered Requires all archive logs up to the present

29 Copyright © 2007, Oracle. All rights reserved. 6 - 29 Performing Complete Closed Database Recovery: Overview Database open? Shutdown. No Yes Query for files to recover. Query for needed archive logs. Restore damaged files and archive logs. Repair hardware. Mount database. Open database. Recover data files. Bring data files online.

30 Copyright © 2007, Oracle. All rights reserved. 6 - 30 Identifying Recovery-Related Files SQL> SELECT file#, error FROM v$recover_file; SQL> SELECT archive_name FROM v$recovery_log; Identify data files that need to be recovered: Identify archive log files that are required to complete recovery:

31 Copyright © 2007, Oracle. All rights reserved. 6 - 31 Restoring Recovery-Related Files Data files Archive logs /disk2/datafile.dbf /disk1/datafile.dbf ONLINE 1 2 3

32 Copyright © 2007, Oracle. All rights reserved. 6 - 32 Restoring Recovery-Related Files Full Notes Page

33 Copyright © 2007, Oracle. All rights reserved. 6 - 33 Applying Redo Data SQL> RECOVER AUTOMATIC FROM '/u01/arch_temp' DATABASE; 1.Apply redo data using the RECOVER command: Apply each redo log without prompting. Alternate location for restored archive log files Could be DATABASE, TABLESPACE, or DATAFILE 2.Open the database: SQL> ALTER DATABASE OPEN;

34 Copyright © 2007, Oracle. All rights reserved. 6 - 34 Performing Complete Open Database Recovery Query for files to recover. Query for needed archive logs. Restore damaged files and archive logs. Diagnose media problem. Recover data files. Bring tablespaces online. Take damaged data files offline. Can bring data files online? Yes No Done

35 Copyright © 2007, Oracle. All rights reserved. 6 - 35 Performing Complete Open Database Recovery Full Notes Page

36 Copyright © 2007, Oracle. All rights reserved. 6 - 36 Performing User-Managed Incomplete Recovery: Overview Recover the database to a past point in time in the following situations: You want the database to be in the state that existed before a user error or an administrative error occurred. The database contains corrupt blocks. You are unable to perform complete database recovery because some of the redo log files are missing. You want to create a test database that is in the state at some time in the past. One or more unarchived redo log files and a data file are lost.

37 Copyright © 2007, Oracle. All rights reserved. 6 - 37 Choosing an Incomplete Recovery Method Indicate when to stop applying redo data by: Specifying a time at which to stop Specifying an SCN at which to stop Issuing a CANCEL command while the recovery is executing Applying redo data SCN = 1200 Time = August 23, 2007 01:00 AM CANCEL Now

38 Copyright © 2007, Oracle. All rights reserved. 6 - 38 Performing User-Managed Incomplete Recovery Recover a database until time: Recover a database until cancel: SQL> RECOVER DATABASE UNTIL CANCEL; SQL> RECOVER DATABASE UNTIL 2 TIME '2005-12-14:12:10:03';

39 Copyright © 2007, Oracle. All rights reserved. 6 - 39 Performing User-Managed Incomplete Recovery Full Notes Page

40 Copyright © 2007, Oracle. All rights reserved. 6 - 40 Performing User-Managed Incomplete Recovery: Steps To perform user-managed incomplete recovery, follow these steps: 1.Shut down the database. 2.Restore data files. 3.Mount the database. 4.Recover the database. 5.Open the database with the RESETLOGS option.

41 Copyright © 2007, Oracle. All rights reserved. 6 - 41 User-Managed Time-Based Recovery: Example This is the scenario: A job ran in error, and its effects have to be undone. This happened 15 minutes ago, and there has been little database activity since then. You decide to perform incomplete recovery to restore the database back to its state as of 15 minutes ago. SQL> SHUTDOWN IMMEDIATE $ cp /BACKUP/* /u01/db01/ORADATA SQL> STARTUP MOUNT SQL> RECOVER DATABASE UNTIL TIME '2005-11-28:11:44:00'; SQL> ALTER DATABASE OPEN RESETLOGS;

42 Copyright © 2007, Oracle. All rights reserved. 6 - 42 User-Managed Time-Based Recovery Steps Full Notes Page

43 Copyright © 2007, Oracle. All rights reserved. 6 - 43 User-Managed Cancel-Based Recovery: Example The scenario is the same as the one for the time-based example, except for these findings: Redo logs are not multiplexed. One of the online redo logs is missing. The missing redo log is not archived. The redo log contained information from 11:34 AM. Twenty-six minutes of data are lost. Users can reenter their data manually.

44 Copyright © 2007, Oracle. All rights reserved. 6 - 44 User-Managed Cancel-Based Recovery: Example Recover the database as follows: Shut down the database. Restore all data files from the most recent backup. You already have a valid backup, so mount the database. Execute RECOVER DATABASE UNTIL CANCEL. Execute ALTER DATABASE OPEN RESETLOGS to open the database.

45 Copyright © 2007, Oracle. All rights reserved. 6 - 45 Recovering a Read-Only Tablespace Special user-managed backup and recovery considerations for a read-only tablespace: You do not have to put it in backup mode in order to make a copy of its data files. You do not have to take the tablespace or data file offline before making a copy of it.

46 Copyright © 2007, Oracle. All rights reserved. 6 - 46 Recovering NOLOGGING Database Objects Redo log SQL> CREATE TABLE sales_copy NOLOGGING; SQL> INSERT /*+ APPEND */ INTO sales_copy 2 SELECT * FROM sales_history;

47 Copyright © 2007, Oracle. All rights reserved. 6 - 47 Recovering from the Loss of All Control File Copies: Overview CurrentBackup Available Restore backup control file, perform complete recovery, OPEN RESETLOGS Unavailable Re-create control file, OPEN RESETLOGS Restore backup control file, perform incomplete recovery, OPEN RESETLOGS Online log status Data file status

48 Copyright © 2007, Oracle. All rights reserved. 6 - 48 Recovering the Control File to the Default Location Repair hardware. Yes Database open? SHUTDOWN ABORT Restore control file. STARTUP MOUNT Start database recovery. Archivelog missing? No Yes Specify online log. Open database using RESETLOGS. No

49 Copyright © 2007, Oracle. All rights reserved. 6 - 49 Summary In this lesson, you should have learned how to: Describe the difference between user-managed and server- managed backup and recovery Manually back up a data file, tablespace, and database Back up and recover a control file Perform user-managed complete database recovery Perform user-managed incomplete database recovery Recover from a lost TEMP file Recover from a lost redo log group

50 Copyright © 2007, Oracle. All rights reserved. 6 - 50 Practice 6 Overview: Performing User-Managed Recovery This practice covers the following topics: Backing up a NOARCHIVELOG database Recovering from lost control files Recovering from the loss of a redo log group


Download ppt "6 Copyright © 2007, Oracle. All rights reserved. Performing User-Managed Backup and Recovery."

Similar presentations


Ads by Google