How to Backup the Transaction Logs in Azure SQL Edge (T-SQL)

By default, databases created in Azure SQL Edge use the simple recovery model. This means that you can’t perform log backups on these databases.

Fortunately, you can change a database’s recovery model to full recovery mode, which will enable you to back up the logs.

Example

Let’s back up the log files of a database called KrankyKranes.

Before backing up the log files, you need to ensure that the database uses either the full recovery model or the bulk logging recovery model. You also need to perform at least one full database backup before you can back up the transaction logs.

Example:

USE master;  
ALTER DATABASE KrankyKranes 
SET RECOVERY FULL;

BACKUP DATABASE KrankyKranes 
    TO DISK = '/var/opt/mssql/backups/KrankyKranes.bak'
    WITH FORMAT,
    MEDIANAME = 'SQLEdgeBackups',
    NAME = 'KrankyKranes backup',
    DESCRIPTION = 'Full Backup of the KrankyKranes database';

BACKUP LOG KrankyKranes 
TO DISK = '/var/opt/mssql/backups/KrankyKranes.trn';

Here’s what we did in the above code:

  1. First we set the database to full recovery mode.
  2. Then we perform a full backup of the database.
  3. Finally, we backed up the transaction log.

We can now continue to perform log file backups as required.

Example:

BACKUP LOG KrankyKranes 
TO DISK = '/var/opt/mssql/backups/KrankyKranes.trn';

You can also specify various options for the log backup.

Here’s an example that includes a few options:

BACKUP LOG KrankyKranes 
TO DISK = '/var/opt/mssql/backups/KrankyKranes.trn'
WITH
    NAME = 'KrankyKranes log backup',
    DESCRIPTION = 'Transaction log backups of the KrankyKranes Database',
    STATS = 5;

See Microsoft’s documentation for a complete description of all available options for the BACKUP statement.