Skip to content

RootDBA

DBA expertise: PostgreSQL, SQL Server & MySQL

Menu
  • Home
  • blog
  • PostgreSql
  • MySql
  • Sql Server
  • About AHMED – Root DBA
Menu

How to configure Log shipping in Sql Server

Posted on September 2, 2025 by AHMED

SQL Server log shipping is one of the DR  solutions which involves two or more SQL Server instances; the source server is called the Primary Server and the destination is called Secondary server(s). Log shipping involves the transferring of the transaction log file from the primary server to the secondary server. Log Shipping is a basic level SQL Server high-availability technology that is part of SQL Server. This is automated by three SQL jobs

Advantages are:

• SQL Server log shipping is primarily used as a disaster recovery solution
• It’s reliable and tested in details
• It’s easy to set up and maintain
• Log shipping can be combined with other disaster recovery options such as Always On Availability Groups, database mirroring, and database replication
• Low cost in human and server resources

Disadvantages are:

• Need to manage all the databases separately
• There isn’t possibility for an automatic failover; must be manual
• And secondary database isn’t fully readable while the restore process is running

setup

its advised to create Ad service account for log shipping

i will create user (log) add the user to domain administrators group

open ssms and got to security then login right click on login and select new login

e276ddbd316860599529b1c1ffb6c050.png
ea1ed9ab2fb0c1ac112b07e867f06b3b.png

give the user the below roles

620b86b24b57962e7cdce41f062529c4.png

premission for sql server service account must have sysadmin premission

go to sql configuration manager’
576cf3d8374c54d7766f48235ef2533b.png

below services must have services account with domian admin right

240048f6697b3f1a54a396ed0474c20c.png

strating log shipping

create a database

create a table
3247425d2a89ff02c725c5e67fbb069d.png

create a shared drive in other server

now go to server one to start log shipping

mstsc_3mnP6IRyVB.gif

enable primiray database

79ec8386ed71b69cf05b046af7969ef1.png

the transaction backup will accoure by defult every 15 min but you can changed it
as showing below
ada5f7c3a37889056207bbd62f8f5dae.png
click backup setting

put the network path for backup to be dumpted

0dfcd4d72e74e6f34f7901192f2eb250.png

next we need to add secendary instance
9a78fddde6f5cb2f8dcfab97001e7922.png

mstsc_AOMUUiApwt.gif

in the below is asking location go to db2
and copy path you want to store loges
create folder in db2 and shared on the network copy the network path and put below

8efea5bc477f26cd75cac70a863fcfc8.png

b9bc487d0750bdb258dcba460244a6be.png
resotre transaction log tab

you have two option

  • List itemno recovery mode : the datae on secendray mode will not be accseable and you will not be able to qurey on secerndary modem
  • standy mode allow you to qurey on secendray mode

3eb8f3fcf054c41b1435e274397e4ef0.png

i will select standbay mode

46195e28af94bf519d03e3a596ecd7f7.png

go to db2

you will se the database ahmed we created but in read only mode

257fb8f7ceeb3a502c155682929e04bc.png

b549802dbcc13a8b640737b6e6463978.png

if you go to jobs you will find jobs

81cccce64750418f6388841e4df4ff43.png

i have created new table i will start the job manualy

msedge_gyM7vdSnGb.gif

go to serverdb2

and start job copy then restore

mstsc_lEcfVTVTqy.gif

manual failover

When managing backups and restores in a Disaster Recovery (DR) scenario, particularly in SQL Server environments, it’s crucial to ensure that the transaction log sequence numbers (LSNs) are correctly aligned. Here’s a rewritten process for managing backups and restores, focusing on LSN matching, job execution, and database restoration:

1. Verify LSN Match in Backup and DR Reports:

First, check the backup reports to confirm that the Last Log Backup LSN matches the LSN on the DR site. This ensures that the transaction logs you’re about to apply to the DR database are in sequence and no log data is missing.

2. Run the Backup Job:

Execute the backup job to create a fresh backup. This could include both full and transaction log backups, depending on your backup strategy.

3. Disable the Backup Job:

Once the backup job completes successfully, disable it temporarily. This is usually done to prevent further backups from interfering with the restoration process you’re about to perform.

4. Copy and Restore Job Execution:

Next, copy the backup files to the DR site and execute the restore job there. Ensure that the restore operation is using the most recent backups.

5. Disable the Restore Job:

