Backup mode

With backup mode Restorly also takes the backups: it dumps production, writes the dump to a backup location, and validates it right away. It is off by default and needs:

  • agent.mode: backup+validate;
  • the backup module (modules: enable: [backup]) and a licence that includes it;
  • a location with role: destination or both;
  • a backup: block on the target.
agent:
  mode: backup+validate
modules:
  enable: [backup]
locations:
  - id: nas
    type: sftp
    host: 10.0.0.20
    user: restorly
    host_key: SHA256:...
    path: /Backups
    role: both                 # Restorly reads and writes here
targets:
  - id: shop-prod
    engine: mariadb
    location: nas
    path: mysql/shop
    pattern: "shop-{YYYY}-{MM}-{DD}_{hh}{mm}.sql.zst"   # also names new backups
    schedule: "0 6 * * *"      # validation
    backup:
      from:
        host: 10.0.0.31
        user: restorly_backup
        credentials_ref: secret://shop-backup
        databases: [shop]
      schedule: "30 1 * * *"   # backups; validated straight after

In the panel, the database wizard's Backup step sets it up: the production server, the backup user (its connection is tested before you go on), the databases, the daily backup time and what to keep; the review shows the change, including agent.mode: backup+validate. A database in backup mode has Back up now next to Run now (operators); the REST API has POST /api/v1/targets/{id}/backup.

