Share via

How can I create TRN file to capture only difference daily (between TRN files)?

Justin Doh 980 Reputation points
2026-02-05T20:07:21.91+00:00

I am trying to understand how Transaction Log works.

This question is related to my previous post.

My requirement is, instead of providing BAK file (because it is huge), I am trying to generate one TRN file daily for any change (insert, update or delete) from previous day's TRN file.

So, I run the bottom script to generate a BAK file. There is no issue on this.

BACKUP DATABASE TestDB  
TO DISK = 'F:\TestDB.bak'  
WITH COMPRESSION, INIT;

Then, I run the bottom script to run TRN file daily, correct?

BACKUP LOG TestDB  
TO DISK = 'F:\TestDB_Log.trn'  
WITH COMPRESSION;

What is difference between top and bottom script (with or without INIT)?

BACKUP LOG TestDB  
TO DISK = 'F:\TestDB_Log.trn'  
WITH COMPRESSION, INIT;

The reason I am asking this is when I ran the bottom code (with INIT) for testing, the size of TRN file was relatively big, so I am curious whether bottom one captures everything from original BAK or not. Should I delete INIT?

BACKUP LOG TestDB  
TO DISK = 'F:\TestDB_Log.trn'  
WITH COMPRESSION, INIT;

My goal is create a TRN file daily only for the difference between each TRN file (not accumulative differences from BAK file).

Please let me know. Thank you.

SQL Server | SQL Server Transact-SQL
0 comments No comments
{count} votes

Answer accepted by question author
  1. Erland Sommarskog 133.2K Reputation points MVP Volunteer Moderator
    2026-02-05T22:28:06.3633333+00:00

    INIT means that you want to override the existing backup file. If you are not using INIT, you will append to the existing file, so that file will keep growing. Given your use case, you should use INIT. Having multiple backups in the same file, is bound to cause confusion.

    Normally, you write each backup to a distinct filename, but in your use case that may not be necessary. That depends on how your client wants to have it on their side.

    As for the size of the transaction-log backup, I can understand if the first backup was big if you had not backed up the transaction log for a while. In that case, the transaction-log backup includes all changes since that previous log backup. That is, there is no relation to your most recent full backup.

    The transaction-log backups are entirely discoupled from the full backups with one exception: When you take your first transaction log backup, it will go back to the very first full backup after you put the database in FULL recovery mode.

    For your, quite special scenario, you would do this:

    1. As long as you are only sending full backups, set the database in simple recovery.
    2. Once you have completed all your MERGE statements so that you can make incremental updates, switch to full recovery.
    3. Take a full backup and send to customer.
    4. From now on, you send daily TRN log backups.

    Note that if the client is busy and not apply the backup they get on the 22nd, they cannot just ignore that and apply the file they get on the 23rd. They must apply all transaction logs. And they must restore with the WITH STANDBY option.


1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-05T20:07:34.1133333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To create a TRN file that captures only the differences (i.e., the transaction log) from the previous day's TRN file, you can use the BACKUP LOG command as you have shown. Here’s a breakdown of your questions:

    1. Difference Between Scripts with and without INIT:
      • The INIT option in the BACKUP LOG command specifies that the backup file should be overwritten. If you use WITH INIT, it will replace the existing TRN file with the new backup. If you do not use INIT, the new TRN file will be appended to the existing TRN file. This means that without INIT, the TRN file will accumulate logs over time, which may lead to larger file sizes as it includes all transactions since the last full backup.
    2. Size of TRN File:
      • If you notice that the size of the TRN file is relatively large when using INIT, it may be because the log contains all transactions that occurred since the last full backup or the last log backup. If you want to keep only the transactions from the last TRN file, you should not use INIT and instead append to the existing TRN file.
    3. Creating Daily TRN Files:
      • To achieve your goal of creating a TRN file daily that captures only the changes since the last TRN file, you should run the BACKUP LOG command without the INIT option. This way, each TRN file will contain only the transactions that occurred since the last log backup, allowing you to manage the size of your TRN files effectively.

    In summary, use the following command to create a TRN file daily without overwriting the previous one:

    BACKUP LOG TestDB  
    TO DISK = 'F:\TestDB_Log.trn'  
    WITH COMPRESSION;
    

    This will ensure that you are capturing only the transactions that have occurred since the last log backup without accumulating all previous transactions from the BAK file.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.