Skip to content

Recover your data

This page explains which backup procedure applies to your deployment, the database locations to back up and their schedule, how to safely recover IDB and HDB data from backups, and how to create and restore full database snapshots.

Overview

In general, kdb+ databases are stored as ordinary filesystem files and directories rather than in a proprietary database container format. This makes handling databases straightforward, because you can back them up with standard filesystem utilities such as rsync.

The method of backup and recovery is up to you. However, key considerations for any backup are resource contention on the server and the timing of backup procedures. For example, the contents of the HDB change at least once a day during EOD, so if a daily backup of the HDB takes more than 24 hours, it may cause unexpected issues.

A restore also depends on state that's kept outside the database, such as the EMS logs that hold data received since the last EOI, and the etcd discovery registry. How you protect that state depends on your deployment:

Deployment EMS implementation Backup procedure
Single-node TP+ Follow Back up and restore a single-node system, which covers the database, TP+ logs, operational data, and etcd registry as one consistent backup set.
Multi-node RT with Raft replication Back up the database as described on this page. See Multi-node systems for what replication covers.

Back up the database

The following table outlines the database locations to back up and their recommended schedule. On a single-node system, back up these locations as part of the full backup set in Back up and restore a single-node system.

Directories Contents Recommended schedule
$KXS_ROOT KX Sensors installation and configuration files. After installation, upgrade, or configuration change.
hdbDir (default ${KXS_ROOT}/db/hdb) Historical database. If you use tiered storage, also back up each tier's directory, as set in hdbTiers.yaml. After EOD completes.
idbDir (default ${KXS_ROOT}/db/idb) Intraday data, a full copy of master data, and the sym file. After EOI completes.
KXS_LOG_DIR (default ${KXS_ROOT}/logs) Log files. Daily, avoiding EOD and log cutover.

hdbDir and idbDir are system parameters in systemParams.yaml, and KXS_LOG_DIR is an environment variable in kxsenv. Check the values in your deployment, and back up each location wherever it's set. Any of them can be outside $KXS_ROOT, in which case a backup of $KXS_ROOT doesn't include it.

Multi-node systems

On a multi-node system, RT replicates each EMS stream across the three nodes by using Raft, and etcd replicates the discovery registry across three members. If the disk on one node fails, the stream data and the registry are still held by the other nodes, so you don't lose them.

If you lose two nodes of a three-node cluster, the surviving node can't continue on its own, because Raft needs a majority. You have the option to follow Disaster recovery to switch the cluster to run on the surviving node, and to return it to three nodes once the lost nodes are back online. That procedure discards RT data received since the last EOI rather than restoring it from a backup, and it currently supports only three-node clusters. Choose it if restoring service on a single node is more important than retaining the RT data by recovering the lost nodes, or if you know the lost nodes can no longer be restored with disk intact.

This documentation doesn't cover restoring the RT logs, RT state, or etcd registry of a multi-node cluster from a backup. The single-node procedure doesn't apply: don't copy a backup of emsLogDir or of the etcd data directory into a multi-node cluster, because a restored copy can conflict with the cluster's Raft state and member identity. The etcd disaster recovery guide describes restoring an etcd cluster from a snapshot, but restoring the registry alone doesn't recover a KX Sensors cluster. Contact KX Support for these scenarios.

Recover your data

Recover your data carefully so that the directory structures within IDB and HDB stay intact. Restore the IDB and HDB directories from the same backup date. Otherwise, the database has mismatches. Symlinks contain absolute paths to their targets, so recover to the same paths that the backup was taken from. Some copy tools follow symlinks and replace each link with a copy of its target. This leaves you with a broken database that has duplicate data and no symlinks. Copy with a tool that keeps symlinks, such as rsync -aH.

To recover to a different location, re-root the database as described in Move your database.

To recover a single-node system after a disk failure, see Recover after a disk failure.

Database snapshot creation and restoration

This chapter describes how to create a snapshot of an existing KXS database and how to restore it to a fresh installation. The procedure is intended for development and testing purposes and not production environments.

Create a database snapshot

Note

It's recommended to avoid taking the database snapshot during an EOD. Doing so during an EOD is harmless, but results in larger snapshots as transient files will be included.

  1. Stop ingestion to the system.
  2. From a maintenance console, manually invoke an EOI to ensure all in-flight data is written to disk.

    kxsctl mc issueEOI
    
    q).db.initPurview[]
    q).db.requestWD`rdb
    
  3. Stop the system using kxsctl stop system.

  4. Manually update the pos column in the IdbStatus table to 0N within your database from a maintenance console.

    Note

    This step is appropriate for restoring the snapshot to new installation. This step is not appropriate if the intent is to leave the source system in place and operational after taking the snapshot. In that case, updating the pos columns should be done to a copy of the database from a raw q session.

    [app@kxsd01 ~]$ kxsctl mc maint
    q){p set update pos:0N from get p:` sv .cfgp.idbDir,`data,x}each`IdbStatus.0`IdbStatus.1
    
  5. Copy (or move if disk space is limited) the database directory to a backup location on your filesystem.

The snapshot is complete and can be restored to a fresh installation. See steps in the following section.

Note

This snapshot must be moved/copied back to the exact original file path to ensure all sym links within the database are restored correctly. Make note of this location to ensure your system parameters for the IDB/HDB point to the same location in the fresh installation. As long at the database roots remain the same, the snapshot can be used on other servers as well.

Restore a database snapshot

  1. Perform an installation using the KXS installer.

    Note

    If an environment already exists on the server, uninstall it first.

  2. Copy the snapshot from the backup location to the configured database directory.

    Note

    The installer automatically creates empty directories db/hdb and db/idb; delete these before restoring the snapshot.

    [app@kxsd01 kxs]$ rm -rf /data/app/kxs/db
    [app@kxsd01 kxs]$ cp -r /data/app/backup/db /data/app/kxs/db
    
  3. Start a MAINT console and run the following commands to initialize the discovery registry. These objects are typically initialized by DBW the first time a system is being started or during a v2 to v3 upgrade; we run them manually here. These commands should only be run in this context.

    kxsctl mc initDisc
    
    q).disc.putSys[`haState;::;.schema.getTable0`HaState;0]; / HA system state
    q).disc.putSys[`purview;::;.schema.getTable0`Purview;0]; / Database purview
    q).disc.putSys[`loci;::;.schema.getTable0`Loci;0]; / Data presence loci
    

At this point, the snapshot has been successfully restored and the system is ready to start using kxsctl start system.

Next steps