Azure SQL Database Active Geo-Replication简介

The author introduced how to migrate a local version of SQL Server database to Azure SQL Database in the article " Migrating  SQL Server Database to Azure SQL Practice ". Although the migration was successfully achieved, we now face a new task: how to back up the newly migrated database?

For database maintenance, backup is a top priority. Of course MS Azure also provides a complete database backup function, but before creating a backup plan, please think about the real purpose of the backup work: of course, you must first ensure the security of the data. Generally speaking, you need to create a backup file of the database regularly, and then copy it. It can be stored on different storage devices; secondly, when a disaster occurs, can the database be restored in the shortest time to restore the application? Finally, can the backup database also create some value?

Let us take these questions to understand a database backup method provided by Azure that can span data centers: Active Geo-Replication.

Article source: Grape City Product Technology Community

1. What is Active Geo-Replication?

Active here can be understood as "running", Geo means "geographic" or "geographic", and Replication means "replication". The combined effect is "replicas running in different geographic locations".

Active Geo-Replication allows us to configure up to 4 read-only slave databases, plus a master database, at which point you have five instances of the database, all accessible. Note that these five databases can be set up in different data centers, which means that when four of the data centers are completely down, your database is still safe and can be used immediately because it is running database. The master database is readable and writable and synchronizes changes to the rest of the slave databases asynchronously. We can easily configure the primary and secondary databases to different data centers, so when a disaster occurs, we can resume program execution with minimal time and no data loss.

How is this done? When the master database is unavailable for any reason, we can switch any slave database to the master database. After the switch is completed, each database will immediately adapt to its new role, that is, the master database asynchronously synchronizes data to the slave database. It should be noted that Azure does not intelligently help us do the switching work. This work needs to be performed manually by the small partners, or by writing programs to perform it.

Active Geo-Replication implements an architecture that enables redundant backup of databases (databases on Azure) between different regions. It keeps master and slave servers in sync by asynchronously replicating committed transactions. Therefore, the data in the slave database will lag slightly behind the master database (I insert a piece of data in the master database, and execute the query in the slave database in the next row to find this data).

The setup of Active Geo-Replication is very simple and can be done through graphical operations. The screenshot below is a demo that sets up a slave database:

MS really does a good job at this point. The operation is easy to use when you want to create a backup in which data center, just click the circle on the map! However, the operation time cannot be guaranteed. The author tried to back up the 8G database to different data centers. The short time is a few minutes, and the long one takes hours!

2. Advantages of using Active Geo-Replication

1. Provides database-level disaster recovery

当我们把从数据库部署到 Azure 上的不同的数据中心时,就为应用程序提供了最强的的灾难恢复能力。跨数据中心的冗余数据库备份让我们能够很容易的,并且很快的从灾难中恢复数据。其中,这些灾难可能是人力不可抗拒的自然灾害,也有可能是一些人为的恶意攻击。

 

2. 只读的从数据库可以分担主数据库的部分负载

像生成报表等一些只读的操作,完全可以通过访问从数据库来完成,从而降低主数据库的负载。对于笔者来说,这是使用 Active Geo-Replication 的重要目的。读过前文的朋友知道,笔者是在维护一个旧的系统,不是必须要做的事情,笔者是不愿意去优化那些已经跑了很多年的、慢吞吞的、很复杂的报表查询操作的。现在好了,只需要把这些查询定向到备份用的从数据库就可以了,结果就是所有操作的性能都会有所提升。

更进一步,还可以把从数据库与主数据库设置在同一区域中,然后实现对读操作的负载平衡,详情请参考 MSDN。当然这并不会增加应用程序的容灾能力。

 

3. 数据库迁移

通过使用 Active Geo-Replication,我们可以用最短的时间完成数据库的迁移工作,其实就是创建一个从数据库的过程。

 

4. 应用程序升级的回退备份

我们可以创建一个从数据库作为应用程序升级失败后回退用的备份。这里可能会让人迷惑,因为主从数据库是有同步关系的,在升级主数据库的过程中从数据库肯定会被同步,它又如何能够作为备份呢?真相是这样的:在从数据库创建后可以让它断开与主数据库的主从关系,断开后就不会再被同步,所以可以起到备份的作用。

三、Active Geo-Replication的主要功能

前面我们介绍了 Active Geo-Replication 相比传统备份方法的一些优势,接下来我们一起看看它都有哪些主要功能。

1. 自动进行的异步复制

我们只能为已经存在的数据库添加从数据库,并且只能把从数据库添加到和主数据库不同的 Azure SQL Database server 中。被创建的从数据库会使用主数据库中的数据进行填充,这个过程称为播种(seeding)。播种完成后,主数据库中的更新就会以异步复制的方式,自动同步到从数据库中。

 

2. 支持最多四个从数据库

两个或两个以上的从数据库可以显著的增强主数据库的容灾能力。当有多个从数据库存在时,即便其中的一个从数据库发生了故障,也不影响主数据库的抗灾能力。注意,当你配备多个从数据库作为备份时,也是有成本的,需要根据具体需求确定从数据库的个数。

 

3. 从数据库是只读的

应用程序可以把一些只读的操作放在从数据库上,并且可以使用不同的用户权限去操作从数据库。此处我们可能会关注主从数据库同步的性能,当我们在从数据库上执行操作时,会不会影响主数据库到从数据库的同步。按照 MS 的说法是不会的,对从数据库的读操作使用了一种称为快照隔离模式(snapshot isolation mode)的高大上方法,能够在读操作的同时,不影响主数据库到从数据库的同步。

 

4. 可以使用 elastic database pool

Active Geo-Replication 可以像普通数据库一样被配置到 elastic database pool 中。

 

5. 从数据库可以设置为与主数据库不同的配置

对于作为备份存在的从数据库而言,如果保持资源类型和主数据库一致是相当奢侈的。好在 MS 也为我们提前想好了,把从数据库的资源类型设置的低一点可以为我们节省不少的预算。但这样也可能会带来一点问题,就是主从数据库的同步延迟会增加。具体情况取决于你的应用。

 

6. 用户可控的灾难恢复

一个从数据库可以在任何时刻被切换成主数据库。同时,原来的主数据库会成为从数据库。

当灾难发生在主数据库上时,我们可以把一个从数据库切换成主数据库,程序只需要重新配置数据库的链接信息即可。再次强调,这个操作需要用户使用写程序等方式来完成。

 

7. 同步防火墙和认证信息

传统 sql server 的登录用户都是在 database server 级别设置的,这在数据库同步的应用场景中,可能会带来一些不便。比如从数据库所在的 database server 上是否设置了相同的用户登录信息;如果没有,当主从数据库切换后,应用程序访问数据库时就可能碰到登录问题。

为了解决这一问题,新的 sql server 支持数据库级别的用户访问控制。用户不需要有登录 sql server 的权限,只要能够访问某个数据库就可以了,并且用户的信息是保存在数据库的配置文件中的,可以随数据库一起复制。

同理,防火墙的规则也可以设置在数据库上。

8. 使用 PowerShell 进行管理

可以使用 Azure Resource Manager (ARM) APIs 通过 PowerShell 管理 Active Geo-Replication。

四、总结

Active Geo-Replication 在提供数据库备份的同时,也增加了很多附加的价值,为我们的应用程序和维护带来了更多的灵活性。如果使用得当,可以通过很少的成本增加来创造大量的价值。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326633999&siteId=291194637