Backup and recovery
What exists today (cold file copies, replicas, the log as the recovery record), what does not (a backup tool, online backup, point-in-time recovery), and how to plan around it.
Raft DB has a backup tool for a stopped server (raftdb-dump backup, verify, restore) and no online backup and no point-in-time recovery. Those two are future work. This page says what you can do with what exists, and what is not tested.
The backup tool#
raftdb-dump backup DATA_DIR BACKUP_DIR copy a stopped server's data directory and write a manifest
raftdb-dump verify BACKUP_DIR recompute every digest and compare with the manifest
raftdb-dump restore BACKUP_DIR DATA_DIR verify, copy into an empty folder, verify the result- A backup is a folder: the files under
files/and aMANIFEST.txtwith every file's size and SHA-256 digest (a hash list over 8 MiB pieces) and a checksum of the manifest itself. The manifest is written last, so a folder without one is an unfinished backup and is refused. - Stop the server first. The tool does not detect a running server as such. After copying it looks at the source again; if a file changed, appeared or vanished while it was copied, the backup is refused and removed. A server that is running but idle (nothing written during the copy) is not noticed, and a server that wrote something in the middle of the copy is. Only a stopped server gives a backup you can rely on.
- Nothing is overwritten. The backup folder and the restore target must be new or empty, and the backup folder may not be inside the data directory.
verifyfinds a damaged, missing or extra file. Run it on the machine that keeps the backups, on a schedule.- The format is Raft DB's own: it can only be restored into Raft DB. It is not a SQL Server
.bak, amysqldumpfile or any other product's format. For a script that other servers can load, use the SQL export. - Not covered: a backup of a running server, incremental backups, encryption and compression (use the file system or your backup product), and a cluster as a unit (each node has its own folder).
What exists#
1. A cold copy of the data directory#
Stop the server (Ctrl-C, systemctl stop raftdb), copy the whole data directory, start the server again. Because every acknowledged write is on disk and the files are a plain log (or sorted files with a manifest), a stopped server's directory is a complete, consistent copy. This is the one method the design guarantees.
- Copy the whole directory: databases,
control.stateand the password files. For the SQL front-end it includes the hidden tables with table definitions, views, routines, triggers and accounts (see Where data lives). - Restore by stopping the server, replacing the directory with the copy and starting it. Start-up recovery replays the logs and cuts any torn tail.
- A copy taken while the server runs is not guaranteed to be consistent: shards write independently and a checkpoint may rewrite a log during the copy. Do not rely on one.
- On a managed node, restoring an old
control.statealong with old data resets the epochs the node has seen; restore a node of a cluster as a new follower instead (below).
2. A replica as a live copy#
A replica (--profile replica --replica-of PRIMARY) holds a byte-identical copy of the primary's logs, kept current within the network delay, and survives the loss of the primary's machine. See Log shipping and read-only replicas. It is redundancy, not a backup: a mistaken DROP TABLE or DELETE is replicated as fast as any other change.
3. A cold copy of a replica#
Stopping a replica and copying its directory gives a cold copy without stopping the primary. This follows from the byte identity of the logs and the fact that a stopped server's directory is consistent; the procedure is not documented or tested, so test the restore before you rely on it. Start the replica again afterwards: it resumes from the end of its log.
4. Logical export#
Any SQL client can read the data. The Studio has an export wizard (JSON, NDJSON, CSV). Dumping with mysqldump or mariadb-dump is not checked here; whether a given version of those tools works against raftdb-mysql is a question to test. A 15 MB application dump was loaded and round-tripped during development (D64).
What does not exist#
| Missing | Consequence |
|---|---|
| Online (hot) consistent backup | The tool refuses a copy during which files changed, but it has no snapshot call: stop the server. |
| Incremental backup, log archiving, point-in-time recovery | You cannot restore "to 14:03:07". The log is not archived and a checkpoint rewrites it. |
| Backup of a cluster as a unit | Each node has its own directory. |
| Backup encryption or compression | Use the file system or your backup product. |
Planning around it#
- Decide the interval you can afford to lose. A cold copy gives you the state at the time of the copy; a replica gives you the state seconds ago.
- Take cold copies on a schedule from a stopped replica, or from a stopped server in a maintenance window.
- Keep copies on another machine, and test a restore: start the server on the copy with a different
addr(and different ports for the front-ends) and read the data back. - For protection against a mistaken change, keep several generations of copies; a replica will not help.
- If a log in a copy is damaged in the middle, recovery silently drops the records after the damage (Write-ahead log and checkpoints); a second copy is the only repair.
Recovery from a crash#
You need to do nothing. Start the server: it replays each log, cuts a torn last record and serves. Writes that had been acknowledged are all there; a write whose acknowledgement the client never received may or may not be. In a cluster, a node that was primary and may hold an unconfirmed tail is marked dirty (control.state) and follows the new primary's history when it returns; see Failover with a watcher quorum.
Recovery from a lost node in a cluster#
Start a new node as a replica of the current primary (or a managed follower of the quorum's leader) with an empty data directory. It fetches the catalog and every table and then follows the log.