-
Notifications
You must be signed in to change notification settings - Fork 0
Database ‐ restore
This page describes the procedure to restore the SensorThings database (PostgreSQL / TimescaleDB) from a backup file.
ATTENTION
Database restore operations are destructive and irreversible. Always verify that you are restoring the correct backup into the correct environment (local vs server).
A database restore may be required in the following situations:
- Recovery after data corruption or accidental deletion
- Migration to a new server or environment
- Reproducing a production state in a local or test environment
Before starting the restore process, ensure that:
- You have the backup file to restore (
.bak) - You have access to the host where SensorThings is running
- You have permission to modify the database and API credentials
- You know whether the restore is being performed in:
- a local/development environment, or
- the OBSEA/production environment
Locate the backup file you want to restore:
ls *.bakExample:
sensorthings_20260109_083347.bakBefore executing the restore script, database credentials must be configured.
The restore script (sensorthings_restore.sh) must use the same credentials that are defined in secrets.env:
Example configuration:
DB_NAME="sensorthings"
DB_USER="sensorthings"
DB_HOST="localhost" # Use the appropriate host (e.g. docker host or server IP)
DB_PORT="${PGPORT:-5432}" # Default PostgreSQL port
DB_PASSWORD="password" # Set your database passwordIMPORTANT These values must be adapted to your environment before running the script.
Execute the restore script, passing the backup file as argument:
./sensorthings_restore.sh sensorthings_20260109_083347.bakDuring execution:
- The database structure and data are restored
- The script will ask for confirmation before proceeding
After restoring the database, it must be registered again in pgAdmin.
Open pgAdmin and register a new server:
-
Name: any name you want (e.g.
sensorthings3) - Go to the Connection tab and set:
- Host name/address: your database host (e.g. localhost, Docker IP, or server IP)
- Port:
5432 - Maintenance database:
sensorthings - Username:
sensorthings - Password: value from
secrets.env(DB_PASSWORD)
Click Save.

Registering a new database server in pgAdmin.
Here you can choose any name for the connection (for example: sensorthings3).

Configuring the database connection parameters.
Fill in the host, port, database name and credentials using the values defined in secrets.env.
After registering the database server in pgAdmin, API users must be updated
to match the credentials defined in secrets.env.
Navigate to:
- Double-click on the registered server (e.g.
sensorthings3) - Databases
sensorthings- Schemas
public- Tables
USERS
Right-click on the USERS table and select:
View/Edit Data → All Rows

You should see users such as:
admininjectorreadonly

For each user, update the password so that it matches the values defined in
secrets.env:
# API read-only user
STA_API_READ_USER=readonly
STA_API_READ_PASSWORD=password
# API write user
STA_API_WRITE_USER=injector
STA_API_WRITE_PASSWORD=password
# API administrator
STA_API_ADMIN_USER=admin
STA_API_ADMIN_PASSWORD=passwordClick on the password field for each user, update the value, and save the changes using the database save icon in pgAdmin.