After successfully restoring the backups at the DR site, disable the restore job. This step is to prevent the job from running again unintentionally.

6. Restore the DR Database and Bring Online:

Finally, restore the DR database using the copied backups and bring the database online. you can use the below command to bring database from recovery mode to online .
restore database [database name] with recovery

Additional Notes:

Transaction Log Management: Ensure that transaction logs are being managed correctly, especially if you’re using Full or Bulk-Logged recovery models.
Monitoring and Validation: Continuously monitor the restore process for any issues. Validate the integrity and consistency of the restored database.
Documentation and Automation: Keep this process well-documented, and consider automating steps where feasible to reduce the risk of human error.
LSN Consistency: Pay special attention to the LSNs during this process. They are crucial for ensuring data consistency and a successful restore process.
This process outlines a methodical approach to managing backups and restores in a DR scenario, with a particular focus on ensuring LSN consistency and minimizing downtime.

monitor log shipping

detail note about log shipping monitoring
to monitor first type is through log shipping reports
go to db2
and follow the below

mstsc_pQMpMKjnyw.gif

most important information is to look at the last restored logs what is last file copy and what is last log restored

7a3e9d37958c634c204531599390f922.png
on primary server the report will show only the last file backup

this is useful when there is issue with sync

you can use the below query for to get report to

Use master
Go
sp_help_log_shipping_monitor

3b5176df0d163cd78a03500de5f16e31.png

also you can use the below

Use master
Go
sp_help_log_shipping_monitor_primary
@primary_server =  'AHMEDDB1', --<<  PROVIDE THE PARAMETER SERVER NAME
@primary_database = 'AHMEDDB2'    --<<  PROVIDE THE PARAMETER DATABASE NAME

e2f42ded1772fe1159564d1755316bda.png

below qurey will show jobs logs

SELECT * 
FROM [msdb].[dbo].[log_shipping_monitor_error_detail]

below are qureys you can use

Stored procedures (Run on Primary server)

--EXECUTE ON PRIMARY

Use master
Go
sp_help_log_shipping_monitor

Use master
Go
sp_help_log_shipping_monitor_primary
@primary_server =  'server1', --<<  PROVIDE THE PARAMETER SERVER NAME
@primary_database = 'test'    --<<  PROVIDE THE PARAMETER DATABASE NAME


SELECT * 
FROM msdb.dbo.sysjobs 
WHERE category_id = 6

SELECT * 
FROM [msdb].[dbo].[sysjobhistory]
WHERE [message] like '%Operating system error%'

SELECT * 
FROM [msdb].[dbo].[log_shipping_monitor_error_detail]
WHERE [message] like '%Operating system error%'


EXEC xp_readerrorlog 0,1,"Backup", Null


Stored procedures (Run on Secondary server)


--run on secondary server

Use master
Go
sp_help_log_shipping_monitor

Use master
Go
sp_help_log_shipping_monitor_secondary
@secondary_server =  'server2',
@secondary_database =  'test'


SELECT * 
FROM msdb.dbo.sysjobs 
WHERE category_id = 6

SELECT * 
FROM [msdb].[dbo].[sysjobhistory]
WHERE [message] like '%Operating system error%'

SELECT * 
FROM [msdb].[dbo].[log_shipping_monitor_error_detail]
WHERE [message] like '%Operating system error%'

EXEC xp_readerrorlog 0,1,"Restore",Null




Tables in MSDB database

SELECT * 
FROM msdb.dbo.sysjobs 
WHERE category_id = 6

SELECT * 
FROM [msdb].[dbo].[sysjobhistory]
WHERE [message] like '%Operating system error%'

SELECT * 
FROM [msdb].[dbo].[log_shipping_monitor_error_detail]
WHERE [message] like '%Operating system error%'





SQL Server Error Log


Select * from sys.sysmessages 
Where description like '%shipping%' 


--Can execute on both servers

EXEC xp_readerrorlog 0,1,"Error",Null

EXEC xp_readerrorlog 0,1,"Shipping",Null

-- execute on Primary server

EXEC xp_readerrorlog 0,1,"Backup",Null

-- execute on secondary servers

EXEC xp_readerrorlog 0,1,"Restore",Null
0
Visited 92 times, 1 visit(s) today
Category: Sql server

Post navigation

← SQL Server Contained Availability Groups
Data Partition →
© 2025 RootDBA | Powered by Minimalist Blog WordPress Theme