The WikiOasis database backup system combines three complementary strategies: weekly full backups, daily incremental backups, and continuous binary log streaming. Together they provide a recovery point objective (RPO) of approximately five minutes — the interval at which binlogs are synced to the remote destination. The entire system is deployed and configured by theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/wikioasis/salt/llms.txt
Use this file to discover all available pages before exploring further.
mariadb.backup Salt state and is driven entirely by pillar data, so no manual script editing is ever required.
Architecture overview
The backup system is built aroundmariabackup (the MariaDB fork of Percona XtraBackup) streaming directly over SSH to a remote destination host. No backup data is written to the local disk for full or incremental backups — only two small state files are kept locally to track LSN progress and timestamps. Binary logs are an exception: they are buffered locally in /var/backups/mariadb/binlogs/ and rsynced to the remote host every five minutes.
The entire
mariadb.backup state is conditionally applied — it only runs if mariadb:backup:destination:host is set in pillar. If the key is absent, no backup packages are installed and no cron jobs are created.Pillar configuration
All backup parameters are nested under themariadb:backup pillar key. For a database server to receive backup configuration, its pillar file (e.g. pillar/mariadb/db-c2-us-east-031.sls) must include the following keys alongside the standard MariaDB tuning values.
| Pillar key | Default | Description |
|---|---|---|
mariadb:backup:user | mariadb_backup | MariaDB user granted RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT, REPLICATION SLAVE |
mariadb:backup:password | (none) | Password for the backup user — store in private pillar |
mariadb:backup:ssh_private_key | (none) | SSH private key written to /etc/mariadb-backup/ssh_key (mode 0600) |
mariadb:backup:destination:host | (none) | Required. Remote SSH host. If absent, the backup state does nothing. |
mariadb:backup:destination:user | (none) | Remote SSH username for rsync and streaming connections |
mariadb:backup:destination:path | /backup/mariadb | Base directory on the remote host; sub-directories per hostname are created automatically |
Backup schedule
| Job | Schedule | Command | Log |
|---|---|---|---|
| Full backup | Sunday at 01:00 | mariadb-backup-run.sh full | /var/log/mariadb-backup.log |
| Incremental backup | Mon–Sat at 02:00 | mariadb-backup-run.sh incremental | /var/log/mariadb-backup.log |
| Binlog sync | Every 5 minutes | mariadb-binlog-sync.sh | /var/log/mariadb-backup.log |
| Binlog streaming | Continuous (systemd) | mariadb-binlog-stream.service | journalctl -u mariadb-binlog-stream |
Backup scripts
mariadb-backup-run.sh
The main backup script deployed to/usr/local/bin/mariadb-backup-run.sh. It accepts a single argument — full or incremental — and streams the backup directly to the remote destination via SSH using mbstream.
Full backup behaviour:
- Rotates the previous base backup on the remote (
base→base.prev) before writing a new one. - Writes LSN state to
/var/backups/mariadb/xtrabackup_checkpointsfor subsequent incrementals. - Updates
/var/backups/mariadb/last_full_backupand/var/backups/mariadb/last_backupwith the current epoch.
- Reads the
to_lsnfrom/var/backups/mariadb/xtrabackup_checkpointsand passes it as--incremental-lsn. - If the checkpoints file is missing, falls back to a full backup automatically.
- If the full backup is more than 7 days old (i.e. the weekly cron was missed), falls back to a full backup automatically.
- If the incremental fails due to LSN incompatibility, falls back to a full backup automatically.
- Saves each incremental to
<remote_path>/<host>/incremental/<YYYYMMDD-HHMMSS>/.
notifications:discord_webhook_url or notifications:slack_webhook_url is set in pillar).
mariadb-binlog-stream.sh
Deployed to/usr/local/bin/mariadb-binlog-stream.sh and run as a systemd service (mariadb-binlog-stream.service) with Restart=always. It connects to the local MariaDB instance via the Unix socket and streams binary logs using mariadb-binlog --read-from-remote-server --stop-never --raw, writing files to /var/backups/mariadb/binlogs/.
On startup the script looks for the most recently written binlog file in the staging directory and resumes from that file. If no local files exist yet, it queries SHOW MASTER STATUS to find the current binlog filename and starts streaming from there.
mariadb-binlog-sync.sh
Deployed to/usr/local/bin/mariadb-binlog-sync.sh and run every 5 minutes by cron. It rsyncs the contents of /var/backups/mariadb/binlogs/ to <remote_user>@<remote_host>:<remote_path>/<hostname>/binlogs/ using the SSH key at /etc/mariadb-backup/ssh_key.
Local paths
| Path | Purpose |
|---|---|
/var/backups/mariadb/ | Root backup state directory |
/var/backups/mariadb/binlogs/ | Local binlog staging area (rsynced every 5 min) |
/var/backups/mariadb/xtrabackup_checkpoints | LSN state file for incremental backups |
/var/backups/mariadb/last_full_backup | Epoch of last successful full backup |
/var/backups/mariadb/last_backup | Epoch of last successful backup of any type |
/etc/mariadb-backup/ | Backup configuration directory (mode 0750) |
/etc/mariadb-backup/ssh_key | SSH private key for remote destination (mode 0600) |
/var/log/mariadb-backup.log | Cron job output log |
Monitoring and NRPE checks
Themariadb.nrpe_backup state installs check_mariadb_backup.sh as an NRPE plugin. It exposes three independent check modes:
| Mode | Warning threshold | Critical threshold | What is checked |
|---|---|---|---|
base | > 8 days (192 h) | > 9 days (216 h) | Age of last_full_backup |
incremental | > 26 hours | > 28 hours | Age of last_backup |
binlog | newest file > 15 min old | mariadb-binlog-stream not active, or newest file > 30 min old | Streaming service health |
Applying the backup state
- Install
mariadb-backupandjqpackages. - Create
/etc/mariadb-backup/and write the SSH key from pillar. - Create
/var/backups/mariadb/and/var/backups/mariadb/binlogs/. - Deploy the three backup scripts.
- Deploy and enable
mariadb-binlog-stream.service. - Create the backup MariaDB user with the required grants.
- Install the three cron jobs (weekly full, daily incremental, 5-minute binlog sync).
Verifying backups
Adding a Server
Runbook for provisioning a new database server and applying the MariaDB and backup states.
Maintenance Runbook
How to schedule downtime, depool a database server, and apply configuration changes safely.