backup and restore - web viewsql> archive log list; database log mode no archive mode. automatic...

21
Backup and Restore 201 2

Upload: lenhan

Post on 30-Jan-2018

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

Page 2: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

Contents

1 Archivelog mode..................................................................................................................................3

1.1 Display Archive information.........................................................................................................3

1.2 Configure Archive Log directory..................................................................................................3

1.3 Enabling Archivelog mode...........................................................................................................3

1.4 Disabling Archivelog mode..........................................................................................................4

1.5 Enable Archivelog mode scenario................................................................................................4

2 Configure RMAN environment for Backups.........................................................................................6

3 Database Backups................................................................................................................................7

4 Display Backup Information...............................................................................................................10

4.1 List backupset............................................................................................................................10

5 Restore..............................................................................................................................................11

6 Appendix............................................................................................................................................14

6.1 RMAN Backup Retention Policies...............................................................................................14

6.2 Archived Redo Log Deletion Policies..........................................................................................14

6.3 Password Encryption of Backups...............................................................................................15

6.4 Consistent and Inconsistent Backups.........................................................................................15

Page 3: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

Page 4: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

1 Archivelog mode

Archivelog mode is the mechanism that allows you to recover all committed transactions. This mode protects your database from disk failure because your transaction information can be restored and recovered from the archived redo log files. Archivelog mode ensures that after every online redo log switch that the contents of the logs are successfully copied to archived redo log files.

Database is required to be in archivelog mode for online backups.

1.1 Display Archive information

SQL> select log_mode from v$database;LOG_MODE--------------------NOARCHIVELOG

SQL> archive log list;

Database log mode No Archive ModeAutomatic archival DisabledArchive destination /data14/oracle_data/orcl/archived_log_1Oldest online log sequence 7185Current log sequence 7186

1.2 Configure Archive Log directory

alter system set DB_RECOVERY_FILE_DEST='' ;

ALTER SYSTEM SET log_archive_dest = '/data14/oracle_data/orcl/archived_log_1' SCOPE=BOTH;

1.3 Enabling Archivelog mode

To place your database in archivelog mode, perform the following steps:

a. Connect as sysdba.

Page 5: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

b. Shut down your database.c. Start up in mount mode.d. Alter the database into archivelog mode.e. Open your database for use.

1.4 Disabling Archivelog modeIf you want to disable archivelog mode, then you would execute all the previous steps, with one change; in step 4, you will need to use the noarchivelog parameter (instead of archivelog mode).

1.5 Enable Archivelog mode scenario

a. Check database mode

SQL> select name, log_mode from v$database;

NAME LOG_MODE--------- ------------ORCL NOARCHIVELOG

b. If database is in no archivelog mode then configure archivelog directory.

alter system set DB_RECOVERY_FILE_DEST='' ;

ALTER SYSTEM SET log_archive_dest = '/data14/oracle_data/orcl/archived_log_1' SCOPE=BOTH;

c. Check the archive destination parameter to confirm the archivelog destination path.

SQL> archive log list;Database log mode No Archive ModeAutomatic archival DisabledArchive destination /data14/oracle_data/orcl/archived_log_1Oldest online log sequence 7185Current log sequence 7186

d. Execute the following commands in sequence to enable the archivelog mode.

Page 6: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

SQL>Shutdown immediate;

SQL> startup mount;ORACLE instance started.

Total System Global Area 1.3495E+10 bytesFixed Size 2218032 bytesVariable Size 7784630224 bytesDatabase Buffers 5637144576 bytesRedo Buffers 71471104 bytesDatabase mounted.

SQL> alter database archivelog;Database altered.

SQL> alter database open;Database altered.

e. Verify database mode

SQL> archive log list;Database log mode Archive ModeAutomatic archival EnabledArchive destination /data14/oracle_data/orcl/archived_log_1Oldest online log sequence 7185Next log sequence to archive 7186Current log sequence 7186

SQL> select name, log_mode from v$database;

NAME LOG_MODE--------- ------------ORCL ARCHIVELOG

f. In case if the following error occurs during configuration of archivelog directory then execute the following command “alter system set DB_RECOVERY_FILE_DEST='' ;”

SQL> ALTER SYSTEM SET log_archive_dest = "location=/data14/oracle_data/orcl/archived_log_1" SCOPE=BOTH*ERROR at line 1:ORA-02097: parameter cannot be modified because specified value is invalidORA-16018: cannot use LOG_ARCHIVE_DEST with LOG_ARCHIVE_DEST_n or

Page 7: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

DB_RECOVERY_FILE_DEST

2 Configure RMAN environment for Backups

The below table has details of commands that are executed before RMAN backup and restore command.Sr. No.

Command Purpose

1. CONFIGURE RETENTION POLICY TO NONE;

We have disabled the retention policy.Please refer section#5.1 for more details.

2. CONFIGURE ARCHIVELOG DELETION POLICY BACKED UP 2 TIMES TO DEVICE TYPE DISK;

