Backing up the database
2 minute read
Requirements
- Please ensure that you have installed
pg_dump
on your machine.- For Windows users, installation of PostgreSQL
is required.
- Alternatively, you can use chocolatey to install it.
- Linux users can use their package manager to install it.
- For Windows users, installation of PostgreSQL
is required.
- We have observed that even small sites can have databases with more than 100GB of data, so please make sure that you have enough space on your machine to store the backup.
Backup
To store the backup, please follow the below steps:
Open a terminal and navigate to the folder where you want to store the backup.
Run the following command:
pg_dump -h <REMOTE_HOST> -p <REMOTE_PORT> -U factoryinsight -Fc -f <BACKUP_NAME>.bak factoryinsight
where:
<REMOTE_HOST>
is the hostname of the server where the database is running.<REMOTE_PORT>
is the port of the database (default is 5432).<BACKUP_NAME>
is the name of the backup file.
Restore
To restore the backup, we assume that you have a new stack running and the database is empty. Please follow the below steps:
Upload the database backup to the server where the database is running.
kubectl cp <BACKUP_NAME>.bak <timescaledb-pod>:/tmp/<BACKUP_NAME>.bak
Scale the
kafkatopostgres
deployment to 0.Click the Scale button to select the number of replicas for the Deployment.
Open a terminal inside the timescaledb pod
Delete the auto-generated database
DROP DATABASE factoryinsight;
Create a new database
CREATE DATABASE factoryinsight; \c factoryinsight CREATE EXTENSION IF NOT EXISTS timescaledb;
Put the database into timescale restore mode
SELECT timescaledb_pre_restore();
Restore the database
\! pg_restore -Fc -d factoryinsight /tmp/<BACKUP_NAME>.bak
Put the database back into normal mode
SELECT timescaledb_post_restore();
Further reading
For more information, please refer to the following resources: