Perception Database Backup
Introduction
This guide explains how to back up and restore the Perception deployment.
We’ll go through the following steps:
- Create a backup of your database inside the Docker container.
- Copy the backup file to your host machine.
- Restore the database from this backup if needed.
Create Backup
-
Create the backup file inside the Docker Container: Create a database dump in the database container of perception:
-
Copy the backup file to the host machine: After creating the backup file, copy it to the current directory on the host machine:
3. Backup the file to a safe location. We recommend a location on a different device. -
(Optional) Enable this backup as a cron job
Restore from Backup
To restore the database:
-
Copy the Backup File to the Docker Container:
-
Access the Docker Container’s Shell:
-
Connect to PostgreSQL and Prepare for Restoration:
-
Drop and Recreate the Database:
-
Run TimescaleDB Pre-Restoration Command:
-
Restore the Backup:
-
Finalize the Restore with TimescaleDB:
Code for Copy Paste
# Create backup
docker exec perception-database-server-1 pg_dump -U perception -Fc -f backup.bak perceptiondb
docker cp perception-database-server-1:/backup.bak .
# Restore from backup
docker cp backup.bak perception-database-server-1:/
docker exec -it perception-database-server-1 /bin/bash
psql -U perception perceptiondb
\c postgres
DROP DATABASE perceptiondb;
CREATE DATABASE perceptiondb;
SELECT timescaledb_pre_restore();
\! pg_restore -Fc -U perception -d perceptiondb backup.bak
SELECT timescaledb_post_restore();