SQL Server DATABASE Transaction LOG BACKUP Using Transact-SQL

A database developer and Database Administrator should be familiar with these methods.

I have already rovided a brief introduction of database backups and Transaction Logs in my previous article SQL Server DATABASE BACKUP With Multiple Methods Using Transact-SQL and How to Track Database Transaction Log in SQL Server 2012.

About SQL Server Database Transaction Log BACKUP

You must have created at least one full backup before you create any Transaction Log backups, the Transaction Log can be backed up at any time unless the log is already being backed up.

We can create a SQL Server DATABASE LOG BACKUP with multiple methods using TSQL as in the following:

  • Transaction Log backups to disk
  • LOG backups with progress stats
  • LOG Backup with description
  • Mirrored LOG backup
  • LOG Backup with multiple options
  • LOG Backup with [Media Name]
  • LOG Backup with Expiration Date

Now I am creating a SQL Server database LOG backup using the preceding method of the DBAWorks database.

Transaction Log backups to disk

A Transaction Log is also called a database log. It can record any action by the database and store the recording results in a separate file. Now use the database "DBAWorks" to create the backup.

  1. USE [Master]  
  2. GO  
  3. BACKUP LOG DBAWorks  
  4. TO DISK = 'D:\backup\NewBackup\DBAWorks.TRN'  
  5. GO 


LOG backups with progress stats

Stats display the progress of the LOG backup. By default progress is shown after every 10%. You can set the stats value as you want.

  1. USE [Master]  
  2. GO  
  3. BACKUP LOG DBAWorks  
  4. TO DISK = 'D:\backup\NewBackup\DBAWorks_DefaultStats.TRN'  
  5. WITH STATS  
  6. GO 


  1. USE [Master]  
  2. GO  
  3. BACKUP LOG DBAWorks  
  4. TO DISK = 'D:\backup\NewBackup\DBAWorks_StatsVlue.TRN'  
  5. WITH STATS=5  
  6. GO 


LOG Backup with description

This option gives the backup name. The maximum size is 255 characters; we can use that, this can later be used with some of the restore commands to see what is contained in the backup.

  1. USE [Master]  
  2. GO  
  3. BACKUP LOG DBAWorks  
  4. TO DISK = 'D:\backup\NewBackup\DBAWorks_Desc.TRN'  
  5. WITH DESCRIPTION = 'Log backup for DBAWorks'  
  6. GO 


Mirrored LOG backup

A Mirrored LOG backup allows you to create multiple copies of the backups, preferably to various locations.

  1. USE [Master]  
  2. GO  
  3. BACKUP LOG DBAWorks  
  4. TO DISK = 'D:\backup\NewBackup\DBAWorks.TRN'  
  5. MIRROR TO DISK = 'D:\backup\NewBackup\DBAWorks_mirror.TRN'  
  6. WITH FORMAT  
  7. GO 


LOG Backup with multiple options

You can define multiples options in it as in the following:

  1. USE [Master]  
  2. GO  
  3. BACKUP LOG DBAWorks  
  4. TO DISK = 'D:\backup\NewBackup\DBAWorks1.TRN'  
  5. MIRROR TO DISK = 'D:\backup\NewBackup\DBAWorks_mirror1.TRN'  
  6. WITH DESCRIPTION = 'Log backup for DBAWorks', FORMAT, STATS  
  7. GO 


LOG Backup with [Media Name]

A database backup to disk using a format to create a new media set.

  1. USE [Master]  
  2. GO  
  3. BACKUP LOG DBAWorks  
  4. TO DISK = 'D:\backup\NewBackup\DBAWorks_Media.TRN'  
  5. WITH FORMAT,  
  6. MEDIANAME = 'my_SQLServerBackups',  
  7. NAME = Log Backup of DBAWorks';  
  8. GO 


LOG Backup with Expiration Date

You can specify an expiration date to create the backup.

  1. USE [Master]  
  2. GO  
  3. BACKUP LOG DBAWorks  
  4. TO DISK = 'D:\backup\NewBackup\[DBAWorks_date].TRN'  
  5. WITH EXPIREDATE = '01/31/2015'  
  6. GO 

You can see the following query of how many backups have been created of the database:

  1. SELECT a.database_name ,  
  2. b.physical_device_name ,  
  3. a.type ,  
  4. a.expiration_date ,  
  5. a.name ,  
  6. a.description  
  7. FROM msdb.dbo.backupset a  
  8. LEFT JOIN msdb.dbo.backupmediafamily b  
  9. ON a.media_set_id = b.media_set_id  

You can also see in the following path: