Data backup

This page describes how Tengri data backup works, how to install and configure the tengri-pile backup tool, how to run it, verify backups and restore data from them.

Overview

Tengri data is stored in three places:

  • the PostgreSQL database — application tables, the Iceberg catalog, the audit log, the schema and sequences;

  • the S3 object storage — Iceberg table files;

  • local Git repositories — see Working with Git.

A backup is created by the separate tengri-pile backup tool that saves all three stores in full. Tengri itself does not create archives: during the copy it only prohibits physical deletion of objects in S3, so that the files referenced by the database copy do not disappear. The copy is made without stopping the system: users keep reading and writing data.

Recovery point

The PostgreSQL database is the source of truth. The recovery point is the moment of the snapshot from which the database dump is taken, not the time the copy finishes. The backup includes only transactions committed by that moment.

The S3 storage and Git repositories are copied in full, without selecting individual table versions or filtering history. The backup may therefore contain data newer than the recovery point, but after restore only the state referenced by the database is visible.

Deletion protection

During a backup, Tengri prohibits physical deletion of S3 objects. The prohibition applies to all Tengri processes and to all physical deletion paths: cleanup of old snapshots and orphan files, dropping tables with data cleanup, bulk operations. The prohibition survives a server restart. If a backup is interrupted, the prohibition is lifted automatically when it expires, so a failure does not disable storage cleanup forever.

The prohibition does not block regular database work and does not protect Git repositories. Only administrators can enable and lift the prohibition, and all actions are logged.

Backup procedure

On every run, tengri-pile performs the following steps:

  1. Enables deletion protection and waits for the confirmation: the deletion prohibition is active and deletions already in progress have completed.

  2. Takes a PostgreSQL snapshot and makes a full database dump with the standard pg_dump utility in the custom format, and exports the PostgreSQL roles with their passwords, attributes and memberships from the same snapshot to an SQL script. The postgres service role exists on any server, so the script includes neither the role itself, nor its password and attributes, nor any memberships involving it.

  3. Copies the S3 storage and Git repositories in full.

  4. Verifies the dump and the copies, saves the recovery point and the Tengri version.

  5. Lifts deletion protection.

  6. Uploads the backup to the backup storage, removes outdated revisions according to retention rules and checks the storage when due.

Deletion protection is extended throughout the whole backup, including the dump. If the deletion protection is lost before the S3 copy finishes, the backup attempt is considered failed.

Backup tool

The tengri-pile backup tool:

  • runs the procedure above automatically, including on a schedule;

  • saves backups to a separate cloud backup storage independent of the source S3;

  • encrypts backups, keeps several revisions and removes outdated ones according to retention rules;

  • verifies a backup without modifying it and by a trial restore in an isolated environment;

  • is configured with a TOML file and reads secrets from environment variables, files or the Vault secrets storage;

  • reports the result in a machine-readable form and does not write secrets to logs.

Installation

Install the tengri-pile package on a server that can reach the PostgreSQL database, the S3 storage and the Tengri Git workspaces directory:

sudo apt install tengri-pile

The package installs the /usr/bin/tengri-pile executable, the /etc/tengri-pile/main.toml.example sample configuration, the /var/lib/tengri-pile working directory and the /var/log/tengri-pile reports directory. The PostgreSQL client utilities pg_dump and pg_restore of the same major version as the database server are required.

Configuration file

tengri-pile is configured with a TOML file. By default, the /etc/tengri-pile/main.toml file is read; another path is set with the --config option.

Parsing rules:

  • an unknown key in any section is a configuration error, and the backup does not start;

  • durations are strings with a unit: '30s', '10m', '6h';

  • sizes are strings with a suffix: '512K', '256M', '4G';

  • passwords, keys and tokens are set with secret references, see Secret references.

Sample configuration:

[global]
  instance = 'main'
  work_dir = '/var/lib/tengri-pile/main'
  log_level = 'info'
  log_format = 'text'
  timeout = '12h'

