Export, Import, Backend Durability and Recovery

Article · 9:00

Logical export and import, durability by storage backend, distributed deployment options, rebuild as the primary strategy, and verification.

Recovery here depends almost entirely on your storage backend, and the honest summary is that the open-source single-node story is export plus filesystem snapshots plus the ability to rebuild - not point-in-time recovery. After the TimescaleDB course that is a step down, and it is better to design for it than to discover it.

surreal export and surreal import are the logical path. Export produces SurrealQL - the schema definitions and the data as statements - which is readable, portable across backends, and the thing you can diff. Its costs are the ordinary logical-backup ones: the export takes time proportional to the data, the import takes longer, and neither is atomic with respect to a live system, so an export taken while writes continue is not a consistent snapshot unless you arrange one. Measure both on your real data volume, because the import time is your rebuild RTO and people are routinely surprised by it.

Durability is the backend's property, not the engine's. An in-memory store has none. A local embedded file store is durable to disk and is backed up by stopping or quiescing the process and snapshotting the data directory, which gives you a consistent point - and that is the mechanism to build your backup on, with exports as the portable secondary. A distributed key-value store underneath brings its own replication, its own backup tooling and its own operational discipline, and that becomes the system you are actually operating - which is a real staffing consideration and the main reason the single-node file-backed deployment is more often the right answer than people expect.

So the primary recovery strategy is rebuild, and it should be a designed capability rather than a fallback. The pattern is the one the vector database courses arrived at: keep a durable source of record outside the database - an event log, an object store of source documents, or your upstream system - and make the SurrealDB instance reconstructable from it. Three reasons this is the right posture here specifically: your recovery options are limited, your upgrade path may itself require an export and reimport, and a young engine is one where you want a way back regardless. A tested rebuild path is simultaneously your disaster recovery, your upgrade mechanism and your confidence to upgrade at all - which is unusually good value for one piece of engineering.

Measure the rebuild rate and state the arithmetic. If a full rebuild takes nine hours and your tolerance is four, you need either a faster path - parallel import, a restored snapshot as the starting point, partial rebuild of only what changed - or a stated acceptance. A rebuild time you have not measured is not a recovery plan, and this is the number the runbook turns on.

Verification must be a correctness check. A restored or rebuilt database with the right record count and wrong links looks exactly like a correct one, and links and edges are what verification must actually check here, because they are the structure. The checks: record counts per table against the source; dangling link detection - a link pointing at a record that does not exist; edge endpoint integrity - edges whose in or out is missing; constraint re-verification, since ASSERTs and UNIQUEs are only enforced on write and a bad import can bypass expectations; permissions re-tested, because they are schema and schema comes back from an export; and a sample of real queries producing the same results as before.

Laboratory exercise 5 - lose it and rebuild it, timed.

Configure a durable source of record in front of your tracker - an event log or an object store of source records - and make the SurrealDB instance reconstructable from it.

Measure export and import at your full data volume, both directions, recording wall time and output size. Demonstrate the consistency problem: export while writes continue, import to a second instance, and find the inconsistency - a task referencing a comment that is not there, or an edge with a missing endpoint. Then arrange a consistent export and show it clean.

Demonstrate the snapshot path: quiesce the process, snapshot the data directory, restore it to a new instance, and verify. Time every phase and compare with the export path.

Then the rebuild drill, which is the module's point. Destroy the database entirely while the system is under load, rebuild from the source of record, and time every phase: detect, decide, provision, load, verify, resume. State the measured RTO and the RPO your source of record gives you.

Then the capacity question: with the measured rebuild rate, calculate the largest dataset you can rebuild within your target RTO. If your current data already exceeds it, say so and design the faster path - and record which option you chose.

Write the verification suite: per-table counts, dangling link detection, edge endpoint integrity, constraint re-verification, permission re-tests, and a sample query comparison. Run it after every recovery in this module.

If you are using a distributed backend, additionally document its failure modes and recovery procedures, and be honest in the runbook about which team owns that operational burden.

Deliverable: the source-of-record architecture, export and import timings, the inconsistent export demonstrated and the consistent one, the snapshot path timed against the export path, the rebuild drill with measured RPO and RTO, the capacity calculation with its chosen faster path, and the verification suite with its output.

-- ==================================================================
-- *** THE HONEST SUMMARY: the open-source single-node story is
-- *** EXPORT + FILESYSTEM SNAPSHOTS + THE ABILITY TO REBUILD. NOT
-- *** POINT-IN-TIME RECOVERY. *** After TimescaleDB that is a step
-- *** down, and it is better to DESIGN FOR IT than to DISCOVER IT.
-- ==================================================================

-- THE LOGICAL PATH - produces SurrealQL: readable, portable across
-- backends, and *** THE THING YOU CAN DIFF: ***
--   surreal export --conn http://localhost:8000 \
--     --user root --pass root --ns acme --db tracker tracker.surql
--   surreal import --conn http://localhost:8000 \
--     --user root --pass root --ns acme --db tracker tracker.surql
--
-- *** MEASURE BOTH ON YOUR REAL DATA VOLUME. THE IMPORT TIME IS YOUR
-- *** REBUILD RTO AND PEOPLE ARE ROUTINELY SURPRISED BY IT: ***
--   20,000,000 records
--     export     14 min     file 41 GB
--     *** import   2 h 50 min ***     <- the number for the runbook
--
-- *** AND NEITHER IS ATOMIC WITH RESPECT TO A LIVE SYSTEM. *** An
-- export taken while writes continue IS NOT A CONSISTENT SNAPSHOT:
--   demonstrate it - export under load, import to a second instance,
--   and FIND the inconsistency (a comment referencing a task that is
--   not there; an edge with a missing endpoint). Then arrange a
--   consistent export - quiesce writes, or snapshot first - and show
--   it clean.

