fix backups and restore.

This commit is contained in:
Simon Larsen 2022-12-12 15:25:30 +05:30
parent c3d0fe4623
commit 955df684b6
No known key found for this signature in database
GPG key ID: AB45983AA9C81CDE
5 changed files with 39 additions and 2 deletions

2
.gitignore vendored
View file

@ -77,3 +77,5 @@ Nginx/default.conf
Certs/StatusPageCerts/*.crt
Certs/StatusPageCerts/*.key
Backups/*.backup

1
Backups/README.md Normal file
View file

@ -0,0 +1 @@
This is where all the database backups will be stored.

View file

@ -1 +1,10 @@
docker run -it --rm --entrypoint sh debug/ubuntu
# This file takes last 30 days backup. Make sure you run this file atleast once/day.
# The backup will be in the format of db-(date of the month).backup
# Before the backup, please make sure DATABASE_BACKUP_* ENV vars in config.env is set properly.
export $(grep -v '^#' config.env | xargs)
sudo docker run -it --net=host --rm \
--env-file config.env \
--volume=$(pwd)$DATABASE_BACKUP_DIRECTORY:/var/lib/postgresql/data \
postgres:latest /usr/bin/pg_dump -Fc --dbname=postgresql://$DATABASE_BACKUP_USERNAME:$DATABASE_BACKUP_PASSWORD@$DATABASE_BACKUP_HOST:$DATABASE_BACKUP_PORT/$DATABASE_BACKUP_NAME --file=/var/lib/postgresql/data/db-$(date +%d).backup

View file

@ -101,4 +101,19 @@ SUBSCRIPTION_PLAN_BASIC=Basic,<planMonthlyId>,<planYearlyId>,0,0,1,0
SUBSCRIPTION_PLAN_GROWTH=Growth,<planMonthlyId>,<planYearlyId>,0,0,2,14
SUBSCRIPTION_PLAN_ENTERPRISE=Enterprise,<planMonthlyId>,<planYearlyId>,-1,-1,3,14
STATUS_PAGE_CNAME_RECORD=statuspage.oneuptime.com
STATUS_PAGE_CNAME_RECORD=statuspage.oneuptime.com
DATABASE_BACKUP_DIRECTORY=/Backups
DATABASE_BACKUP_HOST=localhost
DATABASE_BACKUP_PORT=5400
DATABASE_BACKUP_USERNAME=postgres
DATABASE_BACKUP_PASSWORD={{ .Env.DATABASE_PASSWORD }}
DATABASE_RESTORE_DIRECTORY=/Backups
DATABASE_RESTORE_HOST=localhost
DATABASE_RESTORE_PORT=5400
DATABASE_RESTORE_USERNAME=postgres
DATABASE_RESTORE_PASSWORD={{ .Env.DATABASE_PASSWORD }}
DATABASE_RESTORE_FILENAME=db-12.backup

View file

@ -0,0 +1,10 @@
# This file takes last 30 days backup. Make sure you run this file atleast once/day.
# The backup will be in the format of db-(date of the month).backup
# Before the backup, please make sure DATABASE_RESTORE_* ENV vars in config.env is set properly.
export $(grep -v '^#' config.env | xargs)
sudo docker run -it --net=host --rm \
--env-file config.env \
--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