Importing archives

Moving a database in from mimic-db or from another deployment, offline, with mimicd cutover.

A database moves into a deployment as a Mimic Archive, which mimicd cutover imports into a new database there. This is how a database leaves:

  • mimic-db, the earlier TypeScript server;
  • another deployment of this server, which exports one with mimicd archive export (see Backups and restores).

An archive of the earlier server (mimicd 0.x, which kept its data in replicated journals and an object store) is refused: that server is retired, and this one imports none of its data.

A cutover is offline: the source stops taking writes, its archive is imported, and clients move to the target. There is no live cutover, and no way back once the database serves at the target.

What carries over

  • Each document's state and state hash, and every collection's active schema. Collections keep their names, and their ids when those are UUIDs; document ids are kept.
  • The transaction ids the archive holds of each document, recorded as committed at the target, so a write the source committed and a client sends again is answered from its outcome, never applied twice.
  • Users granted on the database and their grants, with --users, from an archive that holds them.

Each document starts a new history at the target: the source's versions, commit times and history are not carried. Neither are its keys (create new ones, unless you carry them with mimicd admin access export|import between deployments of this server), its limits and access mode (set them again), nor its webhook endpoints and triggers.

Clients

  • From mimic-db, clients upgrade with the move: this server does not serve mimic-db's HTTP API or WebSocket protocol. Applications move to the current packages (the client at /v1/sessions and the server SDK) and point at the new deployment once it serves.

Before you start

  • The target deployment runs, and you hold a superuser of it.
  • No process of an earlier build of this server runs in the target: an import is refused (unavailable) while one is live.
  • The source's collections have no unfinished migration: activate or abort any migration that is verifying or sealing.
  • Every id, name, schema and value must fit this server. The cutover checks the whole archive before it writes anything, lists what does not fit, and stops: nothing is dropped or truncated.
  • Rehearse: import an archive of a backup into a throwaway deployment, and note how long it took.

Moving a database

Stop the writers

Announce the move. Stop the database's writers that do not retry (backends using the server SDK, once their writes in flight are answered). Clients that retry keep their edits, and the target answers those the archive holds.

Export the archive

From mimic-db, once its writes stopped, export the database's archive: a Mimic Archive of format version 1.

From this server, fence the database and run mimicd archive export (see Backups and restores).

Check the archive without a server, with this server's binary:

mimicd archive verify final.tar

Run the cutover

MIMIC_TARGET_PASSWORD=… mimicd cutover \
  --archive ./final.tar \
  --target https://mimic.example.com \
  --target-user admin \
  --database "$DB" \
  --partitions 4 \
  --users
OptionMeaning
--archiveThe archive: a directory, a tar file, or a tar file stored as one S3 object (s3://bucket/[prefix/]NAME.tar)
--targetThe deployment's base URL (or MIMIC_TARGET); --target-ca-cert a CA certificate to trust for it
--target-userA superuser of the target (or MIMIC_TARGET_USER), its password in MIMIC_TARGET_PASSWORD
--databaseThe source database's id
--database-idThe target database's id, 32 hexadecimal digits; by default the source's, when it is a UUID
--collection-id NAME=HEXA target id for a collection whose source id is no UUID; drawn at random otherwise
--partitionsThe target database's partitions, fixed for its life; the same on every run of one cutover
--budget-groupThe target database's budget group (default)
--usersCarry the users the database's grants name, with their password hashes, and the grants
--allow-unconverted-keysFinish although the source's keys are not carried: applications holding them are refused at the target
--archive-sha256The SHA-256 a tar archive must have, checked before anything is written
--archive-bytesThe length the tar archive must have; --archive-max-bytes the most it may have
--archive-max-transaction-bytesThe most its transaction ids and history may decompress to (4 GiB by default)
--require-fencedRefuse an archive not exported under a fence of this server (a mimic-db archive has none)
--import-sourceA name for the archive's source, the same on every run of one cutover
--jsonPrint each line as a JSON object

The database is made on the target's home store. An S3 archive's credentials come from the environment and its roles, never a shared credentials file; it is read by ranges of one version.

Point applications at the target

Once the cutover finished, compare a sample of documents between the two, create the target's keys (or import them) and set its limits, then point clients at it. Never take writes at the source again: remove the database there once the target holds a backup of its own.

Resuming and aborting

Every step reads where the last one left off from the archive and the target, so a cutover that stopped (a crash, a lost connection, a refusal you fixed) resumes when you run it again with the same arguments. --abort abandons a cutover that has not finished: the target's import is abandoned, and its database id is used up there. Abort before you let the source take writes again.

The tool prints one line per step and per collection, with counts and a summary, and never prints document content, credentials or password hashes. Its exit codes:

CodeMeaning
0Done
1A failure that may pass: run it again with the same arguments
2Something you must change, or an archive larger than its transaction budget
5An archive that cannot be read or converted
6A document the target holds otherwise than written: running it again won't help
7An archive of another length than stated