1. Preface
As a saying goes, "You must know what it is, but you must know what it is ". But I don't know why. Why. This series of articles will show you how to do it and why it will also be involved. However, due to the limited level, the principle is not profound enough. I hope that the readers can understand the concept.
I have read a lot of materials recently and are also thinking about the value that the technology we are pursuing can bring to this society. It's a bit boring to walk on the road of technology, but why?
2. Description of RMAN backup and recovery Control Files
We often say "backup is more important than everything". If there is a problem, it can be recovered from the backup file. This series of articles explains how to back up and restore RMAN. RMAN can be used to back up and restore database files, archive logs and control files. It can also be used to perform full or incomplete database Recovery. RMAN Backup methods include Full Backup, Incremental Backup, Open Backup, Closed Backup, and Consistent Backup) inconsistent Backup ). RMAN recovery has full recovery and Incomplete recovery. Incomplete recovery can be performed based on the time, SCN, log serial number, and backup control file.
The control file records the structure and behavior of the database. For the database, the control file is very important. If the control file is faulty and the parameter file is normal, the database can only start to NOMOUNT. By default, the Oracle 11g control file is stored in the data directory and the other in the flashback directory. There are also multiple control files in the real environment. Generally, three files are recommended.
To back up the RMAN backup and recovery control files, we must first back up the database. The database backup process is as follows: After RMAN issues the backup full database command, RMAN generates the bequeath connection to the target database, that is, it checks the Instance name in the parameter la_sid variable, in addition, a server process is generated on the instance and then logged on as sysdba. Then a backup channel is generated (in fact, it is also a process, and storage is allocated in PGA or SGA ). Then RMAN calls SYS. DBMS_RCVMAN to request the database structure information, including the control file information (current serial number, creation time ......), Because the full backup database is specified, RMAN will request the data file information in the database and determine whether there is an offline data file (including the location and working method ). RMAN starts backup. To maintain data consistency, RMAN must create a snapshot of the control file. Next, RMAN calls the DBMS _ BACKUP_RESTORE data package. This call can create a backup file. RMAN has a file list, so it allocates a memory buffer for data file read operations. After the buffer is allocated, RMAN initializes the backup disk. Once the backup file is initialized, RMAN determines whether the server parameter file is used. If yes, it will be used as a part of the backup and also backup the control file before backing up the data file, and push it to the memory. To implement this function, the channel process performs a pre-read operation on the disk and reads multiple data files into the memory. RMAN checks whether the data block header information is still zero, if the data block has not been used, it will not be written to the output buffer, and the data block will be discarded (this is why RMAN only backs up the used data, is also its advantage ). RMAN also checks whether the data block has an uption operation. When the check is passed, it is written to the output buffer. Once the output buffer is full, it is pushed to the backup file location. When backing up data blocks, the RMAN shadow process obtains the backup status information and sends it to the V $ session_longops view to query the information. When all data blocks in the data file are read into the input buffer and the status is determined, RMAN will end the backup operation by writing the data file to the backup file. After all data files are written to the BACKUP file, RMAN generates the last call to the sys dbms backup restore data packet. This call writes the BACKUP information (including the BACKUP name, the SCN of the checkpoint when the backup operation is started and the time when the backup is completed). This completes the backup!
After the database is backed up, we need to shut down the database consistently because the database is in the running state and writes content to the control file. If it is not closed, the version of the control file is inconsistent. After the database is shut down in consistency mode, we need to simulate the loss of control files. To avoid recovery errors, we do not use the rm command. It is also very dangerous to use this command in the real environment. We use the mv command. Then we start the database to the NOMOUNT state. Why is it NOMOUNT? Because the database starts up in three phases: instance startup, Database loading, database opening, and NOMOUNT, parameter files are used, because our control file is lost, it cannot be read and can only be started to NOMOUNT. Then, RMAN restores the database through the backup control file. Because the control file recovery is complete, the database can be started to the MOUNT state, so we continue to make the database to the MOUNT state, because the Database Control file is recovered through RMAN, we need to restore the database so that the control file takes effect and proofread and synchronize the control file version. Then we use RESETLOGS to open the database. Because the log file is cleared and the previous backup is invalid, we should back up the database again. This is crucial.
We can also use the RUN Command to write all operations into a human script, which can reduce many operations, provided that such a script has undergone rigorous testing.
Control File loss use the run Command
Syntax:
RUN {
Startup mount;
Restore controlfile from '/';
Alter database mount;
Recover database;
Alter database open resetlogs;
}
Example:
RUN {
STARTUPNOMOUNT;
Restorecontrolfile from '/u01/oracle/fast_recovery_area/JUSTDB/backupset/2013_12_11/o1_mf_ncsnf_TAG20131211T164208_9bj9c8rp _. bkp ';
Alterdatabase mount;
RECOVERDATABASE;
Alterdatabase open resetlogs;
}
Of course, this is just a simulation, and the control files are basically not lost in the real environment.
Three Control File loss simulation
Step 1: Back up the database
RMAN> backup database;
Starting backup at 11-DEC-13
Using channel ORA_DISK_1
Channel ORA_DISK_1: starting full datafile backup set
Channel ORA_DISK_1: specifying datafile (s) in backup set
Input datafile file number = 00001 name =/u01/oracle/oradata/justdb/system01.dbf
Input datafile file number = 00002 name =/u01/oracle/oradata/justdb/sysaux01.dbf
Input datafile file number = 00003 name =/u01/oracle/oradata/justdb/undotbs01.dbf
Input datafile file number = 00004 name =/u01/oracle/oradata/justdb/users01.dbf
Channel ORA_DISK_1: starting piece 1 at 11-DEC-13
Channel ORA_DISK_1: finished piece 1 at 11-DEC-13
Piece handle =/u01/oracle/fast_recovery_area/JUSTDB/backupset/2013_12_11/partition _. bkp tag = TAG20131211T162913 comment = NONE
Channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Channel ORA_DISK_1: starting full datafile backup set
Channel ORA_DISK_1: specifying datafile (s) in backup set
Including current control file in backup set
Including current SPFILE in backup set
Channel ORA_DISK_1: starting piece 1 at 11-DEC-13
Channel ORA_DISK_1: finished piece 1 at 11-DEC-13
Piece handle =/u01/oracle/fast_recovery_area/JUSTDB/backupset/2013_12_11/partition _. bkp tag = TAG20131211T162913 comment = NONE
Channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-DEC-13
Step 2: Close the database consistently
RMAN> shutdown immediate;
Database closed
Database dismounted
Oracle instance shut down
Step 3: simulate control file loss
[Oracle @ orcl dbs] $ \ mv/u01/oracle/oradata/justdb/control01.ctl/opt/learn/-v
'/U01/oracle/oradata/justdb/control01.ctl'-> '/opt/learn/control01.ctl'
Removed '/u01/oracle/oradata/justdb/control01.ctl'
[Oracle @ orcl dbs] $ \ mv/u01/oracle/fast_recovery_area/justdb/control02.ctl/opt/learn/-v
'/U01/oracle/fast_recovery_area/justdb/control02.ctl'-> '/opt/learn/control02.ctl'
Removed '/u01/oracle/fast_recovery_area/justdb/control02.ctl'
Step 4: Start the database to the NOMOUNT status
RMAN> startup nomount;
Connected to target database (not started)
Oracle instance started
Total System Global Area 1269366784 bytes
Fixed Size 2227984 bytes
Variable Size 754974960 bytes
Database Buffers 503316480 bytes
Redo Buffers 8847360 bytes
Step 5: Restore the control file
RMAN> restore controlfile from '/u01/oracle/fast_recovery_area/JUSTDB/backupset/2013_12_11/o1_mf_ncsnf_TAG20131211T162913_9bj8m1gt _. bkp ';
Starting restore at 11-DEC-13
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: SID = 19 device type = DISK
Channel ORA_DISK_1: restoring control file
Channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Output file name =/u01/oracle/oradata/justdb/control01.ctl
Output file name =/u01/oracle/fast_recovery_area/justdb/control02.ctl
Finished restore at 11-DEC-13
Step 6: Switch the database to the MOUNT status
RMAN> alter database mount;
Database mounted
Released channel: ORA_DISK_1
Step 7 restore the database
RMAN> recover database;
Starting recover at 11-DEC-13
Starting implicit crosscheck backup at 11-DEC-13
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: SID = 1 device type = DISK
Crosschecked 6 objects
Finished implicit crosscheck backup at 11-DEC-13
Starting implicit crosscheck copy at 11-DEC-13
Using channel ORA_DISK_1
Finished implicit crosscheck copy at 11-DEC-13
Searching for all files in the recovery area
Cataloging files...
Cataloging done
List of Cataloged Files
======================================
File Name:/u01/oracle/fast_recovery_area/JUSTDB/backupset/2013_12_11/o1_mf_ncsnf_TAG20131211T162913_9bj8m1gt _. bkp
Using channel ORA_DISK_1
Starting media recovery
Archived log for thread 1 with sequence 1 is already on disk as file/u01/oracle/oradata/justdb/redo01.log
Archived log file name =/u01/oracle/oradata/justdb/redo01.log thread = 1 sequence = 1
Media recovery complete, elapsed time: 00:00:00
Finished recover at 11-DEC-13
Step 8: Open the database in RESETLOGS Mode
RMAN> alter database open resetlogs;
Alter database open resetlogs;
Database opened
Step 9: view the database status
[Oracle @ orcl ~] $ Sqlplus
[Uniread] Loaded history (97 lines)
SQL * Plus: Release 11.2.0.3.0 Production on Wed Dec 11 16:32:16 2013
Copyright (c) 1982,201 1, Oracle. All rights reserved.
Connected:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0-64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> SELECT open_mode FROM v $ database;
OPEN_MODE
--------------------
READ WRITE
Step 10: Back up the database
RMAN> backup database;
Recommended reading:
RMAN: Configure an archive log deletion policy
Basic Oracle tutorial-copying a database through RMAN
Reference for RMAN backup policy formulation
RMAN backup learning notes
Oracle Database Backup encryption RMAN Encryption