Nightly database dumps to a second machine
A dump that sits on the same drives as the database protects against mistakes, not against losing the machine. Sending it to another server covers both.
Where should the dumps go?
To a different machine, ideally in a different data centre. We do not sell a separate backup storage product, so the usual setup is a second server that acts as the vault, often from the Storage line: STORAGE-1 carries 2x 480 GB SSD SATA (system) + 4x 14 TB HDD SAS, Soft RAID, which holds years of nightly dumps for most databases. Put it in another city than the database, for example Roubaix for a primary in Frankfurt, so one site problem never takes both.
How do I make a consistent dump?
Ask the database for a snapshot rather than copying files. For InnoDB tables, --single-transaction gives a consistent view without locking writers. PostgreSQL dumps are always consistent; the custom format compresses well and allows restoring single tables.
# MariaDB or MySQL mariadb-dump --single-transaction --quick --routines --events --triggers --databases shop crm # PostgreSQL pg_dump -Fc --no-owner -d shop -f shop.pgdump pg_dumpall --globals-only > roles.sql
Run them as a dedicated backup user with read rights only. In MariaDB that user needs SELECT, SHOW VIEW, TRIGGER, EVENT and LOCK TABLES; in PostgreSQL, membership of pg_read_all_data does the job from version 14 onwards.
Should the dumps be compressed and encrypted?
Both. zstd shrinks SQL text to a fifth or less at high speed, and encrypting before the file leaves the database server means the vault never holds readable data. The age tool encrypts to a public key, so the database server can create backups but cannot read them; the private key stays offline with you.
apt install zstd age age-keygen -o vault-key.txt # on your own computer; keep this file safe mariadb-dump --single-transaction --all-databases | zstd -T0 -6 | age -r age1qxyz...publickey > /var/backups/db/all-$(date +%F).sql.zst.age
How do I send them to the vault?
With rsync over SSH using a key that may only write into one folder. On the vault, restrict the key in authorized_keys with rrsync, which ships with rsync, so a compromised database server can neither read older backups nor reach anything else.
# on the vault, one line in ~dbvault/.ssh/authorized_keys command="rrsync -wo /vault/db1",restrict ssh-ed25519 AAAAC3Nz...db1key db1-push # on the database server rsync -a --remove-source-files /var/backups/db/ dbvault@203.0.113.80:
-wo makes the folder write-only for that key. Pruning then runs on the vault itself, where the database server has no say.
What does a complete nightly job look like?
One script run by a systemd timer, which logs to the journal and catches missed runs after a reboot.
#!/bin/sh # /usr/local/sbin/db-nightly set -eu D=/var/backups/db; mkdir -p $D F=$D/$(hostname -s)-$(date +%F-%H%M).sql.zst.age mariadb-dump --single-transaction --all-databases --routines --events | zstd -T0 -6 | age -r "$(cat /etc/backup/vault.pub)" > "$F" rsync -a --remove-source-files "$D"/ dbvault@203.0.113.80:
# /etc/systemd/system/db-nightly.timer [Timer] OnCalendar=*-*-* 02:30 Persistent=true RandomizedDelaySec=600 [Install] WantedBy=timers.target
Pair it with a matching db-nightly.service of type oneshot that runs the script, then enable the timer with systemctl enable --now db-nightly.timer.
How long should I keep dumps?
Long enough to cover a problem you notice late. A common pattern keeps 14 daily, 8 weekly and 12 monthly copies. On the vault, a short script deletes daily files older than 14 days except those from Sundays and the first of each month. Size it from real numbers: a database whose compressed dump is 20 GB needs about 34 copies under this scheme, roughly 680 GB, which leaves plenty of room on a Storage machine.
| Compressed dump | Copies kept | Vault space needed |
|---|---|---|
| 2 GB | 34 | About 70 GB |
| 20 GB | 34 | About 680 GB |
| 150 GB | 34 | About 5 TB |
Are dumps enough for a large database?
Up to a few hundred gigabytes, yes. Beyond that, dumps take hours and restores longer, so add physical backups: mariabackup for MariaDB, or pgBackRest and WAL archiving for PostgreSQL, which also allow restoring to a point in time. A streaming replica on a second machine gives the fastest recovery of all, as Migrate to a new server shows. Keep logical dumps as well; they survive version upgrades that physical copies do not.
How do I know the backups work?
Restore one regularly. Once a month, take the newest file on the vault, decrypt it on a test machine with the private key, load it into a scratch database and run a few row counts against production. A backup that has never been restored is a hope rather than a plan. The Backup and archive storage page covers sizing a vault for files as well as databases.
age -d -i vault-key.txt db1-2026-12-01-0230.sql.zst.age | zstd -d | mariadb --database=restore_test
Storage machines that work well as a backup vault
| Model | Processor | Cores | Memory | Drives | Port | Per month |
|---|---|---|---|---|---|---|
| STORAGE-1 | AMD Ryzen 7 Pro 3700 | 8 | 32 GB | 2x 480 GB SSD SATA + 4x 14 TB HDD SAS | 1 Gbps unmetered | $109.80 |
| STORAGE-2 2024 | AMD EPYC 4344P | 8 | 32 GB | 2x 960 GB SSD NVMe + 2x 22 TB HDD SAS | 3 Gbps unmetered | $187.80 |
| STORAGE-2 2026 | AMD EPYC 4345P | 8 | 32 GB | 2x 960 GB SSD NVMe + 2x 24 TB HDD SAS | 3 Gbps unmetered | $273.00 |
| STORAGE-3 2024 | Intel Xeon Gold 6554S | 36 | 128 GB | 2x 960 GB SSD NVMe + 24x 22 TB HDD SAS | 10 Gbps unmetered | $1,037.40 |
Related pages
Backup and archive storage
Hard disk chassis from 44 TB to 576 TB raw for offsite backups, archives and object storage targets.
Read moreRescue a database from a dead system
Get a consistent MariaDB, MySQL or PostgreSQL dump out of a server whose operating system no longer starts, working entirely from rescue mode.
Read moreDatabase servers
NVMe machines with large memory for PostgreSQL, MySQL, MariaDB and MongoDB, from a single primary to replicated pairs.
Read moreQuestions and answers
Do you offer a separate backup storage service?
No. Rent a second server, often a Storage model in another data centre, and send encrypted dumps to it as shown here.
How do I dump MariaDB without locking the site?
Use mariadb-dump with --single-transaction. InnoDB tables are read from a consistent snapshot while writes continue.
Why encrypt dumps with a public key?
The database server can create backups but cannot read them, and the vault never holds readable data. The private key stays offline.
How many backup copies should I keep?
A common scheme keeps 14 daily, 8 weekly and 12 monthly copies, enough to cover problems noticed weeks later.
How often should I test a restore?
Monthly at least. Decrypt the newest dump on a test machine, load it and compare row counts with production.