{"id":1648,"date":"2013-01-20T16:02:55","date_gmt":"2013-01-20T18:02:55","guid":{"rendered":"http:\/\/fabriciolima.net\/blog\/?p=1648"},"modified":"2016-07-23T23:36:11","modified_gmt":"2016-07-24T02:36:11","slug":"database-mirroring-como-fica-o-backup-do-log-quando-ocorre-um-failover-no-mirror","status":"publish","type":"post","link":"https:\/\/fabriciolima.net\/blog\/2013\/01\/20\/database-mirroring-como-fica-o-backup-do-log-quando-ocorre-um-failover-no-mirror\/","title":{"rendered":"Database Mirroring &#8211; Como fica o Backup do Log quando ocorre um Failover no Mirror"},"content":{"rendered":"<p>Ol\u00e1 Pessoal,<\/p>\n<p>Esse ser\u00e1 o \u00faltimo post de uma s\u00e9rie com 12 posts sobre testes realizados com o Database Mirroring. Com a chegada do SQL Server 2012, o Database Mirroring parece ser uma tecnologia \u00faltrapassada, contudo, conseguimos implementar ele apenas no fim do ano passado em minha empresa. At\u00e9 a migra\u00e7\u00e3o do nosso ambiente para o SQL Server 2012, precisamos ter muito conhecimento sobre o Database Mirroring para saber como agir no dia a dia.<\/p>\n<p>Para homologar o que acontece com os backups do log quando ocorre um failover no mirror, nesse teste foi feito um failover manual de uma inst\u00e2ncia A (AMBIENTE5) para uma inst\u00e2ncia B (AMBIENTE5\\INST) e em seguida foi feito um failover de volta da inst\u00e2ncia B (AMBIENTE5\\INST1) para a inst\u00e2ncia A (AMBIENTE5). Durante esses failovers, um loop de inser\u00e7\u00e3o de dados estava sendo executado nas duas inst\u00e2ncias e foi realizado v\u00e1rios backups do log nas duas inst\u00e2ncias gravando em um mesmo device.<\/p>\n<p>1 &#8211; Inicialmente foi feito um backup FULL da database Mirror1 em uma inst\u00e2ncia do SQL Server chamada AMBIENTE5.<\/p>\n<p>2 &#8211; Em seguida foi feito um backup do log da mesma base no device C:\\Mirror1_Logs.bak.<\/p>\n<p>3 &#8211; Para gerar inser\u00e7\u00f5es no log do SQL Server o loop abaixo foi iniciado:<\/p>\n<p>while 1=1<br \/>\nbegin<br \/>\nif exists (select null<br \/>\nfrom sys.databases<br \/>\nwhere name = &#8216;MIRROR1&#8217; and state_desc = &#8216;ONLINE&#8217;)<\/p>\n<p>insert into mirror1..Teste(texto)<br \/>\nselect @@servername<br \/>\nEnd<\/p>\n<p>4 &#8211; Ap\u00f3s alguns segundos foi realizado outro backup do log no mesmo device que o passo 2.<\/p>\n<p>5 &#8211; Ap\u00f3s mais alguns segundos, com o loop do passo 3 sendo executado, foi\u00a0 realizado um\u00a0 failover manual\u00a0 da inst\u00e2ncia AMBIENTE5 para a inst\u00e2ncia AMBIENTE5\\INST1 com o comando:<\/p>\n<p>ALTER DATABASE Mirror1 SET PARTNER FAILOVER<\/p>\n<p>6 &#8211; Agora conectado na inst\u00e2ncia AMBIENTE5\\INST1, a database Mirror1 possui a role Principal do Database Mirroring. Nesse momento foi realizado um backup do log nessa base para o mesmo device do passo 2.<\/p>\n<p>7 &#8211; Novamente foi deixado o loop do passo 3 executando, s\u00f3 que agora na inst\u00e2ncia AMBIENTE5\\INST1.<\/p>\n<p>8 &#8211; Ap\u00f3s alguns segundos foi realizado outro backup do log no mesmo device que o passo 2.<\/p>\n<p>9 &#8211; Realizando o mesmo processo do passo 5, foi feito um failover da inst\u00e2ncia AMBIENTE5\\INST1 para a AMBIENTE5.<\/p>\n<p>10 &#8211; Finalizando a sequencia de backups, com o loop j\u00e1 parado, foi realizado um \u00faltimo backup do Log na inst\u00e2ncia AMBIENTE5 para o mesmo device utilizado durante todo o teste.<\/p>\n<p>Para visualizar a sequ\u00eancia de backups do log, pode-se abrir a tela de restore do backup device seguindo o caminho abaixo:<\/p>\n<p>No Object Explorer do Management Studio-&gt; Bot\u00e3o direito em Databases-&gt; Restore Database&#8230; -&gt; Em \u201cSource for restore\u201d-&gt; Selecione \u201cFrom device\u201d e coloque o caminho do device utilizado:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1897\" title=\"Figura 1\" src=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11.png\" alt=\"\" width=\"882\" height=\"298\" srcset=\"https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11.png 1157w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11-300x102.png 300w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11-1024x347.png 1024w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11-768x260.png 768w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11-700x237.png 700w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11-410x139.png 410w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11-100x34.png 100w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11-275x93.png 275w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-11-20x7.png 20w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/a><\/p>\n<p>Como \u00e9 poss\u00edvel analisar na figura acima, seguindo a ordem da coluna \u201cPosition\u201d, a sequ\u00eancia de backup come\u00e7ou na instancia AMBIENTE5, executou por duas vezes na inst\u00e2ncia AMBIENTE5\\INST1 e voltou para a inst\u00e2ncia AMBIENTE5. Analisando as colunas \u201cFirst LSN\u201d e \u201cLast LSN\u201d, pode-se notar que o \u201cLAST LSN\u201d de um backup \u00e9 o mesmo \u201cFIRST LSN\u201d do backup do Log seguinte, mesmo quando os backups s\u00e3o executados em inst\u00e2ncias diferentes.<\/p>\n<p>Para finalizar o teste, foi realizado um restore do backup full realizado no Passo 1 do teste em uma database chamada \u201cMirror2\u201d seguido de um restore dos 6 backups do log da figura acima.<\/p>\n<p>Como pode ser visto na figura abaixo, a tabela onde os inserts foram realizados possui o mesmo n\u00famero de registros na base restaurada (Mirror2), ou seja, os backups do log foram todos aplicados com sucesso na opera\u00e7\u00e3o de restore.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-21.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1898\" title=\"Figura 2\" src=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-21.png\" alt=\"\" width=\"310\" height=\"169\" srcset=\"https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-21.png 390w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-21-300x163.png 300w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-21-100x54.png 100w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-21-275x149.png 275w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-21-20x11.png 20w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/a><\/p>\n<p>Conclus\u00e3o: O backup do log n\u00e3o \u00e9 afetado quando temos um failover de uma database entre dois servidores configurados em uma solu\u00e7\u00e3o de Database Mirroring.<\/p>\n<p>Para Informa\u00e7\u00e3o:<br \/>\nWhen you backup the log on the principal, the virtual log files (individual units within the log file) are marked as re-writable. The same VLF\u2019s are marked as re-writable in the mirror log file as well. The VLF status is mirrored on the database.<\/p>\n<p>Artigos relacionados:<\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/15\/serie-de-posts-sobre-database-mirroring\/\" target=\"_blank\">S\u00e9rie de Posts sobre Database Mirroring<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/15\/database-mirroring-como-alterar-o-operation-mode\/\" target=\"_blank\">Database Mirroring \u2013 Como alterar o Operation Mode<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/23\/database-mirroring-testes-operation-mode-high-performance-parte-1\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Performance \u2013 Parte 1<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/28\/database-mirroring-operation-mode-high-performance-parte-2\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Performance \u2013 Parte 2<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/31\/database-mirroring-operation-mode-high-performance-parte-3\/\" target=\"_blank\">Database Mirroring &#8211; Operation Mode High Performance &#8211; Parte 3<\/a><\/p>\n<p><a rel=\"bookmark\" href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/06\/27\/database-mirroring-operation-mode-high-safety-without-failover-parte-1\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Safety Without Failover \u2013  Parte 1<\/a><\/p>\n<p><a rel=\"bookmark\" href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/06\/29\/database-mirroring-operation-mode-high-safety-without-failover-parte-2\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Safety Without Failover \u2013  Parte 2<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/10\/31\/database-mirroring-operation-mode-high-safety-with-automatic-failover\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Safety with Automatic Failover<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/12\/03\/database-mirroring-tempo-failover-hs-with-automatic-failover-com-timeout\/\" target=\"_blank\">Database Mirroring \u2013 Tempo Failover \u2013 HS With Automatic Failover com Timeout<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2013\/01\/01\/database-mirroring-tirando-o-servidor-de-witness-do-mirror-em-caso-de-falha\/\" target=\"_blank\">Database Mirroring \u2013 Tirando o servidor de Witness do Mirror em caso de falha<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2013\/01\/11\/database-mirroring-failover-manual-de-varias-bases-ao-mesmo-tempo\/\" target=\"_blank\">Database Mirroring \u2013 Failover manual de v\u00e1rias bases ao mesmo tempo<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2013\/01\/14\/database-mirroring-configurando-um-snapshot-no-servidor-mirror\/\" target=\"_blank\">Database Mirroring \u2013 Configurando um Snapshot no servidor Mirror<\/a><\/p>\n<p><b>Gostou desse Post?<\/b><\/p>\n<p>Cadastre seu e-mail para receber novos Posts e curta minha <a href=\"https:\/\/www.facebook.com\/FabricioLimaSolucoesemBancodeDados\/\" target=\"_blank\">P\u00e1gina no Facebook<\/a> para receber Dicas de Leituras e Eventos sobre SQL Server.<\/p>\n<p>Abra\u00e7os,<\/p>\n<p>Fabr\u00edcio Lima<\/p>\n<p>MCITP \u2013 Database Administrator<\/p>\n<p>Consultor e Instrutor SQL Server<\/p>\n<p>Trabalha com SQL Server desde 2006<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ol\u00e1 Pessoal, Esse ser\u00e1 o \u00faltimo post de uma s\u00e9rie com 12 posts sobre testes realizados com o Database Mirroring. Com a chegada do SQL Server 2012, o Database Mirroring parece ser uma tecnologia \u00faltrapassada, contudo, conseguimos implementar ele apenas no fim do ano passado em minha empresa. At\u00e9 a migra\u00e7\u00e3o do nosso ambiente para [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[3,280],"tags":[604,606,391,23,607,372,613,611,612,610,608,616,49,33,50,34,605,609,614,615],"class_list":["post-1648","post","type-post","status-publish","format-standard","hentry","category-administracao-de-bd","category-virtual-pass-br","tag-alta-disponibilidade","tag-database-mirror","tag-database-mirroring","tag-dba","tag-espelhamento-de-banco-de-dados","tag-high-availability","tag-high-performance","tag-high-safety-with-automatic-failover","tag-high-safety-without-automatic-failover","tag-operation-mode","tag-perda-de-dados","tag-safety","tag-sql","tag-sql-server","tag-sql-server-2005","tag-sql-server-2008","tag-sql-server-mirror","tag-sql-server-online","tag-sys-database_mirroring","tag-witness"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts\/1648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/comments?post=1648"}],"version-history":[{"count":0,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts\/1648\/revisions"}],"wp:attachment":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/media?parent=1648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/categories?post=1648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/tags?post=1648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}