Backup restore
This section contains scripts to backup and restore your postgres and clickhouse databases. It is compatible with a docker based installation, but can be adapted to work with bare metal setups.
1. Backup and Restore the postgres Database
Run these scripts from directory that contains the
docker-compose.ymlfile.
1.1 Backup postgres
KAWA Postgres database contains all the state of the application - dashboards, applications, sheets, datasources, views, etc... It also contains user accounts if using KAWA's internal authentication mechanism.
#!/bin/bash
DOCKER_CONTAINER_NAME="postgres"
DUMP_DIR="/tmp"
KAWA_COMPOSE_DIR="$PWD"
EXCLUDED_TABLE="application_event"
DB_USER="kawa"
DB_NAME="postgres"
TIMESTAMP=$(date +%Y-%m-%d)
DUMP_FILE="$DUMP_DIR/kawa-db-$TIMESTAMP.sql"
TAR_FILE="$DUMP_DIR/kawa-db-$TIMESTAMP.tar.gz"
mkdir -p "$DUMP_DIR"
echo "1️⃣ Starting database dump to $DUMP_FILE..."
if sudo docker compose exec "$DOCKER_CONTAINER_NAME" \
pg_dump -U "$DB_USER" "$DB_NAME" --exclude-table-data="$EXCLUDED_TABLE" > "$DUMP_FILE"; then
echo "✅ Database dump completed successfully."
else
echo "❌ Database dump failed." >&2
exit 1
fi
echo "2️⃣ Compressing dump to $TAR_FILE..."
if tar -czf "$TAR_FILE" -C "$DUMP_DIR" "$(basename "$DUMP_FILE")"; then
echo "✅ Compression successful: $TAR_FILE"
rm -f "$DUMP_FILE"
else
echo "❌ Compression failed." >&2
exit 1
fi1.2 Restore the postgres database
2. Backup and Restore the clickhouse Database
In order to backup and restore a clickhouse database, we use the native BACKUP and RESTORE utilities from Clickhouse.
Connect to your clickhouse database with a SQL client:
To restore a database:
The backups will be generated in the assets/backup directory of your docker compose install folder. Please refer to https://clickhouse.com/docs/operations/backup for additional configuration options and details.
Last updated
Was this helpful?

