Saturday, October 26, 2013

Managing Backups and Recovery of the OCR Using OCR Backup Files

Two methods are most popular for copying OCR content and using it for recovery. The first method uses automatically generated OCR file copies and the second method uses manually created OCR export files.

Backing up OCR
For taking OCR backup we can use one of the following methods 
1.Backup from automatically generated OCR copies 
The Oracle Clusterware automatically creates OCR backups every four hours. At any one time, Oracle always retains the last three backup copies of the OCR. The CRSD process that creates the backups also creates and retains an OCR backup for each full day and at the end of each week.

Note:- You cannot customize the backup frequencies or the number of files that oracle retains. You can use any backup software to copy the automatically generated backup files at least once daily to a different device from where the primary OCR resides.

The default location for generating backups on UNIX-based systems is CRS_home/cdata/cluster_name where cluster_name is the name of your cluster. The Windows-based default location for generating backups uses the same path structure.
ocrconfig utility can be used to view the backups generated automatically by Oracle Clusterware.To find the most recent backup of the OCR, On any cluster node run following command
[root@rac2 ~]# ocrconfig -showbackup

rac2     2013/10/19 14:26:26     /app/gridHome/cdata/rac-cluster/backup00.ocr

rac2     2013/10/19 10:26:16     /app/gridHome/cdata/rac-cluster/backup01.ocr

rac2     2013/10/19 06:26:14     /app/gridHome/cdata/rac-cluster/backup02.ocr

rac2     2013/10/18 02:26:02     /app/gridHome/cdata/rac-cluster/day.ocr

rac2     2013/10/17 22:26:00     /app/gridHome/cdata/rac-cluster/week.ocr
PROT-25: Manual backups for the Oracle Cluster Registry are not available

If you are not getting any output , check the same command on other nodes 
To make a backup, use the ocrconfig tool with the showbackup option to identify the backup files, and then copy each file to a location that is redundant to the location of the original OCR backup file. This ensures that there are at least two copies of each OCR backup file.
Note:- You must be logged in as root user to run ocrconfig commands.if ocrconfig command is not working in root user, update the .bash_profile with specific bin path.

2.Manually creating OCR export files 
In addition to using the automatically created OCR backup files, you should also export the OCR contents to a file before and after making significant configuration changes, such as adding or deleting nodes from your environment, modifying Oracle Clusterware resources, or creating a database. Exporting the OCR contents to a file lets you import the OCR if your configuration changes cause errors. For example, if you have unresolvable configuration problems, or if you are unable to restart your cluster database after such changes, then you can restore your configuration by importing the saved OCR content from the valid configuration.
To perform manual backup of OCR:
You can  either use ocrconfig -manualbackup or ocrconfig -export command to force Oracle Clusterware to perform a backup of the OCR at any time, rather than wait for the automatic backup that occurs at 4-hour intervals.
The -manualbackup option is especially useful when you to need to obtain a binary backup on demand, such as before you make changes to the OCR. You need to be logged in as root user to take manual backups
To view the available OCR Manual backup
[root@rac1 ~]#ocrconfig -showbackup manual  
To perform manual backup
[root@rac1 ~]# ocrconfig -manualbackup
[root@rac1 ~]# ocrconfig -showbackup manual
rac1     2013/10/21 16:26:48     /app/gridHome/cdata/rac-cluster/backup_20131021_162648.ocr
You can also use export command along  with ocrconfig  to take the backup of  OCR  
[root@rac1 ~]# ocrconfig -export /backup/ocrbkp.dmp
[root@rac1 ~]# ll /backup/
-rw-r--r-- 1 root root 95055 Oct 26 17:52 ocrbkp.dmp

Recovering the OCR
If an application fails, try to restart the application and if you think the error is related to OCR, run an ocrcheck. It would normally return failure message if there is a issue or corruption in OCR. Then before attempting to restore the OCR, as a definitive verification that the OCR failed on both the primary OCR and the OCR mirror, Attempt to correct the problem using one of the following platform-specific OCR diagnostic procedures. If diagnosis doesn’t help you may have to restore OCR from backup
There are two methods for recovering the OCR. The first method uses automatically generated OCR file copies and the second method uses manually created OCR export files.

