alwayson高可用组

Since the AlwaysOn Availabiliy Groups feature was introduced, we got new options to make the backups strategy more complete, but also more complex. Taking an advantage of secondary replicas, we can offload both, the FULL and even the Transaction Log backups from the Primary Replica to the Secondary, leaving the Primary replica dedicated to serve the production application.

自从引入AlwaysOn可用性组功能以来,我们有了新的选择,可以使备份策略更加完整,但也更加复杂。 利用辅助副本的优势,我们既可以将FULL备份,也可以将事务日志备份从主副本卸载到辅助副本,而将主副本专用于服务生产应用程序。

Going through the Availability Groups options, we can notice that we have distinct backup options:

通过“可用性组”选项,我们可以注意到我们有不同的备份选项:

The available options can be confusing, if you never tried them before. So let’s take a look on each one…

如果您以前从未尝试过可用的选项,则可能会造成混淆。 因此,让我们来看看每个……

优先中学 ( Prefer Secondary )

This option is very conceptual. Basically, you can run the backup command from any replica!

此选项非常概念化。 基本上,您可以从任何副本中运行backup命令!

Automated backups for the availability groups should occur on secondary replica (…)”

“可用性组的自动备份 在辅助副本(...)上进行”

We can easily test this by running a backup command from the Primary replica:

我们可以通过从主副本运行备份命令来轻松地对此进行测试:


BACKUP DATABASE [AdventureWorks2016]
TO  DISK = N'E:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\AdventureWorks2016.bak'
WITH STATS = 10
GO

The result:

结果:

10 percent processed.
20 percent processed.
30 percent processed.
40 percent processed.
50 percent processed.
60 percent processed.
70 percent processed.
80 percent processed.
90 percent processed.
Processed 24320 pages for database ‘AdventureWorks2016’, file ‘AdventureWorks2014_Data’ on file 2.
100 percent processed.
Processed 25 pages for database ‘AdventureWorks2016’, file ‘AdventureWorks2014_Log’ on file 2.
BACKUP DATABASE successfully processed 24345 pages in 39.265 seconds (4.843 MB/sec).

已处理10%。
已处理20%。
30%已处理。
40%已处理。
50%已处理。
60%已处理。
70%已处理。
80%已处理。
90%已处理。
已处理数据库'AdventureWorks2016'的24320页,文件2中的文件'AdventureWorks2014_Data'。
100%已处理。
处理了25页的数据库'AdventureWorks2016',文件2中的文件'AdventureWorks2014_Log'。
BACKUP DATABASE在39.265秒(4.843 MB /秒)内成功处理了24345页。

Yes, it worked! As it would work from any other replica, being a secondary or not! But, what is the reason behind this? As I said before, the keywords are “Automated” and “should”.

是的,它有效! 就像它可以在任何其他副本上工作一样,无论是不是辅助副本! 但是,这背后的原因是什么? 正如我之前所说,关键字是“自动”和“应该”。

Translating this, we can understand that “Should” would mean “yes, this would be good to run in a secondary. If not, that’s ok…”.

通过翻译,我们可以理解“应该”的意思是“是的,这在中学课程中会很好。 如果没有,那没关系……”。

What about the “Automated” keyword? This case is different. SQL Server assumes that when you run a BACKUP DATABASE command, like we did, you know what you are doing. Basically, you set the backup rules, so if you are doing the backup on the primary replica, you assume the risk. In other hand, an automated backup would be done by using the beloved SQL Server Maintenance Plan. Let’s analyse this:

那么“自动”关键字呢? 这种情况是不同的。 SQL Server假定像我们一样,当您运行BACKUP DATABASE命令时,您就知道自己在做什么。 基本上,您设置了备份规则,因此,如果要在主副本上进行备份,则要承担风险。 另一方面,将通过使用备受欢迎SQL Server维护计划来完成自动备份。 让我们分析一下:

I created a simple Maintenance Plan, with a backup task including all the databases in the instance. You can notice that there’s a warning in the bottom of the window.

我创建了一个简单的维护计划,其备份任务包括实例中的所有数据库。 您会注意到窗口底部有一个警告。

“This backup type is not supported on a secondary replica and this task will fail if the task runs on a secondary replica.”

“辅助副本不支持此备份类型,如果任务在辅助副本上运行,则此任务将失败。”

Why this? Because we are including databases that are part of an Availability Group in the plan. The problem here is simple: SQL Server does not support a regular backup to be made on Secondary replicas. In this case we are dealing with the primary one, but in case of a failover, the backup job is going to fail!

为什么这个? 因为我们将数据库纳入计划中的可用性组。 这里的问题很简单:SQL Server不支持在辅助副本上进行常规备份。 在这种情况下,我们要处理主要的问题,但是如果发生故障转移,则备份作业将失败!

