文章
· 九月 17, 2022 阅读大约需 10 分钟

IRIS镜像配置(3)

把数据库添加进Mirror

以往的经验里, 用户在把数据库添加到镜像时遇到过各种各样的问题,以致必须请求外部帮助才能解决。除了步骤本身比较繁琐,很大的原因是阅读文档不细致。还有一个,就是对英文水平不太高的用户,有些英文句式并不是很好懂,比如说,文档中有这一句其实非常关键:

If you attempt to add a new database to the mirror on a nonprimary member that was not created as a mirrored database on the primary, but rather added to the mirror after it was created, an error message notes this and you cannot complete the operation.

我用最好的翻译器DeepL翻译后的中文是:

如果你试图在一个非主要成员上向镜像添加一个新的数据库,而这个数据库并不是在主要成员上作为镜像数据库创建的,而是在创建后添加到镜像中的,那么就会出现错误信息提示,你无法完成操作。

很讨厌的是它没用说明错误信息是什么,以致于很多用户, 当他们在Backup成员中把一个数据库添加到镜像时,遇到相关的错误时,没有把问题和这句话关联起来,这个错误提示是这样的:

“错误 #2105: 与成员 SERVERA/IRIS 中的相匹配的数据库 :mirror:AUGEST:DEMO 未被创建为镜像数据库”。

或者用英文,

ERROR #2105: Matching mirrored DB :mirror:AUGEST:DEMO in member SERVERA/IRIS was not created as mirrored DB

我来解释一下这句话,它说的是: ”嘿, 你在本机要添加的:mirror:AUGEST:DEMO数据库, 它在主镜像成员SERVERA/IRIS里, 未被创建为镜像数据库。“

如果您看了我的解释, 还觉得莫名其秒,我相信您其实是没懂这个关键点:

“一个数据库创建成镜像数据库,和创建成普通数据库后面后再添加到镜像里,它们是不同的。”

关于这一点,其实文档也有说明,啰嗦,但说明了原因。直接上翻译:

创建镜像数据库(即添加一个不含数据的新数据库)的过程与向镜像添加现有数据库的过程不同。作为镜像数据库创建的数据库上的Global操作从一开始就被记录在镜像Journal中,因此镜像可以访问它所需要的所有数据,以便在镜像成员之间同步数据库。但现有数据库在被添加到镜像之前的Global操作包含在非镜像Journal文件中,镜像不能访问这些文件。由于这个原因,一个现有的数据库在被添加到镜像后,必须在主故障转移成员上进行备份,并在备份故障转移成员和它要所在的任何异步成员上进行恢复。一旦这样做了,你必须激活并赶上数据库,使其与主数据库保持同步。

清楚了这个关键, 您才能理解为什么安装步骤分为下面的两个类型,

  • 创建新的镜像数据库
  • 将已有的数据库加入镜像

TIP: 另外,还有一个值得提醒的:只有用户自己的数据库可以被加入镜像。系统本身的数据库, 比如IRISSYS, IRISLIB, IRISTEMP等等,都不能加入镜像。早期有些版本可以,NOMORE!

创建新的镜像数据库

  • 主镜像成员的系统维护界面上,选择System Administration – Configuration – System Configuration – Local Databases , 选择Create New Database. 在数据库创建向导窗口,在“镜像数据库?”下拉菜框,选择'是‘(Yes)

<img src="/sites/default/files/inline/images/image-20220915132341910.png" alt="" style="zoom: 33%/>

创建成功后,维护界面会回到数据库创建页面。在下面数据库列表里,您可以看到的NEWDB前面加入了镜像的名称AUGUEST。

查看镜像监视器, 您会看到这个数据库已经成功添加入了镜像,状态为“一般”。英文原文为“Normal”,请无视优秀的翻译。

Tip: 要把数据库从镜像里移除,在“系统操作>镜像监视器“里操作。

这时候您如果去其他的镜像成员的镜像监视器里查看, 会发现如下的内容, 表示这个成员已经收到了Primary的消息:"嘿,我主机上把这个数据库加到了镜像里。"

  • 在每一个镜像成员中, 无论是backup还是异步成员,创建相同名字的本地数据库。同样的操作,选择相同的文件路径,同样在“镜像数据库?”下拉框回答Yes。创建好之后,您会看到镜像监视器里,这个数据库已经添加成功。如果在您当前操作的机器上查看镜像监视器, 您会发现和Primary里看到的稍有不同, 象这样:

​ (注意它的状态是Dejournaling, 表示它在正常的接收或者准备接收主机发来的数据同步)

  • 检查数据库工作正常
    • 在所有的镜像成员上一个个的创建使用NEWDB的命名空间。在各个机器上必须保持一致,一样的名称,一样的资源等等。(理论上不必要,但维护中非常必要)
    • 在Primary上做一个数据库操作。我喜欢在“系统资源管理器>SQL"页面执行SQL语句,比如CREATE TABLE Persons(Id int, Name varchar(255))。注意先要切换到创建的命名空间
    • 在所有的镜像成员上, 查看“系统资源管理器>SQL"页面, 确认表Persons同步到了所有的镜像成员。

