Docs Server and objects
Back up and restore
Back up a database with the usual options, and restore a .bak, including one on your Mac into SQL Server running in Docker, with file relocation done for you.
#Back up a database
Right-click a database ▸ Back Up Database…:
- Backup type: full, differential or transaction log (log backups need the FULL or BULK_LOGGED recovery model; the dialog says which the database uses);
- Destination on the server: a path on the server's disk, starting in its default backup folder;
- Copy-only (doesn't change the backup chain), Compress, Checksum pages, and Verify the backup afterwards (
RESTORE VERIFYONLY).
Back Up runs it with progress; Script opens the statement in a query tab instead. When the server runs in Docker on this Mac, Copy the .bak to this Mac… brings the file out of the container afterwards.
For a copy-only, compressed, checksummed backup with verification, Script gives:
BACKUP DATABASE [Northwind]
TO DISK = N'/var/opt/mssql/backup/Northwind_FULL_20261108_091500.bak'
WITH COPY_ONLY, COMPRESSION, CHECKSUM, NOINIT, NAME = N'Northwind-Full Database Backup', STATS = 10;
DECLARE @position int = (SELECT TOP (1) position FROM msdb.dbo.backupset WHERE database_name = N'Northwind' ORDER BY backup_set_id DESC);
IF @position IS NULL RAISERROR(N'Verify failed: no backup of %s was found in msdb.', 16, 1, N'Northwind');
ELSE RESTORE VERIFYONLY FROM DISK = N'/var/opt/mssql/backup/Northwind_FULL_20261108_091500.bak' WITH FILE = @position, CHECKSUM;File names default to the database, the backup type and the time (.trn for log backups).
#Restore a database
Right-click a server or its Databases folder ▸ Restore Database….
- Source: a path on the server (type it or Browse server…), or a file on this Mac.
- Read lists the backup sets in the file; pick one.
- Files (restored to): each data and log file with where it will go. The paths are worked out for you from the server's default data and log folders, so restoring a backup taken on another server just works. Change any of them if you like.
- Restore as database: keep the name or restore as a copy under another name.
- Options: RECOVERY (ready to use) or NORECOVERY (more backups to restore), Overwrite the existing database (REPLACE), Close existing connections, and Report progress.
Restore runs it with progress and the server's messages; Script opens the RESTORE statement in a tab.
#A .bak on your Mac into SQL Server in Docker
SQL Server reads backups from its own disk, so a path on your Mac doesn't work in a RESTORE statement. When the server runs in Docker on the same Mac, choose File on this Mac… and Copy into container … and Read: the file is copied into the container's backup folder first, then read and restored as usual.
AdventureWorks2022.bak → /var/opt/mssql/backup/AdventureWorks2022.bak (in the container)
AdventureWorks2022 → /var/opt/mssql/data/AdventureWorks2022.mdf
AdventureWorks2022_log → /var/opt/mssql/data/AdventureWorks2022_log.ldf