Oracle-12c如何从ASM备份里面恢复OCR

前言:

Oracle12c之后恢复OCR相比较之前版本有所不同,一是OCR的默认备份路径被配置在ASM磁盘组里面,这可能会导致在恢复OCR的时候无法正常获取OCR备份,因为如果备份是存放在ASM磁盘组里面,而OCR无法正常启动,这种情况下是无法通过ASM实例正常获取里面的备份的,对于出现的这种情况我们只能通过amdu工具去抽取磁盘进行获取,二是asm的密码文件存放在了OCR里面,在恢复完OCR之后,还需要重建asm密码文件。本文接下来将讲述在Oracle12c之后如何从ASM OCR备份里面恢复OCR。

OCR备份路径:

在Oracle12.2之后,OCR的默认备份路径会被配置在ASM磁盘组里面,我们可以通过ocrconfig工具去查看存放路径

如果开启了mgmt,则备份会被配置在mgmt的磁盘组里面

[grid@rac1 ~]$ ocrconfig -showbackup
rac1     2022/11/08 15:53:12     +MGMT:/rac-cluster/OCRBACKUP/backup00.ocr.275.1120233187     0
rac1     2022/11/06 21:58:04     +MGMT:/rac-cluster/OCRBACKUP/backup01.ocr.274.1120082281     0
rac1     2018/07/26 15:01:55     +MGMT:/rac-cluster/OCRBACKUP/backup02.ocr.273.982508415     0
rac1     2022/11/08 15:53:12     +MGMT:/rac-cluster/OCRBACKUP/day.ocr.271.1120233193     0 

如果没有开启mgmt,则备份默认会被配置在ocr的磁盘组里面

[grid@rac1 ~]$ ocrconfig -showbackup
rac2     2022/11/23 22:04:21     +ocr:/rac-cluster/OCRBACKUP/backup_20221123_220421.ocr.261.1121551461     0     
rac2     2022/11/23 22:04:16     +ocr:/rac-cluster/OCRBACKUP/backup_20221123_220416.ocr.260.1121551457     0     
rac2     2022/11/23 22:04:10     +ocr:/rac-cluster/OCRBACKUP/backup_20221123_220410.ocr.259.1121551451     0     
rac2     2022/11/23 22:04:01     +ocr:/rac-cluster/OCRBACKUP/backup_20221123_220401.ocr.258.1121551441     0     
rac2     2022/11/23 22:03:55     +ocr:/rac-cluster/OCRBACKUP/backup_20221123_220355.ocr.257.1121551437     0

测试(Oracle RAC集群12.2.0.1版本):

我们模拟ocr磁盘组3块磁盘坏了两块,并且备份是配置在ASM磁盘组里面,测试如何从ASM磁盘组备份里面恢复ocr

022-11-23 22:14:44.423 [OCSSD(16516)]CRS-1637: Unable to locate configured voting file with ID 2b2a3556-837f4f9c-bfa551bf-cf863883; details at (:CSSNM00020:) in /oracle/app/grid_base/diag/crs/rac1/crs/trace/ocssd.trc
2022-11-23 22:14:44.423 [OCSSD(16516)]CRS-1637: Unable to locate configured voting file with ID 8e09b740-5cc94f33-bfdf6d53-ac0af4d8; details at (:CSSNM00020:) in /oracle/app/grid_base/diag/crs/rac1/crs/trace/ocssd.trc
2022-11-23 22:14:44.423 [OCSSD(16516)]CRS-1705: Found 1 configured voting files but 2 voting files are required, terminating to ensure data integrity; details at (:CSSNM00021:) in /oracle/app/grid_base/diag/crs/rac1/crs/trace/ocssd.trc

首先,我们先将两个节点的集群强制关闭

/oracle/app/grid_home/bin/crsctl stop crs -f

备份ocr磁盘

dd if=/dev/mapper/ocr1 of=/tmp/backup_ocr1
10485760+0 records in
10485760+0 records out
5368709120 bytes (5.4 GB) copied, 61.7933 s, 86.9 MB/s

