2021年灾备演练

根据线上数据库的使用类型,Oracle DG测试环境switchover、failover故障自动切换;mysql 基于binlog闪回演练(my2sqlGO);xtrabackup(PXB)备份还原;

Oracle DG switchover演练

1.查看主备同步情况

SYS@LHR11G> alter system switch logfile;

System altered.

SYS@LHR11G> alter system switch logfile;

System altered.

SYS@LHR11G> alter system switch logfile;

SYS@LHR11G> @dg_info

   THREAD#    DEST_ID DEST_NAME        TARGET                   DATABASE_MODE              STATUS         ERROR      RECOVERY_MODE                  DB_UNIQUE_NAME  DESTINATION     GAP_STATUS CURRENT_SEQ# LAST_ARCHIVED APPLIED_SEQ#      APPLIED_SCN
---------- ---------- -------------------- -------------------------------------------- ------------------------------ ------------------ ---------- ---------------------------------------------- --------------- --------------- ---------- ------------ ------------- ------------ ----------------
     1      1 LOG_ARCHIVE_DEST_1   LOCAL PRIMARY                OPEN                   VALID             IDLE                       LHR11G                                                       19        18             0
     1      2 LOG_ARCHIVE_DEST_2   PHYSICAL STANDBY             OPEN_READ-ONLY             VALID             MANAGED REAL TIME APPLY                LHR11GDG        lhr11gdg        NO GAP       19        18       17      1488372

SYS@LHR11G> @dg_status

   THREAD# NAME                                                  SEQUENCE# APPLIED        FIRST_TIME
---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ -------------------
     1 lhr11gdg                                                  6 YES            2020-10-27 17:21:52
     1 lhr11gdg                                                 14 YES            2021-03-17 13:49:59
     1 lhr11gdg                                                 15 YES            2021-03-17 13:50:11
     1 lhr11gdg                                                 16 YES            2021-03-17 13:50:50
     1 lhr11gdg                                                 17 YES            2021-03-17 13:53:12
     1 lhr11gdg                                                 18 NO             2021-03-17 13:53:18
     1 lhr11gdg                                                 23 YES            2020-10-27 17:17:38
     1 lhr11gdg                                                 24 YES            2020-10-27 17:18:23
     1 lhr11gdg                                                 25 YES            2020-10-27 17:18:26

9 rows selected.
SYS@LHR11G> create table lhr.testdg as select * from scott.emp;
Table created.

SYS@LHR11G> select count(*) from lhr.testdg;

  COUNT(*)
----------
    14

备库查看同步信息

SYS@LHR11GDG> @dg_status

   THREAD# NAME                                 SEQUENCE# APPLIED         FIRST_TIME
---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ -------------------
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_2_hshsjt0w_.arc            2 YES            2020-10-27 17:19:16
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_3_hshsmx1b_.arc            3 YES            2020-10-27 17:19:22
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_4_hshso41g_.arc            4 YES            2020-10-27 17:21:01
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_5_hshsoj22_.arc            5 YES            2020-10-27 17:21:40
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_6_hshszkyt_.arc            6 YES            2020-10-27 17:21:52
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2021_03_17/o1_mf_1_11_j5365r1m_.arc          11 YES            2021-03-17 06:58:36
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2021_03_17/o1_mf_1_12_j5365r3c_.arc          12 YES            2021-03-17 13:45:47
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2021_03_17/o1_mf_1_13_j5365r7b_.arc          13 YES            2021-03-17 13:45:50
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2021_03_17/o1_mf_1_14_j5365r7l_.arc          14 YES            2021-03-17 13:49:59
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2021_03_17/o1_mf_1_15_j5365ttz_.arc          15 YES            2021-03-17 13:50:11
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2021_03_17/o1_mf_1_16_j536b8vt_.arc          16 YES            2021-03-17 13:50:50
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2021_03_17/o1_mf_1_17_j536bgsr_.arc          17 YES            2021-03-17 13:53:12
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2021_03_17/o1_mf_1_18_j536bnt3_.arc          18 IN-MEMORY          2021-03-17 13:53:18
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_23_hshsgzxr_.arc          23 YES            2020-10-27 17:17:38
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_24_hshsh294_.arc          24 YES            2020-10-27 17:18:23
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_25_hshsh5gn_.arc          25 YES            2020-10-27 17:18:26
     1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_27/o1_mf_1_26_hshsjq3x_.arc          26 YES            2020-10-27 17:18:29
     1                                 29 YES             2020-10-27 16:56:46
     1                                 30 YES             2020-10-27 16:56:53
     1                                 31 YES             2020-10-27 16:56:55
     1                                 32 YES             2020-10-27 16:56:57
     1                                 33 YES             2020-10-27 16:57:06
     1                                 34 YES             2020-10-27 16:57:24
     1                                 35 YES             2020-10-27 16:58:15

