On this page
Backup and restore
Restore the database, object storage, digital employee workspaces, and secrets together. Compose and Kubernetes store data in different locations. Backing up the installation package or images alone is insufficient.
These procedures require data directory access on the target host or workload and storage management permissions on the cluster. Set a time to stop writes before backing up. If writes to databases, files, or workspaces continue, the backups may capture different points in time.
Compose: Back up directories after stopping writes
Except for digital employee workspaces, these paths are relative to the root of the installed Compose package.
| What to retain | Default location |
|---|---|
| Installation configuration and secrets | config.env, .secrets, host/.env, and infrastructure/master/.env. |
| PostgreSQL, Redis, LDAP, and Garage data | infrastructure/master/volumes/. |
| Persistent application data, including messaging data if enabled | host/volumes/. |
| Digital employee workspaces and runtime state | /var/lib/tego/claw-state/. If AVATAR_VOLUME_HOST_PATH was changed, use the actual mount path. |
| Matching application version | The installed release package, manifest.json, and image archives. |
Record the installation directory, package version, and actual data paths. Back up external PostgreSQL, Redis, S3, and LDAP through their own services. The local directories do not contain that data.
Run the following command from the Compose package root to stop and remove application, bundled infrastructure, and managed runtime containers:
bashsudo ./setup.sh uninstallCopy or archive the configuration, secrets, and data directories in the table to a separate backup location. Preserve file ownership, permissions, and directory structure. Store secret files under access control.
After backing up, run
sudo ./setup.sh installto restore service. Verify sign-in, file reads, and a digital employee task.
Do not use --purge or clean.sh here. They delete managed data and secrets. A standard uninstall still runs Compose down -v: Standard bind-mounted data directories remain, but back up custom named volumes separately first.
Kubernetes: Back up databases, storage, and the cluster separately
| Data | Location and backup method |
|---|---|
| Installation configuration | /opt/tego-os/config.env on Node1, or tego-os/config.env under DATA_ROOT if set. |
| Three PostgreSQL databases | POSTGRES_DB, TEGO_MCP_DB, and TEGO_KB_DB, which default to tego-os, tego-mcp, and tego-kb. Run pg_dump -Fc for each. |
| Digital employee workspaces | PVCs in tego-avatar-runtime. Use Longhorn backups for the volume data. |
| Messaging data | If the bundled messaging service is enabled, the data-tego-avatar-im-0 PVC in the tego-avatar application namespace. |
| Object storage and identity services | Back up the actual bundled or external service. Database dumps and etcd snapshots do not contain this data. |
| K3s cluster state | Use snapshots with embedded etcd. For default single-node SQLite, back up the data directory. Retain the K3s server token. |
The knowledge base database stores content, chunks, vectors, and embedded media. Do not add --no-blobs when backing it up. The current version does not use the /opt/maxkb persistent volume for this data.
Back up the databases
Run as root on Node1. The commands use a temporary utility Pod as described in the package's OPERATIONS.md and work with the included PostgreSQL 17 image. For an external database, use a client image compatible with that database version.
If the old configuration is in a different location, update the source line first. Stop the affected application writes during the maintenance window and run:
bash <<'BASH'
set -euo pipefail
source /opt/tego-os/config.env
backup_dir="$(mktemp -d /var/backups/tego-db.XXXXXXXX)"
backup_pod="tego-pgdump-$(date +%s)-$$"
kubectl -n tego-avatar run "$backup_pod" \
--image=pgvector/pgvector:pg17 --image-pull-policy=Never \
--restart=Never --env="PGPASSWORD=$POSTGRES_PASSWORD" \
--command -- sleep 900
trap 'kubectl -n tego-avatar delete pod "$backup_pod" --ignore-not-found >/dev/null' EXIT
kubectl -n tego-avatar wait --for=condition=ready \
"pod/$backup_pod" --timeout=120s
for db in "$POSTGRES_DB" "${TEGO_MCP_DB:-tego-mcp}" "${TEGO_KB_DB:-tego-kb}"; do
kubectl -n tego-avatar exec "$backup_pod" -- \
pg_dump -Fc -h "$POSTGRES_HOST" -p "${POSTGRES_PORT:-5432}" \
-U "$POSTGRES_USER" -d "$db" > "$backup_dir/$db.dump"
test "$(head -c 5 "$backup_dir/$db.dump")" = PGDMP
kubectl -n tego-avatar exec -i "$backup_pod" -- \
pg_restore --list < "$backup_dir/$db.dump" >/dev/null
done
printf '数据库备份目录:%s\n' "$backup_dir"
BASHThe command creates a temporary Pod, dumps the three databases, and checks that the archive listings are readable. On failure, it stops immediately, retains any archives already produced, and deletes the utility Pod. Archive checks do not replace a restore drill in an isolated environment.
Do not use kubectl run --rm -i ... > dump instead. It may miss the beginning of the archive due to attachment timing. This procedure uses kubectl exec in an existing Pod without allocating a TTY.
During upgrades, upgrade.sh automatically exports all three databases and retains the pre-upgrade configuration, merged configuration, and Helm records. It does not replace routine backups or capture object storage, Longhorn volumes, or the K3s token.
Back up cluster state and persistent volumes
For an embedded etcd cluster, create and list snapshots on Node1:
sudo k3s etcd-snapshot save
sudo k3s etcd-snapshot lsCopy snapshots off the cluster and retain /var/lib/rancher/k3s/server/token with them. For a custom K3s data directory, use that directory's server/token. The default single-node SQLite setup does not use these etcd commands.
In the upgrade backup directory, etcd-snapshot.log records only the snapshot command result. The snapshots remain on the node. Longhorn local snapshots and retained replica directories do not replace off-cluster backups. They do not establish that a rebuilt cluster can reclaim the old volumes.
Restore order
- Stop application and digital employee writes in the affected environment. Retain the incident state and the original backups.
- Restore the configuration and secrets that match the backup. For Compose, restore
.secretsand both.envfiles together. For Kubernetes, use the oldconfig.envfrom the backup. - Restore the databases, object storage, identity and messaging data, and digital employee workspaces to the chosen point in time. Use
pg_restorefor PostgreSQL custom archives. If a restore fails, stop without starting the application. - Restore the matching application version. For Compose, preserve the original paths and permissions and run
sudo ./setup.sh install. For Kubernetes, use the Helm release and storage recovery records from the backup. Do not use a new package's empty configuration to generate new secrets. - Verify sign-in, existing files, knowledge retrieval, message history, and a digital employee task before resuming scheduled tasks and external deliveries.
If messaging data was restored to an earlier point in time, increment IM_DATA_EPOCH in config.env by one and apply the configuration using the deployment method. This forces clients to synchronize again. If the setting was not configured previously, use IM_DATA_EPOCH=2 for the restore.
A restore overwrites data in the target environment and does not retain writes made after the backup. Historical keys must match the encrypted data. Do not generate random keys to resolve decryption failures. Check separately whether external messages or business operations have already occurred.
See Upgrade and rollback for upgrade recovery and Log troubleshooting to find the cause of an issue.