[tengri]
  url = 'https://tengri.example.com'
  token = 'vault:secret/tengri-pile/tengri-token'
  ca_file = '/etc/ssl/certs/tengri-ca.pem'

[postgres]
  host = '127.0.0.1'
  port = 5432
  database = 'tengri'
  user = 'postgres'
  password = 'vault:secret/tengri-pile/pg-password'
  bin_dir = '/usr/lib/postgresql/17/bin'
  timeout = '6h'

[s3]
  endpoint = 'http://127.0.0.1:9002'
  buckets = ['prostore']
  access_key = 'vault:secret/tengri-pile/s3-access-key'
  secret_key = 'vault:secret/tengri-pile/s3-secret-key'
  threads = 4

[git]
  paths = ['~tengri/.local/tengri-workspaces']

[storage]
  url = 's3://backup.example.com/tengri-backups/prod'
  snapshot_id = 'tengri-prod'
  password = 'vault:secret/tengri-pile/storage-password'
  threads = 4
  [storage.keys]
    s3_id = 'vault:secret/tengri-pile/backup-s3-id'
    s3_secret = 'vault:secret/tengri-pile/backup-s3-secret'

[prune]
  enabled = true
  keep = ['0:365', '30:90', '7:30', '1:7']

[check]
  enabled = true
  every = '168h'
  test_restore = true
  test_restore_bytes = '256M'

[vault]
  address = 'https://vault.example.com:8200'
  token = 'file:/etc/tengri-pile/vault-token'
  timeout = '30s'
  ca_file = '/etc/ssl/certs/vault-ca.pem'

Configuration parameters:

Parameter Default Description

global.instance

'main'

Instance name. It is part of the default working directory path.

global.work_dir

'/var/lib/tengri-pile/<instance>'

Working directory for the dump and copies before they are uploaded to the backup storage. It needs free space of at least the Tengri data size.

global.log_level

'info'

Log level: debug, info, warn, error.

global.log_format

'text'

Log format: text or json.

global.timeout

'12h'

Maximum duration of one run.

tengri.url

none

Tengri web server address. Required.

tengri.token

none

API token of a Tengri administrator account. Required.

tengri.ca_file

system certificates

Trusted certificates file for the TLS connection to Tengri.

postgres.host

'127.0.0.1'

PostgreSQL server address.

postgres.port

5432

PostgreSQL server port.

postgres.database

'tengri'

Tengri database name.

postgres.user

'postgres'

PostgreSQL superuser: exporting roles requires superuser privileges.

postgres.password

none

User password. Not needed for trusted local login.

postgres.bin_dir

'/usr/bin'

Directory with the pg_dump and pg_restore utilities.

postgres.timeout

'6h'

Maximum duration of the dump.

s3.endpoint

none

S3 API address of the Tengri storage. Required.

s3.buckets

['prostore']

Tengri buckets copied in full.

s3.access_key, s3.secret_key

none

S3 access keys allowed to read the buckets. Required.

s3.threads

4

Number of parallel S3 copy threads.

git.paths

['~tengri/.local/tengri-workspaces']

Tengri Git workspaces directories. Default: the .local/tengri-workspaces directory in the home directory of the tengri user that runs Tengri. A path of the form ~NAME/…​ is relative to the home directory of the NAME user.

storage.url

none

Backup storage address: s3://, b2://, sftp:// or a path to a storage mounted from another server. Required. Do not place the backup storage on the Tengri server: if it fails, both the data and the backups are lost.

storage.snapshot_id

none

Backup set identifier in the backup storage: Latin letters, digits, _ and -. Required.

storage.password

none

Backup encryption password, at least 9 characters. Required: unencrypted storages are not supported.

storage.threads

4

Number of parallel upload threads.

storage.keys

none

Backup storage credentials, for example s3_id and s3_secret for s3://.

prune.enabled

true

Remove outdated revisions after a backup.

prune.keep

[]