1.Restoring the OCR from Automatically Generated OCR Backups
Before you attempt to restore the OCR, ensure that the OCR is unavailable. To check the status of the OCR, Run the following command:
[root@rac1 ~]# ocrcheck
Status of Oracle Cluster Registry is as follows :
         Version                  :          3
         Total space (kbytes)     :     262120
         Used space (kbytes)      :       2696
         Available space (kbytes) :     259424
         ID                       : 1005378644
         Device/File Name         :       +OCR
                                    Device/File integrity check succeeded

                                    Device/File not configured

                                    Device/File not configured

                                    Device/File not configured

                                    Device/File not configured

         Cluster registry integrity check succeeded
         Logical corruption check succeeded
Note:-  Device/File not configured means ocrmirror is not configured
[root@rac1 ~]#
If both the primary OCR and the OCR mirror have failed. You must restore the OCR from a backup.If there is at least one copy of the OCR available, you can use that copy to restore the other copies of the OCR.When restoring the OCR from automatically generated backups, you first have to determine which backup file you will use for the recovery.
Log in as the root user and identify the available OCR backups using the ocrconfig command:
[root@rac1 ~]#ocrconfig -showbackup
Review the contents of the backup using the following ocrdump command, where file_name is the name of the OCR backup file:
[root@rac1 ~]# ocrdump -backupfile file_name
For recovering OCR from automated or manual backup needs all cluster, RAC instances and RAC database bring down before performing recovery of OCR.
[root@rac1 ~]# srvctl stop database -d MYRAC -o immediate
[root@rac1 ~]# srvctl status database -d MYRAC
Instance myrac1 is not running on node rac1
Instance myrac2 is not running on node rac2
[root@rac1 ~]# crsctl stop crs
Repeat this command on each node in your Oracle RAC cluster.
As root user , restore the OCR file using following command
[root@rac1 ~]#ocrconfig -restore file_name
As the root user, restart Oracle Clusterware on all the nodes in your cluster by restarting each node
[root@rac1 ~]# crsctl start crs
[root@rac1 ~]#srvctl start database -d MYRAC
Repeat this command on each node in your Oracle RAC cluster.
Use the Cluster Verification Utility (CVU) to verify the OCR integrity using following command. for that you have to login as grid user
[grid@rac1 ~]$  cluvfy comp ocr -n all 

2.Recovering the OCR from an OCR Export File
To restore the previous configuration stored in the OCR from an OCR export file:
Place the OCR export file that you created previously using the ocrconfig -export command in an accessible directory on disk.Stop Oracle Clusterware and RAC database on all the nodes in your Oracle RAC cluster as root user using following command.
[root@rac1 ~]# srvctl stop database -d MYRAC -o immediate
[root@rac1 ~]# srvctl status database -d MYRAC
Instance myrac1 is not running on node rac1
Instance myrac2 is not running on node rac2
[root@rac1 ~]# crsctl stop crs
Repeat this command on each node in your Oracle RAC cluster.
As root user restore the OCR data by data by importing the contents of the OCR export file
[root@rac1 ~]# ocrconfig -import file_name
Restart Oracle Clusterware on all the nodes in your cluster by restarting each node as root user using following command
[root@rac1 ~]# crsctl start crs
[root@rac1 ~]#srvctl start database -d MYRAC
Repeat this command on each node in your Oracle RAC cluster.
To verify the OCR integrity using Cluster Verification utility using following command.
[grid@rac1 ~]$ cluvfy comp ocr -n all 
 Want to know more about Real Application Cluster Click Oracle Real Application Cluster

Things to remember,
  • Oracle takes physical backup of OCR automatically.
  • No Cluster downtime or RAC database down time requires for PHYSICAL backup of OCR.
  • No Cluster downtime or RAC database down time requires for MANUAL export backup of OCR.
  • For recovery of OCR from any of above backup it should need to down ALL.
  • All procedure requires ROOT login.
  • As of 11gR2  when you backup OCR, it takes backup of voting disk automatically as per Oracle documentation.
  • ocrconfig --manualbackup is introduced in 11g 
  • The -showbackup option now includes auto and manual flags that you can optionally specify to view the auto/manual existing backup information.

No comments:

Post a Comment