Step By Step SQL Server Log Shipping

Problem

Setting up Log Shipping for SQL Server is not that difficult, but having a step by step process is helpful if this is the first time you have setup Log Shipping. In this tip we walk through the steps to setup SQL Server Log Shipping.

Solution

Log Shipping is a basic level SQL Server high-availability technology that is part of SQL Server. It is an automated backup and restore process that allows you to create another copy of your database for failover.

Log shipping involves copying a database backup and subsequent transaction log backups from the primary (source) server and restoring the database and transaction log backups on one or more secondary (Stand By / Destination) servers. The Target Database is in a standby or no-recovery mode on the secondary server(s) which allows subsequent transaction logs to be backed up on the primary and shipped (or copied) to the secondary servers and then applied (restored) there.

Log Shipping Permissions

To setup a log-shipping you must have sysadmin rights on the server.

Log Shipping Minimum Requirements

  1. SQL Server 2005 or later
  2. Standard, Workgroup or Enterprise editions must be installed on all server instances involved in log shipping.
  3. The servers involved in log shipping should have the same case sensitivity settings.
  4. The database must use the full recovery or bulk-logged recovery model
  5. A shared folder for copying T-Log backup files
  6. SQL Server Agent Service must be configured properly

In addition, you should use the same version of SQL Server on both ends. It is possible to Log Ship from SQL 2005 to SQL 2008, but you can not do it the opposite way. Also, since Log Shipping will be primarily used for failover if you have the same versions on each end and there is a need to failover you at least know you are running the same version of SQL Server.

Check the Database Recovery Model

Make sure your database is in full or bulk-logged recovery model. You can change the database recovery model using the below query. You can check the database recovery model by querying sys.databases.

SELECT name, recovery_model_desc FROM sys.databases WHERE name = 'jugal'
USE [master]
GO
ALTER DATABASE [jugal] SET RECOVERY FULL WITH NO_WAIT
GO

Enable Primary Database for Log Shipping

On the primary server, right click on the database in SSMS and select Properties. Then select the Transaction Log Shipping Page. Check the “Enable this as primary database in a log shipping configuration” check box.

enable this as a primary database in a log shipping configuration

Configure and Schedule Transaction Log Backups

The next step is to configure and schedule a transaction log backup. Click on Backup Settings… to do this.

log shipping transaction log backups

If you are creating backups on a network share enter the network path or for the local machine you can specify the local folder path. The backup compression feature was introduced in SQL Server 2008 edition. While configuring log shipping, we can control the backup compression behavior of log backups by specifying the compression option. When this step is completed it will create the backup job on the Primary Server.

log shipping transaction log backup settings

Configure Secondary Instance and Database

In this step we will configure the secondary instance and database. Click on the Add… button to configure the Secondary Server instance and database. You can add multiple servers if you want to setup one to many server log-shipping.

add a secondary server for log shipping

When you click the Add… button it will take you to the below screen where you have to configure the Secondary Server and database. Click on the Connect… button to connect to the secondary server. Once you connect to the secondary server you can access the three tabs as shown below.

Initialize Secondary Database for Log Shipping on SQL Server

In this step you can specify how to create the data on the secondary server. You have three options: create a backup and restore it, use an existing backup and restore or do nothing because you have manually restored the database and have put it into the correct state to receive additional backups.

log shipping secondary database initialize secondary database settings

Copy Files for Log Shipping for SQL Server

In this tab you have to specify the path of the Destination Shared Folder where the Log Shipping Copy job will copy the T-Log backup files. This step will create the Copy job on the secondary server.

log shipping secondary database restore copy files settings

Restore Transaction Log for SQL Server Log Shipping

Here you have to specify the database restoring state information and restore schedule. This will create the restore job on the secondary server.

log shipping secondary database settings

Configure Log Shipping Monitoring

In this step we will configure Log Shipping Monitoring which will notify us in case of any failure. Please note Log Shipping monitoring configuration is optional.

monitor sql server instance

Click on Settings… button which will take you to the “Log Shipping Monitor Settings” screen. Click on Connect … button to setup a monitor server. Monitoring can be done from the source server, target server or a separate SQL Server instance. We can configure alerts on source / destination server if respective jobs fail. Lastly we can also configure how long job history records are retained in the MSDB database. Please note that you cannot add a monitor instance once log shipping is configured.

log shipping monitor settings

Complete Log Shipping Configuration

Click on the OK button to finish the Log Shipping configuration and it will show you the below screen.

save log shipping configuration

Key Takeaways

  • Setting up SQL Server log shipping involves configuring an automated process for backing up and restoring databases across primary and secondary servers.
  • To start, you need sysadmin rights and must fulfill specific requirements, such as matching SQL Server versions and using a full recovery model.
  • Key steps include enabling log shipping on the primary database, scheduling transaction log backups, and configuring the secondary server and database.
  • Finally, you can set up log shipping monitoring to track any failures, although this step is optional.
  • Remember, SQL Server log shipping does not support automatic failover, so plan for manual processes and check for orphaned users during failover.

Next Steps

  • As Log Shipping does not support automatic failover, plan for some down time and a manual failover
  • Once you failover, check for Orphan Users and fix as needed
  • For VLDBs it is recommended that you manually restore the database instead of using the wizard to create the full backup.

4 Comments

  1. Hi Rajashekar,

    Since the database is in standby mode you are not able to make any changes, you can only read from the database.

    If you add the user to the primary database, log shipping should create the user on the standby database.

    The downside is the login-to-user mapping might get mixed up, so it may not provide the login on the standby server access to the database since the SIDs may be different from one server to the other.

    -Greg

  2. Hi Guys,
    Do anyone have idea about how to create user when the database is in standby mode when it is configured to logshiiping.

  3. No SQL Server doesn’t support the higher to lower major version backup restore. You can use the SSIS or import/export wizard for the lower version migration.

Leave a Reply

Your email address will not be published. Required fields are marked *