Update Postgres backup and restore scripts

This commit is contained in:
Simon Larsen 2024-03-17 11:46:32 +00:00
parent 9cf2ae4326
commit e7bbe30a88
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
3 changed files with 9 additions and 9 deletions

View File

@ -32,19 +32,16 @@ This will make the database accessible from the localhost:5432.
### Postgres Backup
Please make sure you have `pg_dump` and `pg_restore` installed on your local machine.
To take a backup of the database, use the following command:
Please fill the values in config.env file and run the following command to take the backup of the database.
```
# Source Database. This will prompt for the password
pg_dump --host=<source_port> --port=<target_port> --username=<source_username> --password --dbname=oneuptimedb --file=oneuptime.sql
./backup.sh
```
### Postgres Restore
To restore the database, use the following command:
Please fill the values in config.env file and run the following command to restore the database.
```
# Target Database. This will prompt for the password
pg_restore --host=localhost --port=5432 --username=<target_username> --dbname=oneuptimedb --password --file=oneuptime.sql
./restore.sh
```

View File

@ -119,6 +119,7 @@ SUBSCRIPTION_PLAN_SCALE=Scale,priceMonthlyId,priceYearlyId,0,0,3,0
SUBSCRIPTION_PLAN_ENTERPRISE=Enterprise,priceMonthlyId,priceYearlyId,-1,-1,4,14
# If you want to run the backup script, then you need to fill these values.
DATABASE_BACKUP_DIRECTORY=/Backups
DATABASE_BACKUP_HOST=localhost
DATABASE_BACKUP_PORT=5400
@ -127,8 +128,9 @@ DATABASE_BACKUP_USERNAME=postgres
DATABASE_BACKUP_PASSWORD=${DATABASE_PASSWORD}
# If you want to run the restore script, then you need to fill these values. Use host.docker.internal if you want to use the host machine's IP.
DATABASE_RESTORE_HOST=host.docker.internal
DATABASE_RESTORE_DIRECTORY=/Backups
DATABASE_RESTORE_HOST=localhost
DATABASE_RESTORE_PORT=5400
DATABASE_RESTORE_NAME=oneuptimedb
DATABASE_RESTORE_USERNAME=postgres

View File

@ -17,6 +17,7 @@ git pull
sudo docker run --net=host --rm \
--env-file config.env \
--add-host=host.docker.internal:host-gateway \
--volume=$(pwd)$DATABASE_RESTORE_DIRECTORY:/var/lib/postgresql/data \
postgres:latest /usr/bin/pg_restore --dbname=postgresql://$DATABASE_RESTORE_USERNAME:$DATABASE_RESTORE_PASSWORD@$DATABASE_RESTORE_HOST:$DATABASE_RESTORE_PORT/$DATABASE_RESTORE_NAME /var/lib/postgresql/data/$DATABASE_RESTORE_FILENAME