这里如果您遇到上面提到的“Error 2105“, 那就是这个数据库在Primary上先是创建成一般数据库,然后加入的镜像,那您应该按下面的步骤操作了。

如果有人好奇:在Primary上的这种区别,Backup是怎么知道的,它不是还没加入到镜像吗? 故事是这样的: 镜像日志中同步的不是只有镜像数据库的数据的修改, 还包括IRISSYS, IRISAUDIT,等库的内容。NEWDB在主成员中是怎么加入到镜像的, IRISSYS里的Global Set是不一样的,而这个set, 是同步给备用成员backup的。 又一个没用的知识。

将已有的数据库加入镜像

已有的(Existing)数据库是指原本在主成员里按普通数据库创建的,然后加入镜像的数据库。

这样的情况,哪怕同样名称,配置的数据库在其他成员上已经有了。能直接加入镜像吗?比如你主成员上有个User, 备用成员上也有,您能在主机, 备机直接把它们加入镜像吗?

答案是肯定不行。系统根本没法保证这两个库里面已有的数据是一样的。您要在主成员上备份数据库,在其他成员恢复, 而恢复操作成功后,在其他成员上,这个数据库自动变成了“镜像数据库”, 也就是加入了镜像。

这个同名的数据库要先在其他成员上创建。创建成普通数据库。如果其他成员上已经有了,也不用删除,就直接用主机的备份文件覆盖就好。

以下是详细的步骤:

  • 在主机的“系统>配置>本地数据库“页面, 点击添加到镜像按钮。然后在跳出窗口中选中您要添加的数据库,可以一次选多个。 数据库很大或者多个数据库同时加入是,可以选中”在后台运行“。通常这个添加动作是在秒级时候内完成的,无所谓是否后台运行。

  • 到镜像监视器查看添加的结果。被添加的数据库状态这时候应该是"一般"(Normal) 。

  • 到其他镜像成员的镜像监视器查看, 您会看到主机来的通知引发的提醒:

  • 在备机检查自己的数据库状态。如果没有DEMO或者USER数据库,那么创建它们,创建时下拉框”是否镜像?”选择否或者NO。之后在本地数据库列表中它们应该是这样,注意没有在镜像里。

  • 在Primary做数据库的在线备份, 用于后面步骤里到其他成员上去做数据库恢复。

    以下过程仅供参考:

# 在主成员备份,并发送给备份成员serverb

%SYS>do ^BACKUP


1) Backup
2) Restore ALL
3) Restore Selected or Renamed Directories
4) Edit/Display List of Directories for Backups
5) Abort Backup
6) Display Backup volume information
7) Monitor progress of backup or restore

Option? 1


*** The time is: 2022-09-17 15:27:48 ***

                 InterSystems IRIS Backup Utility
              --------------------------
What kind of backup:
   1. Full backup of all in-use blocks
   2. Incremental since last backup
   3. Cumulative incremental since last full backup
   4. Exit the backup program
1 => 1
Specify output device (type STOP to exit)
Device: /isc/FullDBList_user.cbk => /isc/setmirror.cbk
Backing up to device: /isc/setmirror.cbk
Description:


Backing up the following directories:
 /isc/data/demo/
 /isc/iris/mgr/user/


Start the Backup (y/n)? => y
Journal file switched to:
/isc/jrnpri/MIRROR-AUGEST-20220917.011


Starting backup pass 1
Backing up /isc/data/demo/ at 09/17/2022 15:28:26
Copied 82 blocks in 0.004 seconds

Finished this pass of copying /isc/data/demo/

Backing up /isc/iris/mgr/user/ at 09/17/2022 15:28:28
Copied 908 blocks in 0.475 seconds

Finished this pass of copying /isc/iris/mgr/user/

Backup pass 1 complete at 09/17/2022 15:28:29

Starting backup pass 2
Backing up /isc/data/demo/ at 09/17/2022 15:28:31
Copied 2 blocks in 0.000 seconds

Finished this pass of copying /isc/data/demo/

Backing up /isc/iris/mgr/user/ at 09/17/2022 15:28:33
Copied 2 blocks in 0.000 seconds

Finished this pass of copying /isc/iris/mgr/user/

Backup pass 2 complete at 09/17/2022 15:28:33

Starting backup pass 3

Journal file '/isc/jrnpri/MIRROR-AUGEST-20220917.010' and the subsequent ones are required for recovery purpose if the backup were to be restored

Journal marker set at
offset 197572 of /isc/jrnpri/MIRROR-AUGEST-20220917.011

 - This is the last pass - Suspending write daemon
Backing up /isc/data/demo/ at 09/17/2022 15:28:35
Copied 2 blocks in 0.000 seconds

Finished this pass of copying /isc/data/demo/

Backing up /isc/iris/mgr/user/ at 09/17/2022 15:28:35
Copied 2 blocks in 0.001 seconds

Finished this pass of copying /isc/iris/mgr/user/

Backup pass 3 complete at 09/17/2022 15:28:35

