實際工作例子,引用別人的文章介紹,
用自動備份的OCR‘恢復了集羣。
Oracle RAC 中OCR 和Voting Disk 備份在我的blog: Oracle RAC 常用維護工具和命令 中已經有說明,現在再次把它單獨拿出做一個說明, 因爲OCR 和Voting Disk 對於RAC 系統來說太重要了。
Oracle RAC 常用維護工具和命令
http://blog.csdn.net/tianlesoftware/archive/2010/03/09/5358573.aspx
一. Voting Disk
Voting Disk 這個文件主要用於記錄節點成員狀態,在出現腦裂時,決定那個Partion獲得控制權,其他的Partion必須從集羣中剔除。Voting disk使用的是一種“多數可用算法”,如果有多個Voting disk,,則必須一半以上的Votedisk同時使用,Clusterware才能正常使用。 比如配置了4個Votedisk,壞一個Votedisk,集羣可以正常工作,如果壞了2個,則不能滿足半數以上,集羣會立即宕掉,所有節點立即重啓,所以如果添加Votedisk,儘量不要只添加一個,而應該添加2個。這點和OCR 不一樣。OCR 只需配置一個。
查看votedisk的位置:
[root@rac1 ~]# crsctl query css votedisk
0. 0 /dev/raw/raw2
located 1 votedisk(s).
備份votedisk盤:
[root@raw1 bin]# dd if=/dev/raw/raw2 of=/home/oracle/voting_disk.bak
294912+0 records in
294912+0 records out
恢復votedisk盤:
[root@raw1 bin]# dd if=/home/oracle/voting_disk.bak of=/dev/raw/raw2
294912+0 records in
294912+0 records out
通過Strings 命令來查看 voting disk 的內容
[root@raw1 oracle]# strings voting_disk.bak |sort -u
fSLC
ssLckcoT
SslcLlik
sSlcrEp0
}|{z
二 . OCR
Oracle Clusterware把整個集羣的配置信息放在共享存儲上,這些信息包括了集羣節點的列表、集羣數據庫實例到節點的映射以及CRS應用程序資源信息。存放的位置就在OCR Disk上. 在整個集羣中,只有一個節點能對OCR Disk 進行讀寫操作,這個節點叫作Master Node,所有節點都會在內存中保留一份OCR的拷貝,同時有一個OCR Process 從這個內存中讀取內容。 OCR 內容發生改變時,由Master Node的OCR Process負責同步到其他節點的OCR Process。
因爲OCR的內容如此重要,所以Oracle 每4個小時對其做一次備份,並且保留最後的3個備份,以及前一天,前一週的最後一個備份。 這個備份由Master Node CRSD進程完成,備份的默認位置是$CRS_HOME/crs/cdata/<cluster_name>目錄下,可以通過ocrconfig -backuploc <directory_name> 命令修改到新的目錄。每次備份後,備份文件名自動更改,以反應備份時間順序,最近一次的備份叫作backup00.ocr。這些備份文件除了保存在本地,DBA還應該在其他存儲設備上保留一份,以防止意外的存儲故障。
[root@raw1 crs]# pwd
/u01/app/oracle/product/crs/cdata/crs
[root@raw1 crs]# ls -lrt
total 22632
-rw-r--r-- 1 root root 4595712 Mar 9 01:03 backup02.ocr
-rw-r--r-- 1 root root 4620288 Mar 9 21:20 backup01.ocr
-rw-r--r-- 1 root root 4632576 Apr 8 19:46 backup00.ocr
-rw-r--r-- 1 root root 4632576 Apr 8 19:46 day.ocr
-rw-r--r-- 1 root root 4632576 Apr 8 19:46 week.ocr
在安裝clusterware過程中,如果選擇External Redundancy冗餘方式,則只能輸入一個OCR磁盤位置。 但是Oracle允許配置兩個OCR 磁盤互爲鏡像,以防止OCR 磁盤的單點故障。 OCR 磁盤和Votedisk磁盤不一樣,OCR磁盤最多只能有兩個,一個Primary OCR 和一個Mirror OCR。
Oracle 推薦在對集羣做調整時,比如增加,刪除節點之前,修改RAC IP之前,對OCR做一個備份,可以使用export 備份到指定文件,如果做了replace或者restore 等操作,Oracle 建議使用 cluvfy comp ocr -n all 命令來做一次全面的檢查。對OCR的備份與恢復,我們可以使用ocrconfig 命令。
[root@raw1 bin]# ./ocrconfig --help
Name:
ocrconfig - Configuration tool for Oracle Cluster Registry.
Synopsis:
ocrconfig [option]
option:
-export <filename> [-s online]
- Export cluster register contents to a file
-import <filename> - Import cluster registry contents from a file
-upgrade [<user> [<group>]]
- Upgrade cluster registry from previous version
-downgrade [-version <version string>]
- Downgrade cluster registry to the specified version
-backuploc <dirname> - Configure periodic backup location
-showbackup - Show backup information
-restore <filename> - Restore from physical backup
-replace ocr|ocrmirror [<filename>] - Add/replace/remove a OCR device/file
-overwrite - Overwrite OCR configuration on disk
-repair ocr|ocrmirror <filename> - Repair local OCR configuration
-help - Print out this help information
Note:
A log file will be created in
$ORACLE_HOME/log/<hostname>/client/ocrconfig_<pid>.log. Please ensure
you have file creation privileges in the above directory before
running this tool.
1. 用導出導入備份恢復OCR
1) 首先關閉所有節點的CRS
[root@raw1 bin]# ./crsctl stop crs
Stopping resources.
Successfully stopped CRS resources
Stopping CSSD.
Shutting down CSS daemon.
Shutdown request successfully issued.
2) 用root 用戶導出OCR內容
[root@raw1 bin]# ./ocrconfig -export /u01/ocr.exp
3) 重啓CRS
[root@raw1 bin]# ./crsctl start crs
Attempting to start CRS stack
The CRS stack will be started shortly
4) 檢查CRS 狀態
[root@raw1 bin]# ./crsctl check crs
CSS appears healthy
CRS appears healthy
EVM appears healthy
5)破壞OCR內容
[root@raw1 bin]# dd if=/dev/zero of=/dev/raw/raw1 bs=1024 count=102400
102400+0 records in
102400+0 records out
6) 檢查OCR一致性
[root@raw1 bin]# ./ocrcheck
PROT-601: Failed to initialize ocrcheck
7)使用cluvfy 工具檢查一致性
[root@raw1 cluvfy]# ./runcluvfy.sh comp ocr -n all
Verifying OCR integrity
Unable to retrieve nodelist from Oracle clusterware.
Verification cannot proceed.
8) 使用Import 恢復OCR 內容
[root@raw1 bin]# ./ocrconfig -import /u01/ocr.exp
注意: 使用restore選項只能導入OCR自動產生的物理備份,
import選項只能導入通過export選項導出的的邏輯備份。
9)再次檢查OCR
[root@raw1 bin]# ./ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 2
Total space (kbytes) : 147352
Used space (kbytes) : 4364
Available space (kbytes) : 142988
ID : 610419116
Device/File Name : /dev/raw/raw1
Device/File integrity check succeeded
Device/File not configured
Cluster registry integrity check succeeded
10) 使用cluvfy工具檢查
[root@raw1 cluvfy]# ./runcluvfy.sh comp ocr -n all
2. 自動備份恢復OCR
(1)關閉運行在集羣數據庫的所有節點上的CRS服務程序
/etc/init.d/init.crs stop
在Oracle 11gR2 中已經沒有了init.crs 命令了。 只能通過
#crsctl stop crs
命令來關閉CRS.
(2). 通過ocrconfig 的showbackup選項查看最近的備份
[root@racnode1 ~]# ocrconfig -showbackup
racnode1 2010/11/22 13:30:27 /u01/app/11.2.0/grid/cdata/racnode-cluster/backup00.ocr
racnode1 2010/11/22 09:30:27 /u01/app/11.2.0/grid/cdata/racnode-cluster/backup01.ocr
racnode1 2010/11/22 05:30:26 /u01/app/11.2.0/grid/cdata/racnode-cluster/backup02.ocr
racnode1 2010/11/21 05:30:23 /u01/app/11.2.0/grid/cdata/racnode-cluster/day.ocr
racnode1 2010/11/11 03:35:10 /u01/app/11.2.0/grid/cdata/racnode-cluster/week.ocr
(3)通過ocrconfig的restore或import選項導入OCR數據
ocrconfig -restore filename_location
如:
ocrconfig -restore /u01/app/11.2.0/grid/cdata/racnode-cluster/backup00.ocr
注意: 使用restore選項只能導入OCR自動產生的物理備份,
import選項只能導入通過export選項導出的的邏輯備份。
(4) 檢查CRS
[root@raw1 bin]# ./ocrcheck
使用cluvfy工具檢查
[root@raw1 cluvfy]# ./runcluvfy.sh comp ocr -n all
(5)在所有節點上重新啓動CRS
/etc/init.d/init.crs start
在Oracle 11gR2使用:#crsctl start crs 命令來啓動CRS.
小結:
這裏只提到了OCR 和Voting Disk 的備份。 實際上,對於一個數據庫環境來說,要備份的東西還有很多。 只不過OCR這東西涉及RAC 底層的東西,所以在做涉及OCR的變更之前要非常小心。 做操作之前,最好是手工的用ocrconfig -export 把OCR 備份一下。
對於一個數據庫環境,還需要的備份的東西如:spfile,control file,數據文件位置等。 數據文件位置,可用如下命令查看:
elect file_name,tablespace_name from dba_data_files;
select file_name,tablespace_name from dba_temp_files;
有時候在恢復的時候需要這些信息。 我們儘量備份多一點,這樣對恢復就越有利。
以前對DBA的認識:
1. 膽大心細,遇事不慌
2. 制定完善的備份策略,做相關操作之前,也是需要備份。
3. 做變更之前,要先整理出文檔,按照文檔操作。 在好的記憶和經驗也難免有遺漏的時候,照文檔來,一步一步操作。
那天和羣裏 布豆 討論的時候,他說了一條:
風險大的事情不做,變個思路將風險降低到最低點再操作!
布豆在Oracle 上給了我很多指導。 在此對布豆表示感謝。