接下来,将集群节点一启动为独占模式,跳过ocr

/oracle/app/grid_home/bin/crsctl start crs -excl -nocrs
​
[grid@rac1 ~]$ crsctl stat res -init -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.asm
      1        ONLINE  ONLINE       rac1                     Started,STABLE
ora.cluster_interconnect.haip
      1        ONLINE  ONLINE       rac1                     STABLE
ora.crf
      1        OFFLINE OFFLINE                               STABLE
ora.crsd
      1        OFFLINE OFFLINE                               STABLE
ora.cssd
      1        ONLINE  ONLINE       rac1                     STABLE
ora.cssdmonitor
      1        ONLINE  ONLINE       rac1                     STABLE
ora.ctssd
      1        ONLINE  ONLINE       rac1                     OBSERVER,STABLE
ora.diskmon
      1        OFFLINE OFFLINE                               STABLE
ora.drivers.acfs
      1        ONLINE  ONLINE       rac1                     STABLE
ora.evmd
      1        ONLINE  INTERMEDIATE rac1                     STABLE
ora.gipcd
      1        ONLINE  ONLINE       rac1                     STABLE
ora.gpnpd
      1        ONLINE  ONLINE       rac1                     STABLE
ora.mdnsd
      1        ONLINE  ONLINE       rac1                     STABLE
ora.storage
      1        OFFLINE OFFLINE                               STABLE

接下来,我们通过amdu工具从asm磁盘里面抽取备份的信息,抽取的磁盘需要操作系统可以访问,并且磁盘组状态正常

注:amdu是Oracle自带的工具,可以通过amdu从磁盘里面抽取asm文件,ocr备份所在磁盘需要完整,并且在操作系统层面可以访问,如果asm磁盘已经完全损坏,操作系统层面没办法访问,那也无法通过amdu进行抽取

#$/bin/amdu -diskstring '' -extract 
---我们需要获取备份的磁盘组名称,磁盘路径以及备份片的文件号
---对于备份片的文件号,我们可以可以ocrconfig -showbackup进行获取,备份片的信息是存放在本地的OLR里面
---可以发现当前的备份片是放置在mgmt里面
[root@rac1 ~]# /oracle/app/grid_home/bin/ocrconfig -showbackup
PROT-26: Oracle Cluster Registry backup locations were retrieved from a local copy
rac1     2022/11/08 15:53:12     +MGMT:/rac-cluster/OCRBACKUP/backup00.ocr.275.1120233187     0
rac1     2022/11/06 21:58:04     +MGMT:/rac-cluster/OCRBACKUP/backup01.ocr.274.1120082281     0
rac1     2018/07/26 15:01:55     +MGMT:/rac-cluster/OCRBACKUP/backup02.ocr.273.982508415     0
rac1     2022/11/08 15:53:12     +MGMT:/rac-cluster/OCRBACKUP/day.ocr.271.1120233193     0
rac1     2022/11/06 21:58:04     +MGMT:/rac-cluster/OCRBACKUP/week.ocr.272.1120082287     0
PROT-25: Manual backups for the Oracle Cluster Registry are not available
---使用amdu抽取备份文件275
---使用grid用户
/oracle/app/grid_home/bin/amdu -diskstring '/dev/mapper/mgmt[1-3]' -extract mgmt.275
amdu_2022_11_24_16_26_51/
---会在目录amdu_2022_11_24_16_26_51下生成文件MGMT_275.f
[grid@rac1 ~]$ ls -l /home/grid/amdu_2022_11_24_16_26_51/
total 2060
-rw-r--r-- 1 grid oinstall 2105344 Nov 24 16:26 MGMT_275.f
-rw-r--r-- 1 grid oinstall    3867 Nov 24 16:26 report.txt
[grid@rac1 ~]$ 

如果备份是配置在ASM磁盘组OCR里面,并且OCR磁盘组损坏,那将无法通过amdu进行抽取,所以,最好将备份路径配置在非OCR磁盘组里面或者定期将备份进行转移

