
{"id":8186,"date":"2019-08-22T18:15:42","date_gmt":"2019-08-22T18:15:42","guid":{"rendered":"https:\/\/rax-stg-wp-aws.com\/blogs\/microsoft-sql-server-log-shipping-on-existing-alwayson-databases\/"},"modified":"2026-11-03T19:29:28","modified_gmt":"2026-11-03T19:29:28","slug":"microsoft-sql-server-log-shipping-on-existing-alwayson-databases","status":"publish","type":"blogs","link":"https:\/\/www.rackspace.com\/en-gb\/blogs\/microsoft-sql-server-log-shipping-on-existing-alwayson-databases\/","title":{"rendered":"Microsoft SQL Server log shipping on existing AlwaysOn databases"},"content":{"rendered":"<p><strong>Introduction<\/strong><\/p>\n<p>This post discusses how to set up log shipping, which is a disaster recovery&nbsp;(DR) solution, with existing Microsoft\u00a9 SQL Server\u00a9 AlwaysOn-configured&nbsp;databases.<\/p>\n<p>The AlwaysOn availability group (AG) feature is a high-availability and&nbsp;disaster recovery solution that provides an enterprise-level alternative to&nbsp;database mirroring. Introduced in SQL Server 2012 (11.x), AlwaysOn AGs&nbsp;maximize the availability of a set of user databases for an enterprise.&nbsp;AGs support a fail over environment for a discrete set of user&nbsp;databases, known as availability databases, that fail over together. They also&nbsp;support a set of read-write primary databases and one to eight sets of&nbsp;corresponding secondary databases. Optionally, AGs can make&nbsp;secondary databases available for read-only access and some backup operations.<\/p>\n<p>SQL Server log shipping enables you to automatically send transaction log&nbsp;backups from a primary database on a primary server instance to one or more&nbsp;secondary databases on separate secondary server instances. The transaction log&nbsp;backups are applied to each of the secondary databases individually.<\/p>\n<p><strong>Reasons why you might need AlwaysOn log shipping<\/strong><\/p>\n<p>Let&#8217;s assume that you have configured an AlwaysOn setup between your primary&nbsp;replica server and your secondary replica and that AlwaysOn is used in the main&nbsp;data center. You might need to use log shipping if you can\u2019t expand the required<br \/>\nWindows Server Failover Cluster (WSFC) configuration into the DR site. Reasons&nbsp;include the following possibilities:<\/p>\n<p>&#8211; The infrastructure or staff can&#8217;t maintain the WSFC configurations between&nbsp;different sites.<br \/>\n&#8211; You can\u2019t leverage the target server in the DR site in the WSFC configuration&nbsp;because it is already part of another WSFC configuration.<br \/>\n&#8211; The service level agreements (SLAs) on recovery point objective (RPO) and&nbsp;&nbsp; &nbsp;recovery time objective (RTO) force a fast recovery from manual error, which&nbsp;can be realized only with a delayed recovery restoring the transaction log&nbsp;backups on one instance of the high availability (HA) and DR strategy.<\/p>\n<p>Therefore, you need to supply the target server, which is in the DR site, by&nbsp;using log shipping to ship the transaction log from backups performed in the&nbsp;main site on the current primary.<\/p>\n<p><strong>Prerequisites for using log shipping<\/strong><\/p>\n<p>Before you set up log shipping, make sure you meet the following prerequisites:<\/p>\n<p>&#8211; The primary database must use the full or bulk-logged recovery model.<br \/>\n&nbsp; &nbsp;Switching the database to simple recovery causes log shipping to stop<br \/>\n&nbsp; &nbsp;functioning.<br \/>\n&#8211; Before you configure log shipping, you must create a shared path to make the<br \/>\n&nbsp; &nbsp;transaction log backups available to the secondary server.<br \/>\n&#8211; The log-shipping stored procedures require membership in the sysadmin<br \/>\n&nbsp; &nbsp;fixed server role.<br \/>\n&#8211; The backup shared path should have read and write permissions to the SQL<br \/>\n&nbsp; &nbsp;Server service account.<\/p>\n<p><strong>&nbsp;Configure log shipping DR solution example<\/strong><\/p>\n<p>In this example, we have already setup AlwasyOn between the primary replica&nbsp;server, called PRIMEHEAD, and your secondary replica, called HEAD2, as shown&nbsp;in the following image:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture1_18.png\" alt=\"mssql log shipping pic 1\" \/><\/p>\n<p>\nThis section provides a step-by-step solution to configure log shipping on a&nbsp;database that is already a part of an AlwaysOn AG.&nbsp;<\/p>\n<p><strong>Step 1<\/strong><\/p>\n<p>Configure log shipping for the <strong>AdventureWork2014<\/strong>&nbsp;database between the&nbsp;PRIMEHEAD and the DR server, HEAD3.<\/p>\n<p>While configuring log shipping on the database, take a full backup of the&nbsp;<strong>AdventureWork2014<\/strong>&nbsp;database and restore it on HEAD3 with non-recovery.&nbsp;You need to create a shared folder on PRIMEHEAD to store the log backup that&nbsp;the <em>LSCopy<\/em>&nbsp;(log shipping) job uses.<\/p>\n<p><strong>Step 2<\/strong><\/p>\n<p>Right-click on the database, select <strong>Properties<\/strong>, and click on the&nbsp;<strong>Transaction Log Shipping<\/strong>&nbsp;option on the left side of&nbsp; PRIMEHEAD. Then, click&nbsp;on the highlighted <strong>Enable this as a primary database in a log shipping configuration<\/strong><br \/>\ncheckbox as shown in the following image:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture2_15.png\" alt=\"mssql log shipping pic 2\" \/><\/p>\n<p><strong>Step 3<\/strong><\/p>\n<p>Click <strong>Backup Setting<\/strong>&nbsp;to configure the <strong>LS Backup<\/strong>&nbsp;option. Select the&nbsp;network-shared path for LS Backup, as shown in the following image:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture3_9.png\" alt=\"mssql log shipping pic 3\" \/><\/p>\n<p><strong>Step 4<\/strong><\/p>\n<p>At this point, you can also schedule LS Backup according to your requirements.&nbsp;However, in this scenario, use the default settings.&nbsp;<\/p>\n<p><strong>Step 5<\/strong><\/p>\n<p>To add a DR server, click <strong>Add<\/strong>&nbsp;as shown in the following image:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture4_8.png\" alt=\"mssql log shipping pic 4\" \/><\/p>\n<p><strong>Step 6<\/strong><\/p>\n<p>Click <strong>Connect<\/strong>&nbsp;to connect to HEAD3, the DR server, as shown in the&nbsp;following image:&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture5_8.png\" alt=\"mssql log shipping pic 5\" \/><\/p>\n<p><strong>Step 7<\/strong><\/p>\n<p>On the <strong>Initialize Secondary Database<\/strong>&nbsp;tab, select the third option because&nbsp;the database has already been initialized on HEAD3.&nbsp;<\/p>\n<p><strong>Step 8<\/strong><\/p>\n<p>Click the <strong>Copy Files<\/strong>&nbsp;tab. In the <strong>Destination folder for copied files&nbsp;<\/strong>box, type the path where transaction log backups are copied. For this scenario,&nbsp;use <strong>C:\\LSCopyAlwaysOn<\/strong>&nbsp;for the path, as shown in the following image:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture6_6.png\" alt=\"mssql log shipping pic 6\" \/><\/p>\n<p><strong>Step 9&nbsp;<\/strong><\/p>\n<p>On the <strong>Restore Transaction Log<\/strong>&nbsp;tab, under <strong>Database state when restoring backups<\/strong>,&nbsp;choose either <strong>No recovery mode<\/strong>&nbsp;or <strong>Standby mode<\/strong>, as shown in the following&nbsp;image:<\/p>\n<p>In this example, we selected <strong>No recovery mode<\/strong>, which implies that the DR&nbsp;database is not accessible. If you select <strong>Standby Mode<\/strong>, the DR database is&nbsp;available to the end user in read-only mode.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture7_6.png\" alt=\"mssql log shipping pic 7\" \/><\/p>\n<p><strong>&nbsp;Step 10&nbsp;<\/strong><\/p>\n<p>Click <strong>OK<\/strong>&nbsp;to start the log shipping.&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture8_6.png\" alt=\"mssql log shipping pic 8\" \/><\/p>\n<p>&nbsp;The following screen displays:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture9_4.png\" alt=\"mssql log shipping pic 9\" \/><\/p>\n<p><strong>&nbsp;Step 11&nbsp;<\/strong><\/p>\n<p>To check the log shipping status, right-click on the DR server, HEAD3, instances,&nbsp;and select <strong>Reports-&gt;Standard reports\u2014&gt;Transactional Log Shipping Status<\/strong>. If&nbsp;the following screen appears, log shipping is healthy and working as expected.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture10_6.png\" alt=\"mssql log shipping pic 10\" \/><\/p>\n<p>If an AG fail over between PRIMEHEAD and HEAD2 occurs, log shipping is interrupted&nbsp;until you configure it considering AG specifications.<\/p>\n<p>Now you can configure log shipping from HEAD2 to HEAD3, which will not impact&nbsp;log shipping functionality even if there is a fail over in the future between the&nbsp;AG replicas. Log backup always happens on the same path or location, regardless&nbsp;of which replica is serving as the primary.<\/p>\n<p>You need to initiate a fail over between the replicas. Before initiating the&nbsp;fail over, complete the following steps:<\/p>\n<p>1. Execute an LS backup job on primary replica and disable the job.<\/p>\n<p>2. Execute an LS copy and restore job on secondary replica and then disable it.<br \/>\n&nbsp;<\/p>\n<p>To do this, right-click on the AG and select the fail over option as shown in the&nbsp;following image:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture11_5.png\" alt=\"mssql log shipping pic 11\" \/><\/p>\n<p>You can also accomplish this by using the following T-SQL commands to manually&nbsp;trigger an AG fail over:<\/p>\n<p><em>&nbsp; USE master;<br \/>\n&nbsp; &nbsp; GO<\/em><\/p>\n<p><em>&nbsp; &nbsp; ALTER AVAILABILITY GROUP [AGName] FAILOVER<br \/>\n&nbsp; &nbsp; GO<\/em><\/p>\n<p>After the fail over completes, the following window displays:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture12_3.png\" alt=\"mssql log shipping pic 12\" \/><\/p>\n<p><strong>&nbsp;Step 12<\/strong><\/p>\n<p>After an AG fail over between PRIMEHEAD and HEAD2, the current primary instance<br \/>\nis HEAD2.<\/p>\n<p>Follow the same steps to configure log shipping from the current primary server or&nbsp;node, HEAD2, to the DR Server, HEAD3. While configuring log shipping, choose the&nbsp;same shared path that you used during LS configuration between PRIMEHEAD and<br \/>\nHEAD3, <strong>\\\\Avail2017\\lsbackup<\/strong>.<\/p>\n<p><strong>Step 13<\/strong><\/p>\n<p>After the log shipping between HEAD2, the current primary, and HEAD3 completes,&nbsp;an LS backup job is created on HEAD2, and another set of LS copy and LS restore&nbsp;jobs are created on HEAD3.<\/p>\n<p>Once again, initiate a fail over between AG replicas. Before initiating the&nbsp;fail over, make sure to complete the following steps:<\/p>\n<p>1. Execute LS backup job on primary (HEAD2) and disable the job.<\/p>\n<p>2. Execute LS copy and restore job on secondary (HEAD3) and then disable it.<\/p>\n<p><strong>Step 14<\/strong><\/p>\n<p>After the final fail over, the current primary is PRIMEHEAD, HEAD2 is the&nbsp;secondary replica, and HEAD3 is the DR server. Because LS backup jobs exist on&nbsp;both the servers (primary and secondary), you need to modify LS backup job on&nbsp;both the PRIMEHEAD and HEAD2 to ensure that it only takes the log backup from&nbsp;the current primary.<\/p>\n<p>To do this, add the following code to the job step 1:<\/p>\n<p><em>&nbsp; &nbsp; Declare @dbname as varchar(20)<br \/>\n&nbsp; &nbsp; Set @dbname=\u2019AdventureWorks2014\u2019<br \/>\n&nbsp; &nbsp; If sys.fn_hadr_backup_is_preferred_replica (@dbname)&lt;&gt;1<br \/>\n&nbsp; &nbsp; begin<br \/>\n&nbsp; &nbsp; RAISERROR (50005,&#8211; Message id,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16, &#8212; Severity,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1, &#8211;State,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;N\u2019This is not the primary server backup is rolled back\u2019);<br \/>\n&nbsp; &nbsp; end<\/em><\/p>\n<p>The following image illustrates this:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture13_2.png\" alt=\"mssql log shipping pic 13\" \/><\/p>\n<p>&nbsp;After making the preceding changes, notice that the LS backup job starts failing&nbsp;on secondary server but runs fine on the primary.<\/p>\n<p><strong>Step 15<\/strong><\/p>\n<p>Because there are two sets of LS copy and restore jobs on HEAD3, the DR server,&nbsp;you must ensure that only one set of jobs run at a time. You need to keep the&nbsp;jobs enabled that got created while configuring log shipping between HEAD2 and&nbsp;HEAD3 and disable the other set of jobs.<\/p>\n<p>The following image shows more details:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26620-body-Picture14_2.png\" alt=\"mssql log shipping pic 14\" \/><\/p>\n<p>&nbsp;Now, you have successfully configured log shipping on a database that is an&nbsp;existing part of an AlwaysOn AG. No matter which server is working as a primary&nbsp;server, your log shipping will be in sync.<\/p>\n<p><strong>Note<\/strong>: We strongly recommended that you do not make any changes in production&nbsp;without testing. Before implementing this solution in your production environment,&nbsp;first implement this configuration in a test environment.<\/p>\n<p><strong>Validation:<\/strong><\/p>\n<p>a)&nbsp;&nbsp; &nbsp;Make sure that the backup job is running successfully on the current primary replica.<br \/>\nb)&nbsp;&nbsp; &nbsp;The backup path should be the same as the shared path.<br \/>\nc)&nbsp;&nbsp; &nbsp;Copy and restore jobs, which were created during LS configuration from HEAD2<br \/>\nto HEAD3 should run properly on the DR server.<br \/>\nd)&nbsp;&nbsp; &nbsp;Check the Transactional Log Shipping Status in the standard report section<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Configuring log shipping on a highly available database enables you to have a&nbsp;DR server set up in a different data center. This setup proves helpful in case of a&nbsp;disaster and keeps your business unaffected while requiring minimal manual effort&nbsp;even if the servers in another data center are impacted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft SQL Server log shipping on existing AlwaysOn databases<\/p>\n","protected":false},"author":2,"featured_media":8188,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"content-type":"","nid":"26620","content_type":"blog","created_by":"10130","authored_on":"2024-02-18T19:15:42+00:00","field_article_industries":"","tag_category":"Technical","field_blog_author_text":"by Rackspace Technology Staff","seo_description":"Set up log shipping on SQL Server AlwaysOn-configured databases. Emphasize disaster recovery solutions and optimal deployment strategies.\r\n","field_featured_image":"","insights_image":"\/wp-content\/uploads\/2026\/blog_technical_images\/26620-insights_image-database-technical-blog-2-insights.jpg","field_partners":"","rxt_platforms":"Microsoft SQL","product":"","publisheddate":"2019-08-22T18:15:42","rxt_solutions":"Databases","opengraph_tag":"","x_tag":"","teaser_flag":"Technical Blog","seo_titile":"Establishing Log Shipping on SQL Server AlwaysOn Databases | Rackspace Technology","field_topics":"","field_slug":"microsoft-sql-server-log-shipping","footnotes":""},"categories":[178],"tags":[204],"class_list":["post-8186","blogs","type-blogs","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-technical"],"_links":{"self":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/8186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs"}],"about":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/types\/blogs"}],"author":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/comments?post=8186"}],"version-history":[{"count":3,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/8186\/revisions"}],"predecessor-version":[{"id":9952,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/8186\/revisions\/9952"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media\/8188"}],"wp:attachment":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media?parent=8186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/categories?post=8186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/tags?post=8186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}