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:
-
Enables deletion protection and waits for the confirmation: the deletion prohibition is active and deletions already in progress have completed.
-
Takes a PostgreSQL snapshot and makes a full database dump with the standard
pg_dumputility in the custom format, and exports the PostgreSQL roles with their passwords, attributes and memberships from the same snapshot to an SQL script. Thepostgresservice role exists on any server, so the script includes neither the role itself, nor its password and attributes, nor any memberships involving it. -
Copies the S3 storage and Git repositories in full.
-
Verifies the dump and the copies, saves the recovery point and the Tengri version.
-
Lifts deletion protection.
-
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 |
|---|---|---|
|
|
Instance name. It is part of the default working directory path. |
|
|
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. |
|
|
Log level: |
|
|
Log format: |
|
|
Maximum duration of one run. |
|
none |
Tengri web server address. Required. |
|
none |
API token of a Tengri administrator account. Required. |
|
system certificates |
Trusted certificates file for the TLS connection to Tengri. |
|
|
PostgreSQL server address. |
|
|
PostgreSQL server port. |
|
|
Tengri database name. |
|
|
PostgreSQL superuser: exporting roles requires superuser privileges. |
|
none |
User password. Not needed for trusted local login. |
|
|
Directory with the |
|
|
Maximum duration of the dump. |
|
none |
S3 API address of the Tengri storage. Required. |
|
|
Tengri buckets copied in full. |
|
none |
S3 access keys allowed to read the buckets. Required. |
|
|
Number of parallel S3 copy threads. |
|
|
Tengri Git workspaces directories. Default: the |
|
none |
Backup storage address: |
|
none |
Backup set identifier in the backup storage: Latin letters, digits, |
|
none |
Backup encryption password, at least 9 characters. Required: unencrypted storages are not supported. |
|
|
Number of parallel upload threads. |
|
none |
Backup storage credentials, for example |
|
|
Remove outdated revisions after a backup. |
|
|
Revision retention rules in the |
|
|
Check the backup storage after a backup. |
|
|
Backup storage check interval. |
|
|
Perform a trial extraction during the check. |
|
|
Data size of the trial extraction. |
|
none |
Vault address. Required if |
|
none |
Vault token. Only |
|
|
Maximum duration of a Vault request. |
|
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 |
|---|---|
|
Value of the |
|
File contents with surrounding whitespace removed. The file size is at most 64 KB. |
|
The |
|
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 |
|---|---|---|
|
all |
Configuration file. Default: |
|
no command |
Parse and validate the configuration, resolve secrets, print the plan and exit without copying and without changes in Tengri. |
|
all |
Log level. Overrides |
|
all |
Do not show the progress indicator. |
|
no command, |
Save the run result to a JSON file. |
|
|
Check depth: |
|
|
Revision number. Default: the latest one. |
|
|
Empty directory to extract the revision to. It is created if missing. Required. |
|
no command |
Print the version and exit. |
|
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 |
|---|---|
|
Success. |
|
Some data was not copied, or the check found issues that do not prevent extraction. |
|
Configuration or command-line error. |
|
Backup storage error. |
|
The run was interrupted. |
|
Deletion protection could not be enabled or kept. |
|
The integrity check or trial extraction failed. |
Running a backup
-
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 -
Validate the configuration without copying:
sudo tengri-pile --dry-run -
Run the backup:
sudo tengri-pile --report /var/log/tengri-pile/last.json -
Make sure the command exits with code
0and 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.
-
Prepare an isolated system with the Tengri version shown for the revision by
tengri-pile listand with the deployment configuration of the original system. Do not start Tengri on it until the restore is complete. -
Extract the revision to an empty directory:
sudo tengri-pile extract --revision 42 --output /var/restore/tengriThe directory will contain the database dump
postgres/tengri.dump, the PostgreSQL rolespostgres/globals.sql, S3 objects in thes3/<bucket>/directory, Git repositories in thegit/directory and themanifest.jsonfile with the recovery point and the Tengri version. -
Restore the PostgreSQL roles and database on a clean PostgreSQL server that has neither the Tengri database nor any roles other than
postgresand the built-inpg_*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.dumpIf the command fails, do not continue the restore: fix the cause and repeat the step on a clean PostgreSQL server.
-
Set a new password for the
postgresrole 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 bytengri-pilewith this role, pointpostgres.passwordto a separate secret with the new password without changing the secret of the original system:sudo -u postgres psql --command '\password postgres' -
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 -
Copy the Git repositories from the
git/directory to the directories set ingit.paths. -
Set the original deployment master key in the
TENGRI_MASTER_KEYvariable (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
postgresservice 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 withGRANTif 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.