---通过ocrconfig配置新的备份路径
/oracle/app/grid_home/bin/ocrconfig -backuploc +DATA
---通过ocrconfig转移备份
/oracle/app/grid_home/bin/ocrconfig -copy +ocr:/rac-cluster/OCRBACKUP/backup_20221123_220355.ocr.257.1121551437 /tmp/backup_20221123_220355.ocr.257.1121551437

重建OCR磁盘组,使用3块新的磁盘/dev/mapper/nocr1-3,3块盘的大小要保持跟原来的磁盘大小一致

---重建ocr磁盘组
create diskgroup OCR NORMAL redundancy disk '/dev/mapper/nocr1','/dev/mapper/nocr2','/dev/mapper/nocr3'  attribute 'COMPATIBLE.ASM' = '12.2';
---如果创建提示磁盘组已经存在,有可能是ocr的原来磁盘被扫到,可以备份之后进行dd磁盘头清空ocr磁盘组的信息,或者直接服用原来ocr的磁盘进行创建
ORA-15018: diskgroup cannot be created
ORA-15030: diskgroup name "OCR" is in use by another diskgroup

从amdu抽取的备份里面恢复ocr

su - root
/oracle/app/grid_home/bin/ocrconfig -restore /home/grid/amdu_2022_11_24_16_26_51/MGMT_275.f

恢复完成之后,重启集群

/oracle/app/grid_home/bin/crsctl stop crs -f 
/oracle/app/grid_home/bin/crsctl start crs -excl -nocrs

恢复投票盘

---设置asm_diskstring
sqlplus / as sysasm
alter system set asm_diskstring='/dev/mapper/*';  
---确认没有表决盘0
/oracle/app/grid_home/bin/crsctl query css votedisk
Located 0 voting disk(s).
---替换投票盘
su - grid
/oracle/app/grid_home/bin/crsctl replace votedisk +OCR
[grid@rac1 ~]$ /oracle/app/grid_home/bin/crsctl replace votedisk +OCR
Successful addition of voting disk a5238bc26b944f2fbf7482d6b604906a.
Successful addition of voting disk deaf2115bd334f0bbf1a2aae20c2a410.
Successful addition of voting disk 016398a196fd4f3bbf4176a1ed84100a.
Successfully replaced voting disk group with +OCR.
CRS-4266: Voting file(s) successfully replaced
---确认替换成功
[grid@rac1 ~]$ crsctl query css votedisk
##  STATE    File Universal Id                File Name Disk group
--  -----    -----------------                --------- ---------
 1. ONLINE   a5238bc26b944f2fbf7482d6b604906a (/dev/mapper/nocr1) [OCR]
 2. ONLINE   deaf2115bd334f0bbf1a2aae20c2a410 (/dev/mapper/nocr2) [OCR]
 3. ONLINE   016398a196fd4f3bbf4176a1ed84100a (/dev/mapper/nocr3) [OCR]
Located 3 voting disk(s).

恢复asm参数文件

---在本地创建临时参数文件
vi /tmp/pfile.ora 
​
*.asm_diskstring='/dev/mapper/*'
*.asm_power_limit=1
*.diagnostic_dest='/oracle/app/grid_base'
*.instance_type='asm'
*.large_pool_size=12M
*.remote_login_passwordfile='EXCLUSIVE'
---恢复到ocr磁盘组里面
SQL> create spfile='+OCR' from pfile='/tmp/pfile.ora';
---新的ASM spfile路径会自动更新到gnpnp profile里面
2022-11-24T17:11:48.656741+08:00
NOTE: updated gpnp profile ASM SPFILE to +OCR/rac-cluster/ASMPARAMETERFILE/registry.253.1121620307

恢复密码文件

