diff --git a/docs/deployment.md b/docs/deployment.md index b9fa8a0..d774dcb 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -350,6 +350,10 @@ The MariaDB node stores the application login in the root-only file `/var/lib/coulobre/database-node/.json`. Use the credentials from that file when configuring the hosted application. +Use the MariaDB node commands to create a compressed SQL dump for an individual +managed database and restore it to an empty database with the same identity. +[Database backup and restore](development.md#back-up-and-restore-a-managed-database) + ## Publish local DNS zones from the panel Enable the [DNS publishing socket](development.md#enable-local-dns-publishing) diff --git a/docs/development.md b/docs/development.md index b4134e3..00d5c1e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -157,11 +157,49 @@ message when the installation needs attention. | --- | --- | --- | | `configured` | 0 | All checks passed. | | `not_installed` | 2 | The registry, database, and login are absent. | -| `needs_attention` | 2 | An installation is incomplete or differs from the expected configuration. | +| `needs_attention` | 2 | Provisioning or restore is incomplete, or the installation differs from the expected configuration. | Exit code `1` indicates an invalid manifest or an unavailable check, for example when the MariaDB administrative connection fails. +### Back up and restore a managed database + +Run these commands as root on the MariaDB node. Install the MariaDB client +utilities and the Coulobre package with its `mariadb` extra. Use the same +database manifest and socket as for provisioning. Add `--socket PATH` when +using a custom socket. + +```sh +sudo install -d -m 0700 /var/backups/coulobre +sudo /opt/coulobre/bin/coulobre-database-node backup-database \ + coulobre-database-1.json /var/backups/coulobre/database-1.sql.gz +``` + +The node writes a gzip-compressed SQL dump containing the database's schema, +rows, views, triggers, routines, and events. Database objects with a definer +must use the managed application login. The dump uses a single transaction +for InnoDB data. Pause schema changes and writes to nontransactional tables +during backup. Choose a new filename for each backup and keep archives in a +root-controlled directory with file permissions of `0600`. + +To restore, apply the original manifest on the destination node and leave the +new database empty. Transfer the archive to a root-controlled directory on that +node and ensure it is owned by root with permissions of `0600`. + +```sh +sudo /opt/coulobre/bin/coulobre-database-node restore-database \ + coulobre-database-1.json /var/backups/coulobre/database-1.sql.gz +``` + +The node checks the gzip stream and its database identity before running the +SQL. The archive needs temporary space for the uncompressed SQL on the same +filesystem. Use the destination node's application credentials and keep the +application disconnected until the restore completes. + +MariaDB can commit schema changes before reporting a restore error. If an +import fails, `status` reports `needs_attention`. Inspect the partial database +and return it to an empty state before retrying with the same manifest. + ### Enable local database provisioning On a MariaDB node using `/run/mysqld/mysqld.sock`, install the matching Coulobre