24 rows selected.

SYS@LHR11GDG> select count(*) from lhr.testdg;

  COUNT(*)
----------
    14

2.接下来使用dgmgrl来验证switchover功能。

[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11g
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production

Copyright (c) 2000, 2009, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> show configuration

Configuration - LHR11G

  Protection Mode: MaxPerformance
  Databases:
    LHR11G   - Primary database
    LHR11GDG - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS
#做切换
DGMGRL> switchover to 'LHR11GDG'
Performing switchover NOW, please wait...
Operation requires a connection to instance "LHR11GDG" on database "LHR11GDG"
Connecting to instance "LHR11GDG"...
Connected.
New primary database "LHR11GDG" is opening...
Operation requires startup of instance "LHR11G" on database "LHR11G"
Starting instance "LHR11G"...
ORACLE instance started.
Database mounted.
Database opened.
Switchover succeeded, new primary is "LHR11GDG"
DGMGRL> show configration
show configration
     ^
Syntax error before or at "configration"
DGMGRL> show configuration

Configuration - LHR11G

  Protection Mode: MaxPerformance
  Databases:
    LHR11GDG - Primary database
    LHR11G   - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

切换成功后验证一下主备同步情况,此时的主库已经变成LHR11GDG了

SYS@LHR11GDG> @dg_info

   THREAD#    DEST_ID DEST_NAME        TARGET                   DATABASE_MODE              STATUS         ERROR      RECOVERY_MODE            DB_UNIQUE_NAME  DESTINATION     GAP_STATUS CURRENT_SEQ# LAST_ARCHIVED APPLIED_SEQ#        APPLIED_SCN
---------- ---------- -------------------- -------------------------------------------- ------------------------------ ------------------ ---------- ---------------------------------------------- --------------- --------------- ---------- ------------ ------------- ------------ ----------------
     1      1 LOG_ARCHIVE_DEST_1   LOCAL PRIMARY                OPEN                   VALID                 IDLE                 LHR11GDG                       25        24               0
     1      2 LOG_ARCHIVE_DEST_2   PHYSICAL STANDBY             OPEN_READ-ONLY             VALID                 MANAGED REAL TIME APPLY          LHR11G        lhr11g      NO GAP       25        24       23    1510118

SYS@LHR11GDG> @dg_status

   THREAD# NAME                                                  SEQUENCE# APPLIED        FIRST_TIME
---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ -------------------
     1 lhr11g                                                    3 YES            2020-10-27 17:19:22
     1 lhr11g                                                    4 YES            2020-10-27 17:21:01
     1 lhr11g                                                    5 YES            2020-10-27 17:21:40
     1 lhr11g                                                   20 YES            2021-03-17 14:28:37
     1 lhr11g                                                   21 YES            2021-03-17 14:28:42
     1 lhr11g                                                   22 YES            2021-03-17 14:28:43
     1 lhr11g                                                   23 YES            2021-03-17 14:28:46
     1 lhr11g                                                   24 NO             2021-03-17 14:28:55
     1 lhr11g                                                   26 YES            2020-10-27 17:18:29
     1 LHR11G                                                   28 YES            2020-10-27 16:56:00

10 rows selected.

SYS@LHR11GDG> insert into lhr.testdg select * from lhr.testdg;

14 rows created.

SYS@LHR11GDG> commit;
Commit complete.

此时查看备库有无新增数据

SYS@LHR11G> select count(*) from lhr.testdg;

  COUNT(*)
----------
    28

SYS@LHR11G> @dg_status

   THREAD# NAME                                      SEQUENCE# APPLIED        FIRST_TIME
---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ -------------------
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_3_hshso1qq_.arc          3 YES            2020-10-27 17:19:22
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_4_hshso436_.arc          4 YES            2020-10-27 17:21:01
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_5_hshsoj58_.arc          5 YES            2020-10-27 17:21:40
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_6_hshstwmw_.arc          6 YES            2020-10-27 17:21:52
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2021_03_17/o1_mf_1_20_j538f2yx_.arc            20 YES            2021-03-17 14:28:37
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2021_03_17/o1_mf_1_21_j538f2yc_.arc            21 YES            2021-03-17 14:28:42
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_22_hshsfldb_.arc            22 YES            2020-10-27 17:17:20
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2021_03_17/o1_mf_1_22_j538f329_.arc            22 YES            2021-03-17 14:28:43
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2021_03_17/o1_mf_1_23_j538f80d_.arc            23 YES            2021-03-17 14:28:46
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_23_hshsgzsz_.arc            23 YES            2020-10-27 17:17:38
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2021_03_17/o1_mf_1_24_j538fqc9_.arc            24 IN-MEMORY          2021-03-17 14:28:55
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_24_hshsh25x_.arc            24 YES            2020-10-27 17:18:23
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_25_hshsh5bz_.arc            25 YES            2020-10-27 17:18:26
     1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_27/o1_mf_1_26_hshso1o6_.arc            26 YES            2020-10-27 17:18:29

14 rows selected.

可以看到备库同步正常。
3.接下来验证switchover主库挂了切换到备库承担业务功能,这时当然从备库failover了

[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11g
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production

Copyright (c) 2000, 2009, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> show configuration

Configuration - LHR11G

  Protection Mode: MaxPerformance
  Databases:
    LHR11GDG - Primary database
    LHR11G   - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

DGMGRL> failover to 'LHR11G'
Performing failover NOW, please wait...
Failover succeeded, new primary is "LHR11G"
DGMGRL> show configuration

Configuration - LHR11G

  Protection Mode: MaxPerformance
  Databases:
    LHR11G   - Primary database
    LHR11GDG - Physical standby database (disabled)
      ORA-16661: the standby database needs to be reinstated

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

DGMGRL> show configuration

Configuration - LHR11G

  Protection Mode: MaxPerformance
  Databases:
    LHR11G   - Primary database
    LHR11GDG - Physical standby database (disabled)
      ORA-16661: the standby database needs to be reinstated

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

切换成功后,需要重新reinstate备库,步骤如下,1.备库强制重启到mount状态,2.然后用DGMGRL连接到主库上执行 REINSTATE DATABASE 'LHR11GDG'

#备库上执行
SYS@LHR11GDG> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@LHR11GDG> select status from v$instance;
select status from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 2437
Session ID: 138 Serial number: 15


SYS@LHR11GDG> startup mount
ORACLE instance started.

Total System Global Area  346562560 bytes
Fixed Size          2253144 bytes
Variable Size         192941736 bytes
Database Buffers      146800640 bytes
Redo Buffers            4567040 bytes
Database mounted.
SYS@LHR11GDG> exit

主库上用DGMGRL连接到主库上执行 REINSTATE DATABASE 'LHR11GDG'

DGMGRL> show configuration

Configuration - LHR11G

  Protection Mode: MaxPerformance
  Databases:
    LHR11G   - Primary database
    LHR11GDG - Physical standby database (disabled)
      ORA-16661: the standby database needs to be reinstated

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

DGMGRL> REINSTATE DATABASE 'LHR11GDG'
Reinstating database "LHR11GDG", please wait...
Operation requires shutdown of instance "LHR11GDG" on database "LHR11GDG"
Shutting down instance "LHR11GDG"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "LHR11GDG" on database "LHR11GDG"
Starting instance "LHR11GDG"...
ORACLE instance started.
Database mounted.
Continuing to reinstate database "LHR11GDG" ...
Reinstatement of database "LHR11GDG" succeeded
DGMGRL> show configuration

Configuration - LHR11G

  Protection Mode: MaxPerformance
  Databases:
    LHR11G   - Primary database
    LHR11GDG - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,884评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,755评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,369评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,799评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,910评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,096评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,159评论 3 411
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,917评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,360评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,673评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,814评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,509评论 4 334
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,156评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,882评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,123评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,641评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,728评论 2 351

推荐阅读更多精彩内容