Revision retention rules in the 'n:m' format: for revisions older than m days keep one every n days; '0:m' removes all revisions older than m days. Rules are listed in descending order of m.

check.enabled

true

Check the backup storage after a backup.

check.every

'168h'

Backup storage check interval.

check.test_restore

true

Perform a trial extraction during the check.

check.test_restore_bytes

'256M'

Data size of the trial extraction.

vault.address

none

Vault address. Required if vault: references are used.

vault.token

none

Vault token. Only env: and file: references are allowed.

vault.timeout

'30s'

Maximum duration of a Vault request.

vault.ca_file

system certificates

Trusted certificates file for the TLS connection to Vault.

Secret references

Passwords, keys and tokens are set in the configuration as references, not values:

Format Value

env:NAME

Value of the NAME environment variable. An empty value is a configuration error.

file:PATH

File contents with surrounding whitespace removed. The file size is at most 64 KB.

vault:MOUNT/PATH/KEY

The KEY key of the PATH secret from the KV version 2 storage mounted in Vault as MOUNT.

plain:VALUE

The value as is. Only for non-confidential parameters.

A string without a prefix is treated as a plain: reference, and a warning is written to the log. Secrets are resolved once before the run starts and never get into logs or the final report. Secrets cannot be passed as command-line options.

Command-line options

tengri-pile [OPTIONS]
tengri-pile verify [OPTIONS]
tengri-pile list [OPTIONS]
tengri-pile extract --output DIRECTORY [OPTIONS]

Without a command, tengri-pile performs a backup. The verify command checks the backup storage, list lists revisions, extract extracts a revision to a local directory.

Option Commands Description

--config PATH

all

Configuration file. Default: /etc/tengri-pile/main.toml.

--dry-run

no command

Parse and validate the configuration, resolve secrets, print the plan and exit without copying and without changes in Tengri.

--log-level LEVEL

all

Log level. Overrides global.log_level.

--no-progress

all

Do not show the progress indicator.

--report PATH

no command, verify

Save the run result to a JSON file.

--level LEVEL

verify

Check depth: storage — storage structure and integrity, restore — trial extraction, artifacts — dump and copies check, all — all of the above. Default: all.

--revision NUMBER

verify, extract

Revision number. Default: the latest one.

--output DIRECTORY

extract

Empty directory to extract the revision to. It is created if missing. Required.

--version

no command

Print the version and exit.

--help

no command

Print help and exit.

Command-line option values take precedence over the configuration file. Parameters not set by options are taken from the configuration file or defaults; environment variables do not override them.

Exit codes

Code Meaning

0

Success.

1

Some data was not copied, or the check found issues that do not prevent extraction.

2

Configuration or command-line error.

3

Backup storage error.

4

The run was interrupted.

5

Deletion protection could not be enabled or kept.

6

The integrity check or trial extraction failed.

Running a backup

  1. Create the configuration file from the sample and set your addresses and secret references in it:

    sudo cp /etc/tengri-pile/main.toml.example /etc/tengri-pile/main.toml
    sudo chmod 600 /etc/tengri-pile/main.toml
  2. Validate the configuration without copying:

    sudo tengri-pile --dry-run
  3. Run the backup:

    sudo tengri-pile --report /var/log/tengri-pile/last.json
  4. Make sure the command exits with code 0 and the report file contains the revision number, the recovery point and the Tengri version.

Only one run with the same configuration can be active at a time: a run started while the previous one is still running fails.

Scheduled runs

For a daily backup, add a cron job, for example to the /etc/cron.d/tengri-pile file:

30 1 * * * root /usr/bin/tengri-pile --no-progress --report /var/log/tengri-pile/last.json

A cron job does not have the environment variables of an interactive session, so use file: or vault: secret references for scheduled runs.

Verifying a backup

The check does not modify the backup storage. It runs automatically after a backup every check.every, and can be started manually with:

sudo tengri-pile verify --level all --report /var/log/tengri-pile/verify.json

