How to Back Up an Azure SQL Edge Database to Local Disk using T-SQL

Microsoft Azure SQL Edge’s backup capabilities are similar to those in SQL Server on Linux, and SQL Server running in containers.

Azure SQL Edge supports T-SQL, and so you can back up your SQL Edge databases by running a T-SQL statement.

In this article, I back up a SQL Edge database to the local disk in my Docker container.

Example

In my case, I’m running SQL Edge in a Docker container. So I will start by creating a backup folder inside that Docker container.

If you already have a backup folder, you can skip this step. Otherwise, you can create a backup folder like this:

sudo docker exec -it sqledge mkdir /var/opt/mssql/backups

Run that on the host where the Azure SQL Edge container is running.

In my case, my container is called sqledge. Be sure to replace sqledge with the name of your container.

Now we can back up the database into the above folder.

Connect to the SQL Edge instance (for example, with SSMS or Azure Data Studio).

Once connected, run the backup:

BACKUP DATABASE KrankyKranes 
TO DISK = '/var/opt/mssql/backups/KrankyKranes.bak';

Done. That created a backup file called KrankyKranes.bak in the specified location.

Backup Options

There are many options that can be used when backing up a database in SQL Edge.

For example:

  • You can use WITH FORMAT to cause the backup operation to write a new media header on all media volumes used for the backup operation.
  • You can specify DIFFERENTIAL, so that the backup consists only of the portions of the database or file changed since the last full backup.
  • You can use the STATS option to inform you whenever a certain percentage of the backup has been done. By default, it updates at 10 percent intervals (i.e. whenever another 10% has completed). You can change this amount (for example, STATS=20).
  • You can specify a name for the backup, a filegroup, encryption, and much more.

Here’s a backup that uses a few of these options:

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',
    STATS = 20;

See Microsoft’s documentation for a complete rundown on the available options.

Note that databases created in Azure SQL Edge use the simple recovery model by default. Therefore, you can’t perform log backups on databases created in SQL Edge. If you need to perform log backups, you’ll need to change the database recovery model to the full recovery model first.