Validating SQL Server backups

Restorly restores your SQL Server backups on the validation host — full backups (.bak) alone, or with their differential and log backups — checks them and signs the result, the same way as for MySQL, MariaDB, PostgreSQL and MongoDB.

1. Licence

Restorly runs Microsoft's SQL Server image on your validation host, so it needs two things from you, in the setup wizard (database step) or in the configuration file:

mssql:
  accept_eula: true   # you accept Microsoft's licence terms for the image
  edition: express    # free for any use, databases up to 10 GB of data
  • Express is free. Databases over 10 GB of data files are refused before anything is restored, with the size in the message.
  • Standard or Enterprise for larger databases, only if you hold licences of that edition that cover the validation host:
    mssql:
      accept_eula: true
      edition: standard
      licensed: true                       # your statement that you hold the licences
      product_key_ref: secret://mssql-key  # optional
  • A database can have its own mssql: (for a client whose licence covers their restores); the top-level section applies to the others.
  • Developer and Evaluation editions are not offered.

The edition each restore ran on is written into its signed report.

2. Validation host

  • x86-64 (Microsoft publishes no arm64 image).
  • Memory: at least 2 GiB for each SQL Server restore (set resources.memory: 2GiB or more on the database).
  • Disk: the backup is copied into the restore sandbox (decompressed), then the database is restored next to it: free space for the .bak plus the database's data and log files, plus 10%. restorly preflight shows the figure; after the first run it uses the exact sizes recorded in the backup.

3. Backups

  • Full database backups: BACKUP DATABASE [erp] TO DISK = N'...\erp-20261002.bak' WITH CHECKSUM. WITH CHECKSUM lets the restore verify every page; without it damage inside pages is found only by DBCC CHECKDB (which Restorly also runs).
  • One database per file; a file with several backup sets (NOINIT) is restored from its newest full backup.
  • Compressed backups (WITH COMPRESSION) restore on every edition.
  • Put the files where Restorly reads backups (a share, SFTP, S3) and name them with a date, e.g. pattern erp-{YYYY}{MM}{DD}.bak.
  • Differential and log backups: see Full, differential and log backups.
  • Not supported yet: FILESTREAM / memory-optimized data, backups striped over several files. Each is reported with its reason.

Full, differential and log backups

Most SQL Server databases have a full backup now and then, differential backups in between and log backups every few minutes, often made by Ola Hallengren's maintenance solution. Restorly restores them as you would after losing the server:

  1. the newest full backup, without recovery;
  2. the newest differential backup taken after it, if it was made on that full backup;
  3. every log backup after that, in the order of the log sequence numbers SQL Server records in each file;
  4. recovery. The checks then run on the database as it was at the last log backup, whose time is the run's recovery point.

For Ola Hallengren's layout (<server>/<database>/FULL, DIFF and LOG under his backup directory) a database needs its directory and chain: {}:

targets:
  - id: sales
    engine: mssql
    location: nas
    path: SQL01/Sales     # the database's directory
    chain: {}             # its FULL, DIFF and LOG directories
    timezone: Europe/Sofia  # the server's time zone: Ola Hallengren's names use local time

A backup location's Find databases proposes such a database with its chain by itself. Other layouts give each kind its pattern, relative to path:

    pattern: "Sales_FULL_{YYYY}{MM}{DD}.bak"
    chain:
      diff: "Sales_DIFF_{YYYY}{MM}{DD}_{hh}{mm}.bak"
      log: "logs/Sales_LOG_{YYYY}{MM}{DD}_{hh}{mm}.trn"
      log_max_age: 1h

What a run says (check restore.chain):

  • Passed: what was restored and the recovery point.
  • Failed: a log backup that does not follow the one before it (a missing file): the run names the file after the gap, and the database is checked as it was before it. Also a file SQL Server refuses (damaged, another database's).
  • A differential backup made on another full backup (one taken elsewhere without COPY_ONLY, or a COPY_ONLY full backup in FULL) is not restored on the full backup it does not belong to: the run warns when the log backups carry the database past it, and fails when they do not.
  • Warning: no log backup after the full or differential one although the database uses the full or bulk-logged recovery model; or the newest log backup restored older than log_max_age (2 hours by default): is the log backup job still running? A database in the simple recovery model takes no log backups, and none are expected.

A file changed within settle (10 minutes by default) waits for the next run. Only one file of the chain is in the restore sandbox at a time, so the disk needed is the larger of the full and the differential backup plus the database. On Express, a database that grows past 10 GB while its log backups restore fails with that reason. A run restores every log backup since the full or differential one, as a real recovery would, so it takes longer than a full backup alone. Not yet: striped backups (several files per backup), backups inside archives, and a drill to a chosen point in time (STOPAT). In the setup wizard, tick Also restore the differential and log backups after the full one on the database step. An upgrade rehearsal restores the full backup alone. A remote runner needs Restorly v0.1.12 or later for such a database; an older one is not given it, and the run says to update the runner.

Compressed and encrypted backups

Backups made WITH COMPRESSION or WITH ENCRYPTION are validated too. SQL Server 2022 and later write them so that only SQL Server can read their header, so Restorly restores them in the newest supported release (it reads backups of every earlier one) and records the version SQL Server reports; the run says so, and whether SQL Server's encryption was opened with your certificate. An encrypted backup, or a database with transparent data encryption, needs the server certificate it was made with: export it on the production server with

BACKUP CERTIFICATE backup_cert TO FILE = 'backup_cert.cer'
  WITH PRIVATE KEY (FILE = 'backup_cert.pvk', ENCRYPTION BY PASSWORD = '…');

and give both files and the password where you add the database (format SQL Server backup encryption), or in the configuration file (encryption.format: mssql). The certificate is created only in the throwaway restore.

4. Custom checks

T-SQL that returns rows, run in the restored database by a login that can only read (db_datareader); it cannot execute procedures.

checks:
  custom:
    - id: recent-orders
      sql: "SELECT DATEDIFF(HOUR, MAX(created_at), SYSDATETIME()) FROM dbo.orders"
      expect: { op: "<=", value: 24 }