---12c之后asm的密码文件配置在ocr磁盘组里面,因此需要进行重建,否则集群会出现报错
2022-11-24 10:20:46.462 : USRTHRD:3288332032: {0:9:3} ORA-01017: invalid username/password; logon denied
ORA-17503: ksfdopn:2 Failed to open file +OCR/orapwasm
ORA-15173: entry 'orapwasm' does not exist in director
---查看当前asm没有配置密码文件,没有用户信息
[grid@rac1 trace]$ asmcmd lspwusr
Username sysdba sysoper sysasm 
---创建密码文件,配置sys,asmsnmp用户密码
[grid@rac1 trace]$ asmcmd pwcreate --asm +OCR/orapwasm 'OraE123tesT!K#xK0+' -f
[grid@rac1 trace]$ asmcmd lspwusr
Username sysdba sysoper sysasm 
     SYS   TRUE    TRUE  FALSE 
[grid@rac1 trace]$ asmcmd orapwusr --grant sysasm SYS
[grid@rac1 trace]$ asmcmd orapwusr --add ASMSNMP
Enter password: ******************   ---->输入asmsnmp密码
[grid@rac1 trace]$ asmcmd lspwusr
Username sysdba sysoper sysasm 
     SYS   TRUE    TRUE   TRUE 
 ASMSNMP  FALSE   FALSE  FALSE

密码文件添加crsd连接用户密码

#查找crsd连接用户以及密码
---dump一下OCR的文件路径
$ORACLE_HOME/bin/ocrdump /tmp/ocr.dmp
​
[grid@rac1 ~]$ $ORACLE_HOME/bin/ocrdump /tmp/ocr.dmp
PROT-310: Not all keys were dumped due to permissions.
---通过/tmp/ocr.dmp查找CRSUSER__ASM_001用户的ORATEXT 
[SYSTEM.ASM.CREDENTIALS.USERS.CRSUSER__ASM_001]
ORATEXT : 294946121edd6f83ff121dfbb48b55d5:grid
SECURITY : {USER_PERMISSION : PROCR_ALL_ACCESS, GROUP_PERMISSION : PROCR_READ, OTHER_PERMISSION : PROCR_NONE, USER_NAME : grid, GROUP_NAME : oinstall}
---验证294946121edd6f83ff121dfbb48b55d5的认证是否是CRSUSER__ASM_001
[grid@rac1 ~]$ crsctl get credmaint -path /ASM/Self/294946121edd6f83ff121dfbb48b55d5 -credtype userpass -id 0 -attr user -local
CRSUSER__ASM_001
---获取CRSUSER__ASM_001密码
[grid@rac1 ~]$ crsctl get credmaint -path /ASM/Self/294946121edd6f83ff121dfbb48b55d5 -credtype userpass -id 0 -attr passwd -local
nabLiBJhDF8dUxq0mltnf34tYKc4b
---创建crsd用户密码
[grid@rac1 trace]$ asmcmd orapwusr --add CRSUSER__ASM_001
Enter password: ***************************** 密码输入上面查到的nabLiBJhDF8dUxq0mltnf34tYKc4b
[grid@rac1 trace]$ 
---添加sysdba,sysasm组
ASMCMD> lspwusr
        Username sysdba sysoper sysasm 
             SYS   TRUE    TRUE   TRUE 
         ASMSNMP   TRUE   FALSE  FALSE 
CRSUSER__ASM_001  FALSE   FALSE  FALSE 
ASMCMD> orapwusr --grant sysdba CRSUSER__ASM_001
ASMCMD> orapwusr --grant sysasm CRSUSER__ASM_001
ASMCMD> lspwusr
        Username sysdba sysoper sysasm 
             SYS   TRUE    TRUE   TRUE 
         ASMSNMP   TRUE   FALSE  FALSE 
CRSUSER__ASM_001   TRUE   FALSE   TRUE 
ASMCMD>

完成全部恢复工作,关闭重新启动集群

/oracle/app/grid_home/bin/crsctl stop crs -f 
/oracle/app/grid_home/bin/crsctl start crs

集群恢复正常