How can we solve this? We need to go to the tab “Options” and tick the “Copy-only backup” option:

我们该如何解决呢? 我们需要转到“选项”标签,然后勾选“仅复制备份”选项:

For more information about this you can check the Microsoft documentation on Active Secondaries: Backup on Secondary Replicas

有关此的更多信息,您可以查看有关活动辅助副本的Microsoft文档:辅助副本上的备份

Going back to the “Automated” keyword, if we press the “View T-SQL” button, we will be able to explore the code generated to execute the backups. Based on my lab, I’ll get the following, for the AdventureWorks2016 database:

回到“ Automated”关键字,如果我们按下“ View T-SQL”按钮,我们将能够浏览生成的执行备份的代码。 根据我的实验室,我将获得AdventureWorks2016数据库的以下内容:


DECLARE @preferredReplica INT SET @preferredReplica = (SELECT
[master].sys.Fn_hadr_backup_is_preferred_replica('AdventureWorks2016')) IF ( @preferredReplica = 1 ) BEGIN BACKUP DATABASE [AdventureWorks2016] TO DISK =
N'E:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\AdventureWorks2016_backup_2015_11_23_192837_3837451.bak'WITH copy_only, noformat, noinit, NAME = N'AdventureWorks2016_backup_2015_11_23_192837_3837451', skip, rewind, nounload, stats = 10
END 

Code starts with the declaration and value attribution of a variable called “preferredReplica”:

代码从一个名为“ preferredReplica”的变量的声明和值属性开始:


DECLARE @preferredReplica INT SET @preferredReplica = (SELECT
[master].sys.Fn_hadr_backup_is_preferred_replica('AdventureWorks2016')) 

By running the select, present in code, I will get the following :

通过运行代码中存在的select,我将获得以下内容:

This matches with the configuration, as we defined that this Availability Groups would backup from the Secondary replica and, in this case, we are in the Primary replica. So the following function returns 1 if you are in the preferred replica to perform backups, and 0 if not:

这与配置匹配,因为我们定义了此可用性组将从辅助副本进行备份,在这种情况下,我们位于主副本中。 因此,如果您位于首选副本中以执行备份,则以下函数返回1,否则返回0:


[master].sys.Fn_hadr_backup_is_preferred_replica('<DATABASE_NAME>')

Continuing with the code analysis, we have now an IF controlling the execution of the actual BACKUP DATABASE command:

继续进行代码分析,我们现在有了一个IF控制实际BACKUP DATABASE命令的执行:


IF ( @preferredReplica = 1 ) BEGIN <BACKUP CODE…>
END 

Here is the point where we prove that the “Automation” is just conceptual. Basically, the SQL Server Maintenance Plan, is AG aware, and it has the backup task ready to interpret the backup options of the Availability Group. Knowing this, what happed if we run a simple (without IFs) BACKUP DATABASE command in the primary? It’s going to work! So, don’t be “eluded” thinking that set the backup preferences is enough… There are more things to do!

这是我们证明“自动化”只是概念上的观点。 基本上,SQL Server维护计划是AG已知的,并且已准备好备份任务以解释可用性组的备份选项。 知道这一点,如果我们在主数据库中运行一个简单的(没有IF)BACKUP DATABASE命令会怎样? 它会正常工作! 因此,不要以为设置备份首选项就足够了……还有更多事情要做!

One of my suggestions is use the heavily tested and community approved scripts from Ola Hallegren, which are Availability Groups aware, and very smart and flexible!

我的建议之一是使用经过Ola Hallegren严格测试并获得社区认可的脚本,这些脚本具有可用性组的知识,并且非常智能,灵活!

仅中学 ( Secondary Only )

Continuing with the analysis, we can now check the second option “Secondary Only”, which the description states that the backups MUST occur on a Secondary Replica. Let’s test it:

继续进行分析,我们现在可以检查第二个选项“仅次要”,该描述指出备份必须在次要副本上进行。 让我们测试一下:

First, connect to the primary replica, I’ll try to execute a BACKUP DATABASE command:

首先,连接到主副本,我将尝试执行BACKUP DATABASE命令:


BACKUP DATABASE [AdventureWorks2016]
TO  DISK = N'E:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\AdventureWorks2016.bak'
WITH STATS = 10
GO

The output:

输出:

10 percent processed.
20 percent processed.
30 percent processed.
40 percent processed.
50 percent processed.
60 percent processed.
70 percent processed.
80 percent processed.
90 percent processed.
Processed 24320 pages for database ‘AdventureWorks2016’, file ‘AdventureWorks2014_Data’ on file 3.
100 percent processed.
Processed 27 pages for database ‘AdventureWorks2016’, file ‘AdventureWorks2014_Log’ on file 3.
BACKUP DATABASE successfully processed 24347 pages in 12.018 seconds (15.827 MB/sec).