How a backup is taken

  1. Restorly connects to production once, from a throwaway container on the validation host, to read the server version. It warns if the backup user can change data.
  2. The dump runs in a container of the same series as the server:
    • MySQL and MariaDB: mysqldump / mariadb-dump with --single-transaction --routines --triggers --events;
    • PostgreSQL: pg_dump (custom format for .dump);
    • MongoDB: mongodump --archive of one database (.archive.zst, .archive.gz or .archive);
    • SQL Server: BACKUP DATABASE on the server itself (see below).
  3. The dump streams straight to the location (no copy on the validation host's disk):
    • compressed as the pattern's extension says (.sql.zst, .sql.gz, .sql, .dump);
    • hashed with SHA-256, written atomically, followed by a .sha256 file.
  4. A dump that fails, or that ends without the tool's completion marker, leaves nothing at the destination and is recorded as failed. Channels subscribed to failure are notified.
  5. With validate_after (the default) the new backup is restored and checked at once, and gets a signed report like any other backup.

Run one now with restorly backup --target shop-prod (or --all), or POST /api/v1/targets/shop-prod/backup.

Least-privilege backup users

Give the backup user only what the dump needs. Restorly warns loudly if it can write to production.

MariaDB

CREATE USER 'restorly_backup'@'10.0.0.%' IDENTIFIED BY '...';
GRANT SELECT, SHOW VIEW, TRIGGER, EVENT, LOCK TABLES ON *.* TO 'restorly_backup'@'10.0.0.%';

MySQL 8.0.32 and later also need RELOAD (or FLUSH_TABLES) for a consistent --single-transaction dump, and SHOW_ROUTINE for routines:

GRANT SELECT, SHOW VIEW, TRIGGER, EVENT, LOCK TABLES, RELOAD, SHOW_ROUTINE ON *.* TO 'restorly_backup'@'10.0.0.%';

PostgreSQL

CREATE ROLE restorly_backup LOGIN PASSWORD '...';
GRANT pg_read_all_data TO restorly_backup;

MongoDB: the built-in backup role, nothing else.

db.getSiblingDB("admin").createUser({user: "restorly_backup", pwd: "...", roles: [{role: "backup", db: "admin"}]})

The user signs in against admin. tls: require connects over TLS without checking the certificate; prefer and disable connect without TLS (MongoDB has no opportunistic TLS).

SQL Server: a login that is db_backupoperator in the database.

CREATE LOGIN restorly_backup WITH PASSWORD = '...';
USE shop;
CREATE USER restorly_backup FOR LOGIN restorly_backup;
ALTER ROLE db_backupoperator ADD MEMBER restorly_backup;

SQL Server backups

BACKUP DATABASE writes its file where SQL Server runs, so backup mode needs a directory that SQL Server and the host taking the backup both reach. Name it twice: as SQL Server sees it (server_dir) and as that host sees it (host_dir). That host is the hub, or a runner chosen with runner_selector, on the database server or with the directory mounted from a share.

targets:
  - id: erp
    engine: mssql
    location: nas
    path: mssql/erp
    pattern: "erp-{YYYY}{MM}{DD}_{hh}{mm}.bak.zst"
    runner_selector: { host: sql-01 }
    backup:
      from:
        host: 10.0.0.40
        user: restorly_backup
        credentials_ref: secret://erp-backup
        databases: [erp]
        server_dir: /var/opt/mssql/backup    # or D:\Backup, \\filer\backup
        host_dir: /srv/mssql-backup          # the same directory, here

Each run has SQL Server write restorly-<run>.bak there with COPY_ONLY, so the database's own full, differential and log backups and their chain are not disturbed, and with CHECKSUM, so SQL Server checks every page as it reads it. Restorly then compresses the file into the location (with its .sha256 file) and removes it from the directory, also when the run fails.

SQL Server writes the file readable by its own user and group only (0660). Give the directory Restorly's group with the setgid bit, so every backup takes that group and Restorly can read and remove it:

sudo chgrp restorly /srv/mssql-backup && sudo chmod 2770 /srv/mssql-backup

Backups are restored and validated like any SQL Server backup, in Microsoft's image under the database's mssql: licence settings (docs/sqlserver.md).

Retention

    backup:
      retention: { daily: 7, weekly: 4, monthly: 6 }

Grandfather-father-son rotation over the backups Restorly wrote (it never deletes files it did not write):

  • What is kept: the newest backup of each of the last 7 days, 4 ISO weeks and 6 months, and always the newest backup and the newest one that passed validation.
  • When: retention runs after each successful backup and its validation.
  • Preview: see what would go with restorly backup prune --target shop-prod --dry-run.
  • Audit: every deletion (backup and .sha256 file) is audited.
  • Paused: retention stops while backups are halted (licence), so the last good backups are never deleted while no new ones are being made.

Encryption (age)

    pattern: "shop-{YYYY}-{MM}-{DD}_{hh}{mm}.sql.zst.age"
    encryption:
      recipients: [age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p]
      identity_ref: secret://shop-age        # to validate them

Backups are compressed, then encrypted with age to the recipients' public keys before they leave the validation host. Restorly needs only the public key to write them.

  • Validating encrypted backups: Restorly decrypts them in memory with the private key in identity_ref (restorly secret set shop-age < key.txt). The same setting validates age-encrypted backups your own tools make. Without it, encrypted backups fail validation with a clear message.
  • Key escrow is your responsibility. Keep the private key where your disaster-recovery plan can reach it (a password manager, a safe, a second person). Without it nobody, Restorly included, can restore these backups. restorly check warns when recipients are set without an identity.
  • Prove the escrow key works. Encrypt to two recipients: one whose private key Restorly holds (identity_ref, for validation) and one you keep offline. Now and then, test the offline key: the database's Source tab → Recovery key test, or restorly key-test --target shop < escrow-key.txt. Restorly decrypts the start of the newest backup in memory, records the result and the key's public half in the audit log, and forgets the key (module check.key_test). It also says when the key is not among recipients, so new backups would not open with it.

Physical PostgreSQL backups (pg_basebackup)

  - id: pg-cluster
    engine: postgres
    format: physical
    pattern: "cluster-{YYYY}-{MM}-{DD}_{hh}{mm}.tar.zst"
    backup:
      from: { host: 10.0.0.40, user: restorly_repl, credentials_ref: secret://pg-repl, databases: [postgres] }

A .tar[.zst|.gz] pattern on a PostgreSQL target takes a base backup of the whole cluster with pg_basebackup -Ft -X fetch, streamed like any other backup. The user needs the REPLICATION attribute and a pg_hba line for replication connections:

CREATE ROLE restorly_repl LOGIN REPLICATION PASSWORD '...';
host  replication  restorly_repl  10.0.0.0/24  scram-sha-256

Validation extracts the base backup into the sandbox and starts PostgreSQL on it:

  • production settings are neutralised: an empty configuration file, trust on the local socket only, no archiving, replication, TLS or preloaded libraries;
  • the server recovers from backup_label with the WAL the backup carries;
  • the usual consistency and custom checks then run on the result.

Base backups you take yourself (pg_basebackup -Ft -X fetch, optionally compressed or age-encrypted) are validated the same way with format: physical.

Point-in-time restore test (WAL archive)

If the server archives its WAL (archive_mode = on and an archive_command that copies, optionally gzips or zstd-compresses, each segment to a backup location), Restorly can prove that the base backup plus the archive restores to the latest point, and measure how far it gets (module addon.pitr):

    format: physical
    pitr:
      path: pg/wal        # where archive_command puts the segments
      max_age: 1h         # warn when the newest segment is older

Every validation copies the segments from the base backup's first one on into the sandbox, starts the cluster in archive recovery reading only that copy, replays to the end and opens it. The check restore.pitr records the segments replayed and the time of the last transaction reached: how much data a restore right now would lose. Rows written after the base backup must be in the restored copy, and the consistency and custom checks run on it.

Point-in-time restore test for MariaDB and MySQL (binary logs)

For MariaDB and MySQL logical dumps the same pitr: setting replays the binary logs. Take the dump with --master-data=2 (MariaDB) or --source-data=2 (MySQL): it records the binary log position in its header. Copy the binary logs (mysql-bin.000042, MySQL's default binlog.000042, and so on, optionally gzip- or zstd-compressed) to pitr.path. Each validation applies the logs from the dump's position to the end with mariadb-binlog or mysqlbinlog, only for the dump's database when it holds one, and records the last event's time.

MySQL's official images do not include mysqlbinlog, so the first such run builds a tool image on the validation host, restorly-tools/mysqlbinlog:9.7 (or 26.7): the official mysql image plus mysqlbinlog alone, from the client package of exactly that server's version in MySQL's own repository (repo.mysql.com), its signature checked against the MySQL key the image already trusts. The host needs to reach Docker Hub and repo.mysql.com for that build; with pull_policy: never, build it elsewhere and load it (restorly preflight says so).

Restoring to a chosen time (point-in-time drill)

To show that a database can be brought back to how it was at a given moment (for an audit, or a rehearsal of "undo what happened at 14:31"), run a drill on one database with its pitr: set up:

sudo restorly run --target cluster --pitr-to "2026-10-02 14:30"

The time is UTC (or RFC 3339 with an offset, 2026-10-02T16:30:00+02:00). Operators can also start it on the database's Source tab in the panel, or with POST /api/v1/targets/{id}/drill. Restorly restores the newest backup taken at or before that time and replays the WAL or binary logs up to it, inclusive. The check restore.pitr names the point and the last transaction reached; it fails when no backup is that old or the archive ends before the point. The drill's report is signed and chained like every run, but it is not compared with earlier runs (row counts, schema and trends are skipped, as are live compare and staging copies) and the next regular run still compares with the last regular one. Custom checks run on the restored state; one comparing with now() may fail for an earlier point.

Physical MariaDB backups (mariadb-backup)

  - id: maria-cluster
    engine: mariadb
    format: physical
    runner_selector: { host: db-01 }       # the runner on the database host
    pattern: "server-{YYYY}-{MM}-{DD}_{hh}{mm}.xbstream.zst"
    backup:
      from: { host: 127.0.0.1, user: restorly_bk, credentials_ref: secret://maria-bk, datadir: /var/lib/mysql }

A .xbstream[.zst|.gz] pattern on a MariaDB target takes a full physical backup of the server with mariadb-backup --backup --stream=xbstream`. mariadb-backup` reads the data files, so it runs on the database host:

  • Install a Restorly runner there, enable module backup in the runner's own config, and point the target at it with runner_selector (see "Backups on runners" below). restorly check warns when the selector is missing.
  • datadir is the server's data directory on that host. It is mounted read-only into a container of the server's own MariaDB version. The container keeps only the capability to read files (DAC_READ_SEARCH); every other capability is dropped.
  • The backup user connects over TCP and needs these privileges:
CREATE USER 'restorly_bk'@'localhost' IDENTIFIED BY '...';
GRANT RELOAD, PROCESS, LOCK TABLES, BINLOG MONITOR ON *.* TO 'restorly_bk'@'localhost';

Use 127.0.0.1 (or the host's address) rather than localhost, because the tool runs in a container. Grant the user for the address it connects from. A backup counts only when mariadb-backup reports completed OK!. After that it is prepared, started and checked like the backups you take yourself (validation of physical backups, format: physical).

Backup mode takes logical dumps of MySQL. Percona XtraBackup backups of MySQL 8.0 and 8.4 that your own jobs take are validated (format: physical).

Backups on runners

Backups run on the hub's built-in runner, or on a remote runner where its admin allowed them:

  • The runner opts in. A runner advertises can_backup=true only when module backup is enabled in its own configuration, so nobody can send production credentials or backup work to a host without its admin's consent.
  • The hub decides whether backups run at all. Its licence, its backup module and agent.mode: backup+validate apply to every runner. When the licence halts backups, they stop everywhere.
  • Routing follows runner_selector, like validations, plus can_backup=true. A backup with no matching runner is recorded as failed with the reason and notified.
  • The runner writes the backup to the destination itself. The data never passes through the hub. The hub records the result in the backup history and audit log (actor runner:<id>), then validates the backup (routed on its own, usually to the same runner).
  • Retention is planned on the hub and carried out by the runner. A local destination is cleaned on the host where it lives. The runner deletes only files under the target's path that match its pattern.

Sanitised staging copies

With module addon.staging, every validation that passes its checks also leaves a masked copy for development and test: the rules in targets[].staging replace emails, names, phone numbers and other personal data in the restored copy, which is dumped to a destination you choose and rotated (keep). Production is never touched.

    staging:
      location: dev-share          # role: destination or both
      path: shop
      pattern: "shop-staging-{YYYY}{MM}{DD}.sql.zst"
      keep: 3
      rules:
        - { table: customers, column: email, mask: email }
        - { table: customers, column: full_name, mask: name }
        - { table: orders, column: note, mask: "null" }

Columns whose names look personal but have no rule are listed in a warning. That is a name check only: review the schema yourself before you hand the copy on.