***FINISHED BACKUP***

Global references are enabled.

Backup complete.


1) Backup
2) Restore ALL
3) Restore Selected or Renamed Directories
4) Edit/Display List of Directories for Backups
5) Abort Backup
6) Display Backup volume information
7) Monitor progress of backup or restore

Option?
%SYS>!scp /isc/setmirror.cbk root@172.16.58.102:/isc
Enter passphrase for key '/root/.ssh/id_rsa':
root@172.16.58.102's password:
setmirror.cbk                                                                                            100% 8448KB  49.4MB/s   00:00

%SYS>

  • 在其他成员上恢复数据库,这里分两种情况:

    • 其他成员上没有这个数据库: 比如我的serverb没有DEMO数据库,要做的是:创建一个DEMO数据库,使用和servera一样的设置,除了在下拉框“镜像数据库?“,回答”NO“
    • 其他成员上有这个库,比如备机serverb里有User, 不用管它,下面我们就可以直接把它覆盖掉。

    请参考下面的数据库恢复过程。 提醒一点:不要使用第一个选项“All Directories", 该选项不能用其他机器的备份文件恢复本机。

# 在Backup成员serverb上执行,恢复用源文件拷贝自servera

%SYS>do ^DBREST

                        Cache DBREST Utility
         Restore database directories from a backup archive

Restore: 1. All directories
         2. Selected and/or renamed directories
         3. Display backup volume information
         4. Exit the restore program
    1 => 2

Do you want to set switch 10 so that other processes will be
prevented from running during the restore? Yes =>

Specify input file for volume 1 of backup 1
 (Type STOP to exit)
Device: /isc/setmirror.cbk

This backup volume was created by:
   IRIS for UNIX (Red Hat Enterprise Linux 7 for x86-64) 2022.1

The volume label contains:
   Volume number      1
   Volume backup      SEP 17 2022 03:28PM Full
   Previous backup    SEP 16 2022 09:11AM Full
   Last FULL backup   SEP 16 2022 09:11AM
   Description
   Buffer Count       0
   Mirror name        AUGEST
   Failover Member    SERVERA/IRIS
Is this the backup you want to start restoring? Yes =>
This backup was made on the other mirror member.
Limit restore to mirrored databases? yes

For each database included in the backup file, you can:

 -- press RETURN to restore it to its original directory;
 -- type X, then press RETURN to skip it and not restore it at all.
 -- type a different directory name.  It will be restored to the directory
    you specify.  (If you specify a directory that already contains a
    database, the data it contains will be lost).

/isc/data/demo/ (:mirror:AUGEST:DEMO) =>
/isc/iris/mgr/user/ (:mirror:AUGEST:USER) =>

Do you want to change this list of directories? No =>

Restore will overwrite the data in the old database. Confirm Restore? No => Yes

***Restoring /isc/data/demo/ at 15:47:09
82 blocks restored in 0.0 seconds for this pass, 82 total restored.
Expanding /isc/iris/mgr/user/ ...

Expanding /isc/iris/mgr/user/ from 1 MB to 654 MB

***Restoring /isc/iris/mgr/user/ at 15:47:12
908 blocks restored in 0.0 seconds for this pass, 908 total restored.

***Restoring /isc/data/demo/ at 15:47:12
2 blocks restored in 0.0 seconds for this pass, 84 total restored.

***Restoring /isc/iris/mgr/user/ at 15:47:12
2 blocks restored in 0.0 seconds for this pass, 910 total restored.

***Restoring /isc/data/demo/ at 15:47:12
2 blocks restored in 0.0 seconds for this pass, 86 total restored.

***Restoring /isc/iris/mgr/user/ at 15:47:12
2 blocks restored in 0.0 seconds for this pass, 912 total restored.


Specify input file for volume 1 of backup following SEP 17 2022  03:28PM
 (Type STOP to exit)
Device:

Do you have any more backups to restore? Yes => no
Mounting /isc/data/demo/ which is a mirrored DB
    /isc/data/demo/       ... (Mounted)

Mounting /isc/iris/mgr/user/ which is a mirrored DB
    /isc/iris/mgr/user/   ... (Mounted)

Journal records for mirrored DBs were restored successfully.
%SYS>
  • 检查数据库列表中的状态,注意它们已经成了AUGEST的镜像数据库了, 而且它们是只读模式

  • 在serverb上查看镜像监视器,确认它们的状态是Dejournaling

后面您可以像上面提到的,在主机上操作数据, 确认数据修改同步给了备机。到此这部分工作才算结束。

如果只有外部备份文件:

按照文档上的说法,如果用外部备份在非主成员恢复,恢复后需要在镜像监视器的”镜像数据库列表里“点击"ACtiviate", 直到看到状态为Caaught up为至。请参考文档,我不是很清楚细节。

其他的镜像操作

这里我说说怎么删除镜像, 以及其他的一些常用操作的要点, 比如什么时候使用“SET NO FAILOVER”等等。
TO BE CONTINUED...

讨论 (0)1
登录或注册以继续