[grid@rac1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ARCH.dg
               ONLINE  ONLINE       rac1                     STABLE
               ONLINE  ONLINE       rac2                     STABLE
ora.ASMNET1LSNR_ASM.lsnr
               ONLINE  ONLINE       rac1                     STABLE
               ONLINE  ONLINE       rac2                     STABLE
ora.DATA.dg
               ONLINE  OFFLINE      rac1                     STABLE
               ONLINE  OFFLINE      rac2                     STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       rac1                     STABLE
               ONLINE  ONLINE       rac2                     STABLE
ora.MGMT.dg
               ONLINE  ONLINE       rac1                     STABLE
               ONLINE  ONLINE       rac2                     STABLE
ora.OCR.dg
               ONLINE  ONLINE       rac1                     STABLE
               ONLINE  ONLINE       rac2                     STABLE
ora.net1.network
               ONLINE  ONLINE       rac1                     STABLE
               ONLINE  ONLINE       rac2                     STABLE
ora.ons
               ONLINE  ONLINE       rac1                     STABLE
               ONLINE  ONLINE       rac2                     STABLE
ora.proxy_advm
               OFFLINE OFFLINE      rac1                     STABLE
               OFFLINE OFFLINE      rac2                     STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       rac2                     STABLE
ora.MGMTLSNR
      1        ONLINE  ONLINE       rac2                     169.254.19.199 192.1
                                                             68.2.20,STABLE
ora.asm
      1        ONLINE  ONLINE       rac1                     Started,STABLE
      2        ONLINE  ONLINE       rac2                     Started,STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.cvu
      1        ONLINE  ONLINE       rac2                     STABLE
ora.mgmtdb
      1        ONLINE  ONLINE       rac2                     Open,STABLE
ora.orcl.db
      1        OFFLINE OFFLINE                               STABLE
      2        OFFLINE OFFLINE                               STABLE
ora.qosmserver
      1        ONLINE  ONLINE       rac2                     STABLE
ora.rac1.vip
      1        ONLINE  ONLINE       rac1                     STABLE
ora.rac2.vip
      1        ONLINE  ONLINE       rac2                     STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       rac2                     STABLE
--------------------------------------------------------------------------------

总结:

恢复的过程相比之前11G版本更加的复杂,特别是在恢复备份以及ASM密码文件上面,所以要定期将OCR以及ASM密码文件进行异地备份,尽量不要跟OCR磁盘组存放在一起,因为通常遇到的OCR备份恢复都是OCR磁盘组出现损坏的情况,这时候往往也会导致OCR备份以及ASM密码文件的丢失。

OCR备份:

---通过ocrconfig配置新的备份路径
/oracle/app/grid_home/bin/ocrconfig -backuploc +DATA
---手动进行备份
/oracle/app/grid_home/bin/ocrconfig -showbackup
---通过ocrconfig转移备份到列的路径
/oracle/app/grid_home/bin/ocrconfig -copy +ocr:/rac-cluster/OCRBACKUP/backup_20221123_220355.ocr.257.1121551437 /tmp/backup_20221123_220355.ocr.257.1121551437

ASM密码文件备份与恢复:

---备份密码文件
​
ASMCMD> pwget --asm
+DGP_01/ASM/PASSWORD/pwdasm.256.844043619
ASMCMD> ls +DGP_01/ASM/PASSWORD/pwdasm.256.844043619
pwdasm.256.844043619
ASMCMD> pwcopy --asm +DGP_01/ASM/PASSWORD/pwdasm.256.844043619
+DGP_02/pwdasm_bk
copying +DGP_01/ASM/PASSWORD/pwdasm.256.844043619 -> +DGP_02/pwdasm_bk
ASMCMD> pwget --asm
+DGP_02/pwdasm_bk
ASMCMD> pwset --asm +DGP_01/ASM/PASSWORD/pwdasm.256.844043619
ASMCMD> pwget --asm
+DGP_01/ASM/PASSWORD/pwdasm.256.844043619
​
---恢复密码文件 
ASMCMD> pwcopy --asm +DGP_02/pwdasm_bk +DGP_03/pwdasm03
ASMCMD> pwget --asm
+DGP_03/pwdasm03
ASMCMD> ls +DGP_03/pwdasm03
pwdasm03 

你可能感兴趣的:(Oracle,oracle,数据库,dba,运维)