* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Backup and Restore
Survey
Document related concepts
Microsoft SQL Server wikipedia , lookup
Functional Database Model wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Ingres (database) wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Concurrency control wikipedia , lookup
Relational model wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Database model wikipedia , lookup
Oracle Database wikipedia , lookup
Transcript
Backup and Restore 2012 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 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 Automatic archival Archive destination Oldest online log sequence Current log sequence No Archive Mode Disabled /data14/oracle_data/orcl/archived_log_1 7185 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. b. c. d. Connect as sysdba. Shut down your database. Start up in mount mode. Alter the database into archivelog mode. Backup and Restore 2012 e. Open your database for use. 1.4 Disabling Archivelog mode If 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 Mode Automatic archival Disabled Archive destination /data14/oracle_data/orcl/archived_log_1 Oldest online log sequence 7185 Current log sequence 7186 d. Execute the following commands in sequence to enable the archivelog mode. SQL>Shutdown immediate; SQL> startup mount; Backup and Restore 2012 ORACLE instance started. Total System Global Area 1.3495E+10 bytes Fixed Size 2218032 bytes Variable Size 7784630224 bytes Database Buffers 5637144576 bytes Redo Buffers 71471104 bytes Database mounted. SQL> alter database archivelog; Database altered. SQL> alter database open; Database altered. e. Verify database mode SQL> archive log list; Database log mode Automatic archival Archive destination Oldest online log sequence Next log sequence to archive Current log sequence Archive Mode Enabled /data14/oracle_data/orcl/archived_log_1 7185 7186 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 invalid ORA-16018: cannot use LOG_ARCHIVE_DEST with LOG_ARCHIVE_DEST_n or DB_RECOVERY_FILE_DEST Backup and Restore 2012 2 Configure RMAN environment for Backups The below table has details of commands that are executed before RMAN backup and restore command. Sr. Command Purpose No. CONFIGURE RETENTION POLICY TO 1. We have disabled the retention policy. NONE; 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; SET DECRYPTION IDENTIFIED BY "test"; 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. Backup and Restore 2012 3 Database Backups There are following types of backup that we create using RMAN. Sr. No. 1. 2. 3. Database Mode Offline Online Online Backup Type Description 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. 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. 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 Full Incremental Level 0 Script full_off_backup.sql full_on_backup.sql incr_on_level_0_backup.sql Backup and Restore 4. 5. Online Online Incremental differential Level 1 Incremental cumulative level 1 2012 applying incremental backups during a recovery operation. 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. A cumulative level 1 backup backs up all blocks that have changed since the last level 0 backup. incr_on_level_1_backup.sql 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 0 b. 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 ; Backup and Restore RMAN incremental backup Backup incremental level 1 database plus archivelog delete input; 2012 Backup and Restore 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'; 2012 Backup and Restore 5 Restore Deleted all files only oracle home is set RMAN prompt =============== RMAN> startup nomount; startup failed: ORA-01078: failure in processing system parameters LRM-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 spfile Oracle instance started Total System Global Area Fixed Size Variable Size Database Buffers Redo Buffers 158662656 bytes 2211448 bytes 92275080 bytes 58720256 bytes 5455872 bytes =============== Identify DBID Start database RMAN> startup nomount; startup failed: ORA-01078: failure in processing system parameters LRM-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 spfile Oracle instance started Total System Global Area Fixed Size Variable Size Database Buffers 158662656 bytes 2211448 bytes 92275080 bytes 58720256 bytes 2012 Backup and Restore Redo Buffers 2012 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 nomount RMAN> startup force pfile=/tmp/initTemp.ora nomount Oracle instance started Total System Global Area 13495463936 bytes Fixed Size Variable Size Database Buffers Redo Buffers 2218032 bytes 7784630224 bytes 5637144576 bytes 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_cfc1290647802-20121025-07' ; } executing command: SET CONTROLFILE AUTOBACKUP FORMAT Starting restore at 25-OCT-12 allocated channel: ORA_DISK_1 Backup and Restore channel ORA_DISK_1: SID=391 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 output file name=/data13/oracle_data/orcl/control_file_1/control01.ctl output file name=/data16/oracle_data/orcl/control_file_2/control02.ctl Finished 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 started database mounted Total System Global Area 13495463936 bytes Fixed Size Variable Size Database Buffers Redo Buffers 2218032 bytes 7784630224 bytes 5637144576 bytes 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 REPORT SCHEMA; 2012 Backup and Restore 2012 6 Appendix 6.1 RMAN Backup Retention Policies A 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 Policy When 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 Policies Archived redo logs can be deleted automatically by the database or as a result of user-initiated RMAN commands. a. Enabling Archive Log Deletion policy The 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. b. Disabling Archive Log deletion policy The following command will enable the archivelog deletion policy. CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; Backup and Restore 2012 6.3 Password Encryption of Backups Password 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.