make db backups options work

This commit is contained in:
Simon Larsen 2023-01-31 09:40:57 +00:00
parent fc48c308d1
commit 7d5642860d
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
3 changed files with 14 additions and 2 deletions

2
.gitignore vendored
View File

@ -83,3 +83,5 @@ Certs/ServerCerts/*.crt
Certs/ServerCerts/*.key
Backups/*.backup
Backups/*.sql
Backups/*.tar

View File

@ -8,9 +8,17 @@ echo "Starting backup...."
git pull
# Backup as SQL, CANNOT be used with pg_reestore.
sudo docker run --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
postgres:latest /usr/bin/pg_dump --format=plain --clean --create --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).sql
# Backup as Tar can be used with pg_restore
sudo docker run --net=host --rm \
--env-file config.env \
--volume=$(pwd)$DATABASE_BACKUP_DIRECTORY:/var/lib/postgresql/data \
postgres:latest /usr/bin/pg_dump --format=tar --clean --create --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).tar
echo "Backup completed successfully!"

View File

@ -105,6 +105,7 @@ STATUS_PAGE_CNAME_RECORD=statuspage.oneuptime.com
DATABASE_BACKUP_DIRECTORY=/Backups
DATABASE_BACKUP_HOST=localhost
DATABASE_BACKUP_PORT=5400
DATABASE_BACKUP_NAME=oneuptimedb
DATABASE_BACKUP_USERNAME=postgres
DATABASE_BACKUP_PASSWORD={{ .Env.DATABASE_PASSWORD }}
@ -112,9 +113,10 @@ DATABASE_BACKUP_PASSWORD={{ .Env.DATABASE_PASSWORD }}
DATABASE_RESTORE_DIRECTORY=/Backups
DATABASE_RESTORE_HOST=localhost
DATABASE_RESTORE_PORT=5400
DATABASE_RESTORE_NAME=oneuptimedb
DATABASE_RESTORE_USERNAME=postgres
DATABASE_RESTORE_PASSWORD={{ .Env.DATABASE_PASSWORD }}
DATABASE_RESTORE_FILENAME=db-12.backup
DATABASE_RESTORE_FILENAME=db-31.backup
ANALYTICS_KEY=
ANALYTICS_HOST=