We have kept two backups of archivelog files.Please refer section#5.1 for more details.

3. CONFIGURE CONTROLFILE AUTOBACKUP ON;

Configure RMAN to back up the control file after each backup

4. CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'e:\rman_backup\cf%F';

Locating for storing control file backup with unique filename.By default, the format of the autobackup file for all configured devices is the substitution variable %F. This variable format translates into c-IIIIIIIIII-YYYYMMDD-QQ, where:

IIIIIIIIII stands for the DBID. YYYYMMDD is a time stamp of the

day the backup is generated QQ is the hex sequence that starts

with 00 and has a maximum of FF

5. SET ENCRYPTION ON IDENTIFIED BY "test" ONLY;

This command will encrypt the database backup by using default encryption algorithm 128-bit Advanced Encryption Standard (AES).The backup will be password protected and to restore the backup we need to use the step mentioned in point#6 of this table.

6. SET DECRYPTION IDENTIFIED BY "test";

Page 8: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

3 Database Backups

There are following types of backup that we create using RMAN.

Sr. No.

Database Mode

Backup Type Description Script

1. Offline Full An offline full backup of a database will contain complete backups of all the datafiles, also called a cold backup, is one made after shutting down the database using the shutdown command or the shutdown command with the immediate or transactional clause. An offline backup, provided you make one after the database is shut down gracefully, is always consistent, whether you're operating in archivelog or noarchivelog mode. When making an offline backup with RMAN, you must, however, start the database you want to back up in the mount mode.

2. Online Full An online full backup of a database will contain complete backups of all the datafiles. The online backup is made while the database instance is still open. By definition, an online backup is always inconsistent. During a recovery, the application of the necessary archived redo logs will make the backup consistent. Thus, you can make online backups of any database you're operating, and the resulting inconsistent backups can be made consistent with the application of archived redo logs. However, for databases running in noarchivelog mode, open inconsistent backups aren't recommended.

3. Online Incremental Level 0

This backup is same as online full backup. The difference between a full backup and a level backup is that a full backup is not known to any subsequent incremental backups. Therefore, they cannot be used as a basis when

Page 9: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

applying incremental backups during a recovery operation.

4. Online Incremental differential Level 1

Backs up only blocks that have been modified since the previous backup. A differential level 1 backup backs up all blocks that have been modified since the last level 0 or level 1 backup.

5. Online Incremental cumulative level 1

A cumulative level 1 backup backs up all blocks that have changed since the last level 0 backup.

We will be configuring Incremental level 0 and incremental differential level 1 backup. The order of the backup would be as follows:

a. Incremental level 0b. Multiple level 1 backups (as per schedule)

Example: In a week there can be one level 0 and multiple level 1 backups.

Backup incremental level 0 database plus archivelog delete input;

select a.set_count, a.start_time, a.completion_time, sum(b.blocks)

from v$backup_set a, v$backup_datafile b

where a.set_count=b.set_count

and to_char(a.start_time, 'mm/dd/yyyy hh24:mi:ss')=

(select to_char(max(start_time), 'mm/dd/yyyy hh24:mi:ss')

from v$backup_set

where incremental_level=1)

group by a.set_count, a.start_time, a.completion_time ;

Page 10: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

RMAN incremental backup

Backup incremental level 1 database plus archivelog delete input;

Page 11: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

4 Display Backup Information

4.1 List backupset

Crosscheck backup;

run {

}

Crosscheck archivelog all;

DELETE EXPIRED ARCHIVELOG all;

delete backup tag='INC_DAILY_DB_BACKUP';

Page 12: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

5 Restore

Deleted all files only oracle home is set

RMAN prompt

===============RMAN> startup nomount;

startup failed: ORA-01078: failure in processing system parametersLRM-00109: could not open parameter file '/data2/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora'

starting Oracle instance without parameter file for retrieval of spfileOracle instance started

Total System Global Area 158662656 bytes

Fixed Size 2211448 bytesVariable Size 92275080 bytesDatabase Buffers 58720256 bytesRedo Buffers 5455872 bytes

===============

Identify DBID

Start database

RMAN> startup nomount;

startup failed: ORA-01078: failure in processing system parametersLRM-00109: could not open parameter file '/data2/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora'

starting Oracle instance without parameter file for retrieval of spfileOracle instance started

Total System Global Area 158662656 bytes

Page 13: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

Fixed Size 2211448 bytesVariable Size 92275080 bytesDatabase Buffers 58720256 bytesRedo Buffers 5455872 bytes

Restore spfile SET DECRYPTION IDENTIFIED BY "test";

RESTORE SPFILE TO '/tmp/spfileTEMP.ora' FROM '/data15/oracle_data/orcl/rman_backup/FULL_DB_cfc-1290647802-20121025-08' ;

Create pfile

Create /tmp/initTemp.ora file with following contents

