diff --git a/HelmChart/Docs/Postgres.md b/HelmChart/Docs/Postgres.md index c5fd7e6e80..5d88661986 100644 --- a/HelmChart/Docs/Postgres.md +++ b/HelmChart/Docs/Postgres.md @@ -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= --port= --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= --dbname=oneuptimedb --password --file=oneuptime.sql +./restore.sh ``` diff --git a/config.example.env b/config.example.env index b691df6ceb..db894abfd0 100644 --- a/config.example.env +++ b/config.example.env @@ -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 diff --git a/restore.sh b/restore.sh index 98962cf5ce..4035961b8a 100644 --- a/restore.sh +++ b/restore.sh @@ -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