SKEG · OPERATE

Backup and restore

Copy a stopped store, reopen a separate copy and check application data.

Skeg 0.8 · Development documentation

Use this procedure to create a backup and verify that a separate copy opens with the original Skeg version. Plan for downtime while you stop the server and copy the files. A running writer can change files while they are being copied.

The example uses a local store at ./application-data. Substitute your own paths. The commands assume a Unix-like shell and an operator who can read the store and preserve its file permissions.

1. Record what you will restore

Keep the following with the backup:

  • The Skeg executable or container image used to run the store. Record its version and retain a copy or a reference that identifies the exact artifact.
  • The complete data directory, including its shard layout.
  • The configuration file, startup flags, environment overrides and working directory. Record the effective shard count from the startup log.
  • The tenant authentication store and its quota sidecar, if configured.

For an authentication file named auth.kdb, the quota sidecar is auth.kdb.quotas. These may be outside the data directory. Include them from the same stopped state, and protect the backup as credential-bearing data. The sidecar can be absent when no limits have been saved. Record whether it exists; an unexpectedly missing file is a reason to investigate, not to assume the original deployment had no quotas.

Temporary indexes created with PERSISTENCE ephemeral are not restored as persistent indexes. Use a disk-backed durable index for data that must survive a writable restart.

Before stopping the server, record a few expected values from the application or from known test records. Include an updated record and a deleted ID. Use these values to check the restore in step 5.

2. Stop the server and check the result

Pause application writes. Stop the process using Ctrl+C, SIGTERM, or the service manager’s normal stop command. Let Skeg finish its shutdown sequence. Do not copy while the process is still draining requests or synchronising files.

Check the process’s exit status and shutdown logs. A non-zero exit or a forced kill does not certify a successful final sync. Investigate it before treating the directory as a clean stopped backup. See graceful shutdown for supervisor settings.

Keep the server stopped until all the files below have been copied. Pause scheduled restarts and other tools that could modify the data or auth files during the copy. Pausing client writes alone is insufficient: a running server can still perform background maintenance.

3. Copy the complete directory

Choose a new backup destination. These commands create a private parent directory for the copy.

mkdir -m 700 ./backup-example &&
  cp -a ./application-data ./backup-example/data

This creates a data directory inside the backup. Copy the whole store rather than selecting only vector files or recently changed segments. The && runs the copy only if creation of the new backup directory succeeded. If the path already exists, choose a fresh one rather than merging two backups.

If authentication files live outside the data root, copy those too. For example, for a server started with --tenant-auth ./auth/auth.kdb:

mkdir ./backup-example/auth && cp -a ./auth/auth.kdb ./backup-example/auth/

When the quota sidecar recorded in step 1 exists, copy it as well:

cp -a ./auth/auth.kdb.quotas ./backup-example/auth/

Check the exit status of each copy. A failed copy can leave a destination that looks complete but contains only some files. Keep it marked incomplete and repeat into a fresh destination after resolving the failure. Do not combine files from attempts taken across different server runs.

Before restarting the original server, compare the copied files with the stopped source. For the directory in this example:

diff -qr ./application-data ./backup-example/data

Expect exit status 0 and no output. Compare external authentication and quota files separately if you copied them. Check that the backup keeps the required permissions and ownership. Record the comparison before allowing writes again.

Store the backup on separate storage if it is meant to protect against loss of the source disk. An online filesystem copy without a documented consistency mechanism does not implement this procedure.

4. Reopen a copy in a new directory

Keep the backup unchanged. Restore into a new path so an unsuccessful check cannot alter your only backup:

mkdir -m 700 ./restore-check &&
  cp -a ./backup-example/data ./restore-check/data

Use the original Skeg executable. Set the shard count you recorded in step 1 so a different host’s automatic count cannot change the requested layout. The command below assumes the original store has one shard.

SKEG_SHARDS=1 skeg --data-dir ./restore-check/data --addr 127.0.0.1:6381

This example uses the default RESP listener in Skeg 0.8. For an authenticated store, restore the account file and any quota sidecar together into the exercise directory. Keep the sidecar beside the account file with the .quotas suffix. Set --tenant-auth to the restored file and preserve the original strict mode and admin-tenant settings. Use separate copies for every path the restore process may write.

If you use a configuration file, check the restore settings with skeg config check before starting. Confirm the restored paths and the loopback address in the startup log.

5. Check the application’s data

Connect a client to port 6381 and authenticate if needed. From an interactive RESP client, these commands check the listener, a known key, an index and a vector. Replace the example names and ID with ones you recorded before the backup.

PING
GET document:42
SKEG.VINDEX.INFO documents
SKEG.VGET documents 42

Expect PONG and compare the other replies with the source values. Use your application client to compare binary vectors and payloads.

CheckWhat to compare
Key-value recordsKeys and exact values, including empty values
Index metadataNames, dimensions, backend and persistence from SKEG.VINDEX.INFO
Stored vectorsKnown IDs and vectors read with SKEG.VGET
Payloads and filtersExpected metadata on known IDs and eligible rows in representative queries
Updates and deletesThe last saved value is present and deleted records still read as absent
Tenant boundariesThe expected account can read its data; another account cannot

Include recently updated and deleted records in your checks. Search results alone are not an inventory of the store, and a few successful queries are not a full integrity proof.

Separate three observations in your restore record: the files copied correctly, the original executable could open them, and the application’s expected records were present. Passing one check does not imply the others. Record how long the restore took as well, so your recovery plan includes the work before serving traffic.

Stop the restored server cleanly when the check is complete. For an actual recovery, direct application traffic to the checked instance only after it passes your restore criteria. Avoid sending writes to both the original and the restored store: Skeg does not replicate or reconcile them.

After a version change

For the conversion procedure and the authentication declarations needed to activate a converted store, follow Upgrade from Skeg 0.7 to 0.8.

Repeat the restore exercise when you change Skeg versions or deployment settings. Keep the pre-upgrade backup and its executable until you are satisfied with the new deployment. Reopening files with an older version is not a rollback procedure unless that version supports their format.