To list revisions with the recovery point and Tengri version of each, run:

sudo tengri-pile list

Restore

The restore covers the PostgreSQL roles with the psql utility, the PostgreSQL database with the pg_restore utility, the S3 storage and Git repositories. All parts are restored from the same backup, while a compatible Tengri version and the deployment configuration of the original system are prepared on the system in advance.

  1. Prepare an isolated system with the Tengri version shown for the revision by tengri-pile list and with the deployment configuration of the original system. Do not start Tengri on it until the restore is complete.

  2. Extract the revision to an empty directory:

    sudo tengri-pile extract --revision 42 --output /var/restore/tengri

    The directory will contain the database dump postgres/tengri.dump, the PostgreSQL roles postgres/globals.sql, S3 objects in the s3/<bucket>/ directory, Git repositories in the git/ directory and the manifest.json file with the recovery point and the Tengri version.

  3. Restore the PostgreSQL roles and database on a clean PostgreSQL server that has neither the Tengri database nor any roles other than postgres and the built-in pg_* roles:

    sudo -u postgres psql --set ON_ERROR_STOP=1 --file /var/restore/tengri/postgres/globals.sql \
      && sudo -u postgres pg_restore --create --dbname postgres /var/restore/tengri/postgres/tengri.dump

    If the command fails, do not continue the restore: fix the cause and repeat the step on a clean PostgreSQL server.

  4. Set a new password for the postgres role that differs from the original one, and if Tengri connects to PostgreSQL with this role, replace the password in the deployment configuration as well before starting Tengri; if the restored server will be backed up by tengri-pile with this role, point postgres.password to a separate secret with the new password without changing the secret of the original system:

    sudo -u postgres psql --command '\password postgres'
  5. Upload the objects to empty buckets of the S3 storage at the original addresses, for example with the AWS CLI. Pass access keys allowed to write to the buckets to the client in environment variables:

    export AWS_ACCESS_KEY_ID='ACCESS_KEY'
    export AWS_SECRET_ACCESS_KEY='SECRET_KEY'
    aws s3 sync /var/restore/tengri/s3/prostore s3://prostore --endpoint-url http://127.0.0.1:9002
  6. Copy the Git repositories from the git/ directory to the directories set in git.paths.

  7. Set the original deployment master key in the TENGRI_MASTER_KEY variable (see Configuring settings via environment variables) and start Tengri.

Keep in mind when restoring:

  • the original S3 addresses must point to the restored storage: automatic relocation of Iceberg tables to other buckets or paths is not provided;

  • Git repositories are restored without contacting the original remote repository;

  • encrypted fields stay encrypted, and the deployment master key (TENGRI_MASTER_KEY) is not included in the backup: it is kept separately in a secure storage and provided at restore; restore with a new master key is not supported;

  • the deletion protection state copied into the backup does not block cleanup on the restored system;

  • the postgres service role is not restored from the backup: on the restored server it stays a superuser with the attributes set at the initialization of the clean server, and memberships involving it granted on the original server are not transferred: grant them again with GRANT if needed;

  • the restored system is isolated from the original one: the backup keeps the old credentials, and password changes and revoked privileges after the recovery point are missing from it.

Requirements and limitations

  • During the copy, the infrastructure must exclude deletion of S3 objects bypassing Tengri, S3 lifecycle rules and object overwrites.

  • The backup tool ensures the integrity of Git repositories by its own means: deleting a repository or garbage collection during the copy can remove a needed commit, and without a consistent Git copy a full restore is not guaranteed.

  • Mutable intermediate files and job results are not captured as of the recovery point.

  • The database snapshot does not make atomic the application operations spanning several transactions or writes to different stores.

  • Long deletion protection delays freeing space in S3, and a long dump holds old PostgreSQL row versions, so spare disk space is required.

  • A backup contains the whole history and unused S3 objects, so it may take more space than the current data.

  • Access to backups is restricted in the same way as access to the source data.