-- ==================================================================
-- *** DURABILITY IS THE BACKEND'S PROPERTY, NOT THE ENGINE'S. ***
-- ==================================================================
--   IN-MEMORY        *** NONE. *** Tests only.
--   LOCAL FILE STORE durable to disk. Backed up by *** STOPPING OR
--                    QUIESCING THE PROCESS AND SNAPSHOTTING THE DATA
--                    DIRECTORY ***, which gives a CONSISTENT POINT -
--                    and that is the mechanism to BUILD YOUR BACKUP
--                    ON, with exports as the PORTABLE SECONDARY.
--   DISTRIBUTED KV   its OWN replication, its OWN backup tooling,
--                    its OWN operational discipline - *** AND THAT
--                    BECOMES THE SYSTEM YOU ARE ACTUALLY
--                    OPERATING. *** A real STAFFING consideration,
--                    and the main reason the single-node
--                    file-backed deployment is more often right than
--                    people expect.

-- ==================================================================
-- *** SO THE PRIMARY STRATEGY IS REBUILD - A DESIGNED CAPABILITY,
-- *** NOT A FALLBACK. ***
-- ==================================================================
--   source of record  ->  SurrealDB (RECONSTRUCTABLE)
--   (event log, object store of source records, upstream system)
--
-- *** THREE REASONS THIS IS THE RIGHT POSTURE HERE SPECIFICALLY: ***
--   1. your recovery options are LIMITED;
--   2. *** YOUR UPGRADE PATH MAY ITSELF REQUIRE AN EXPORT AND
--      *** REIMPORT *** (Module 6);
--   3. a young engine is one where YOU WANT A WAY BACK regardless.
--
-- *** A TESTED REBUILD PATH IS SIMULTANEOUSLY YOUR DISASTER
-- *** RECOVERY, YOUR UPGRADE MECHANISM AND YOUR CONFIDENCE TO
-- *** UPGRADE AT ALL *** - unusually good value for one piece of
-- engineering, and the reason to build it early rather than when you
-- need it.

-- *** MEASURE THE REBUILD RATE AND STATE THE ARITHMETIC: ***
--   rebuild rate                 ______ records/s
--   current data                 ______ records
--   -> rebuild time              ______ h
--   target RTO                   ______ h
--   -> *** IF REBUILD TIME EXCEEDS THE RTO, YOU NEED A FASTER PATH
--      *** OR A STATED ACCEPTANCE: ***
--        PARALLEL import by table
--        a RESTORED SNAPSHOT as the starting point, then replay
--          forward from the source of record (usually the best one)
--        PARTIAL rebuild of only what changed
--        a documented acceptance, signed off
-- *** A REBUILD TIME YOU HAVE NOT MEASURED IS NOT A RECOVERY PLAN ***
-- - and this is the number the runbook turns on.

-- ==================================================================
-- *** VERIFICATION MUST BE A CORRECTNESS CHECK - AND HERE THAT MEANS
-- *** LINKS AND EDGES, BECAUSE THEY ARE THE STRUCTURE. ***
-- ==================================================================
-- (1) RECORD COUNTS PER TABLE, against the source:
SELECT count() FROM user   GROUP ALL;
SELECT count() FROM project GROUP ALL;
SELECT count() FROM task   GROUP ALL;
SELECT count() FROM comment GROUP ALL;
SELECT count() FROM assigned   GROUP ALL;
SELECT count() FROM depends_on GROUP ALL;
SELECT count() FROM member_of  GROUP ALL;

-- (2) *** DANGLING LINK DETECTION - a link pointing at a record that
--     *** DOES NOT EXIST. The check people skip, and the one a bad
--     *** import produces: ***
SELECT id, assignee FROM task
WHERE assignee != NONE AND assignee.id = NONE;
--   Expected: no rows.
SELECT id, project FROM task WHERE project.id = NONE;
SELECT id, author  FROM comment WHERE author.id = NONE;

-- (3) *** EDGE ENDPOINT INTEGRITY - edges whose in or out is
--     *** missing. An edge with a dead endpoint breaks every
--     *** traversal through it, silently: ***
SELECT id, in, out FROM depends_on WHERE in.id = NONE OR out.id = NONE;
SELECT id, in, out FROM assigned   WHERE in.id = NONE OR out.id = NONE;
SELECT id, in, out FROM member_of  WHERE in.id = NONE OR out.id = NONE;
--   Expected: no rows, all three.

-- (4) CONSTRAINT RE-VERIFICATION. ASSERTs and UNIQUEs are enforced
--     *** ON WRITE ***, so confirm the schema came back and that it
--     still rejects:
INFO FOR TABLE task;
--   then attempt a known violation and confirm the rejection.
SELECT state, count() FROM task GROUP BY state;
--   any state outside the allowed set means the ASSERT was not in
--   force during the import.

-- (5) PERMISSIONS RE-TESTED - they are SCHEMA, and schema comes back
--     from an export. *** RUN THE WHOLE DENIAL SUITE FROM MODULE
--     3. *** A restore that silently dropped a PERMISSIONS clause is
--     a tenancy breach, not a restore defect.

-- (6) A SAMPLE OF REAL QUERIES producing THE SAME RESULTS as before:
--     keep ten queries and their expected output as fixtures, and
--     diff.

-- *** AND TIME THE DRILL: ***
--   detect     ___ min      load       ___ min
--   decide     ___ min      verify     ___ min
--   provision  ___ min      resume     ___ min
--   *** TOTAL RTO ___ min ***    RPO: ___ (the source of record's
--                                          durability, not the
--                                          database's)
--
-- "The database is accepting queries" is NOT verification.

Discussion

No questions on this topic yet. Sign in to ask the first one.