Spfile = /tmp/spfileTEMP.ora

RMAN> startup force pfile=/tmp/initTemp.ora nomountRMAN> startup force pfile=/tmp/initTemp.ora nomount

Oracle instance started

Total System Global Area 13495463936 bytes

Fixed Size 2218032 bytesVariable Size 7784630224 bytesDatabase Buffers 5637144576 bytesRedo Buffers 71471104 bytes

Restore control file

SET DECRYPTION IDENTIFIED BY "test";

SET DBID 1290647802;RUN{ SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/data15/oracle_data/orcl/rman_backup/FULL_DB_cf%F';

RESTORE CONTROLFILE FROM '/data15/oracle_data/orcl/rman_backup/FULL_DB_cfc-1290647802-20121025-07' ;}

Page 14: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

executing command: SET CONTROLFILE AUTOBACKUP FORMAT

Starting restore at 25-OCT-12allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=391 device type=DISK

channel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/data13/oracle_data/orcl/control_file_1/control01.ctloutput file name=/data16/oracle_data/orcl/control_file_2/control02.ctlFinished restore at 25-OCT-12

Restore database

RMAN> Shutdown immediate;

RMAN> Startup pfile=/tmp/initTemp.ora mount;

connected to target database (not started)Oracle instance starteddatabase mounted

Total System Global Area 13495463936 bytes

Fixed Size 2218032 bytesVariable Size 7784630224 bytesDatabase Buffers 5637144576 bytesRedo Buffers 71471104 bytes

Errors

ORA-01113: file 1 needs media recovery

ORA-19914: unable to encrypt backup

ORA-28365: wallet is not open

SQL>RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL

Page 15: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

REPORT SCHEMA;

6 Appendix

6.1 RMAN Backup Retention PoliciesA user-defined policy for determining how long backups and archived logs need to be retained for media recovery. There are following types of retention policies.

a. Recovery window The RECOVERY WINDOW parameter of the CONFIGURE command specifies the number of days between the current time and the earliest point of recoverability. RMAN does not consider any full or level 0 incremental backup as obsolete if it falls within the recovery window. Additionally, RMAN retains all archived logs and level 1 incremental backups that are needed to recover to a random point within the window.

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

b. Redundancy The REDUNDANCY parameter of the CONFIGURE RETENTION POLICY command specifies how many full or level 0 backups of each datafile and control file that RMAN should keep.

CONFIGURE RETENTION POLICY TO REDUNDANCY 3;

c. Disabling the Retention PolicyWhen you disable the retention policy, RMAN does not consider any backup as obsolete. To disable the retention policy, run this command:

CONFIGURE RETENTION POLICY TO NONE;

6.2 Archived Redo Log Deletion PoliciesArchived redo logs can be deleted automatically by the database or as a result of user-initiated RMAN commands.

a. Enabling Archive Log Deletion policyThe following command will enable the archivelog deletion policy.

CONFIGURE ARCHIVELOG DELETION POLICY BACKED UP integer TIMES TO DEVICE TYPE DISK

If integer backups of the logs exist, then the BACKUP ARCHIVELOG command skips the logs.

Page 16: Backup and Restore - Web viewSQL> archive log list; Database log mode No Archive Mode. Automatic archival Disabled. Archive destination /data14/oracle_data/orcl/ archived_log_1. Oldest

Backup and Restore 2012

b. Disabling Archive Log deletion policyThe following command will enable the archivelog deletion policy.

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;

6.3 Password Encryption of BackupsPassword encryption requires that the DBA provide a password when creating and restoring encrypted backups. Restoring a password-encrypted backup requires the same password used to create the backup.Password encryption is useful for backups that will be restored at remote locations, but which must remain secure in transit. Password encryption cannot be persistently configured. You do not need to configure an Oracle wallet if password encryption will be used exclusively.

Caution:If you forget or lose the password that you used to encrypt a password-encrypted backup, then you will be unable to restore the backup.

To use password encryption, use the SET ENCRYPTION ON IDENTIFIED BY password ONLY command in your RMAN scripts.

6.4 Consistent and Inconsistent Backups

To understand the crucial difference between consistent and inconsistent backups, you must first understand the concept of the system change number (SCN). The SCN is an Oracle server-assigned number that indicates a committed version of the database. It's quite possible that different datafiles in the database might have a different SCN at any given point in time. If the SCNs across all the datafiles are synchronized, it means that the data across the datafiles comes from a single point of time and, thus, is consistent.

During each checkpoint, the server makes all database file SCNs consistent with respect to an identical SCN. In addition, it updates the control file with that SCN information. This synchronization of the SCNs gives you a consistent backup of your database. Not only does each of the datafiles in the database have the same SCN, it must also not contain any database changes beyond that common SCN.

If you back up your database while it's running, you may end up with backups of the various datafiles at various time points and different SCNs. This means your backups are inconsistent, since the SCNs aren't identical across all the datafiles.