已处理10%。
已处理20%。
30%已处理。
40%已处理。
50%已处理。
60%已处理。
70%已处理。
80%已处理。
90%已处理。
已处理数据库'AdventureWorks2016'的24320页,文件3中的文件'AdventureWorks2014_Data'。
100%已处理。
已处理数据库'AdventureWorks2016'的27页文件,文件3中的文件'AdventureWorks2014_Log'。
BACKUP DATABASE在12.018秒(15.827 MB /秒)中成功处理了24347页。

OMG! It worked AGAIN! Why?? I set the preferences to backup ONLY in a Secondary replica and it worked in a Primary!! What’s wrong here??

我的天啊! 再次成功! 为什么?? 我将首选项设置为仅备份在辅助副本中,并且在主副本中有效!! 怎么了

Again, this is just an illusion

alwayson高可用组_了解AlwaysOn可用性组上的备份-第1部分相关推荐

  1. SQL Server 2012 AlwaysOn高可用配置之八:新建可用性组

    8. 新建可用性组 8.1 在SQL01服务器,右键"可用性组",选择"新建可用性组向导" 8.2 下一步 8.3 输入可用性组名称,下一步 8.4 勾选对应的 ...

  2. sql server高可用_SQL Server始终在线可用性组采访问题与解答

    sql server高可用 In this article, we will discuss a number of interview questions that you could be ask ...

  3. alwayson高可用组_了解AlwaysOn可用性组上的备份-第2部分

    alwayson高可用组 This article is a continuation of a guide where we are checking all the available backu ...

  4. alwayson高可用组_AlwaysOn可用性组–如何在集群实例和独立实例之间设置AG(第1部分)

    alwayson高可用组 In this article we are going to explore how to configure an Availability Group between ...

  5. alwayson高可用组_AlwaysOn可用性组–简化工作的好奇心–第1部分

    alwayson高可用组 We all love Availability Groups! Since its introduction in the SQL Server 2012, some th ...

  6. alwayson高可用组_AlwaysOn可用性组–好奇心使您的工作更轻松–第2部分

    alwayson高可用组 In continuation to the previous article, where we talked about what happens when I add ...

  7. alwayson高可用组_AlwaysOn可用性组–好奇心使您的工作更轻松–第4部分

    alwayson高可用组 Here we are with the last part of this series of articles! In this article we are going ...

  8. alwayson高可用组_AlwaysOn可用性组–如何在集群实例和独立实例之间设置AG(第2部分)

    alwayson高可用组 In continuation to the part 1, on how to setup a SQL Server Availability Groups, let's ...

  9. alwayson高可用组_AlwaysOn可用性组–如何在集群实例和独立实例之间设置AG(第3部分)

    alwayson高可用组 We have already configured our Availability Group, now we need to make it flexible and ...

最新文章

  1. 谷歌低调了 5 年的 Fuchsia OS,终于有望面世了!
  2. 集成电路:迎国产替代浪潮,设计领域机会凸显
  3. 各种语言速度之比,实验验证Cgojuliajavapythonoctave
  4. Babelfish (STL)
  5. Helpdesk 流程
  6. asp.net core 使用HttpClientFactory Polly实现熔断降级
  7. java char short区别_java 彻底理解 byte char short int float long double
  8. 中国版Azure 文件服务
  9. Wijmo 更优美的jQuery UI部件集:客户端更改C1GridView数据源
  10. 6个最好的 HTML5/CSS3 演示(PPT)框架
  11. java sleep唤醒_[JavaEE]如何唤醒Sleep中的线程
  12. Rust : 闭包、move 与自由变量的穿越
  13. 使用Excel功能抓取网页表格数据
  14. vue调整图标的大小_Vuetify图标大小
  15. 怎么使用计算机英语段落,怎么在电脑word文档中添加英文朗读功能
  16. CCF CSP 数据中心 c++ python csp201812_4 100分
  17. Hibernate主键生成策略
  18. 卡内基梅隆大学计算机科学,美国卡内基梅隆大学计算机专业怎么样?
  19. 20年管理学范围内知识点(潘永明)by:PoilZero
  20. 上传身份证照片js_web端上传图片,截取证件照

热门文章

  1. 设计个人介绍界面(用SWING控件),并添加各种组件练习
  2. Game HDU - 5242 树链思想
  3. 012-centos6.5配置静态ip
  4. Vue 组件 data为什么是函数
  5. FPGA--(verilog)一个完整工程的设计(包含设计块和激励块)及仿真
  6. Java反序列化漏洞通用利用分析
  7. AngularJs angular.element
  8. 云计算商家必争之地 推荐几款云平台
  9. 手写一切(updating...)
  10. fastdfs windows部署_从零搭建分布式文件系统MinIO比FastDFS要更合适