diff --git a/.gitignore b/.gitignore index 98cf78bb6f..6a35d82de2 100644 --- a/.gitignore +++ b/.gitignore @@ -83,3 +83,5 @@ Certs/ServerCerts/*.crt Certs/ServerCerts/*.key Backups/*.backup +Backups/*.sql +Backups/*.tar diff --git a/backup.sh b/backup.sh index daed3a9096..cdc888e166 100644 --- a/backup.sh +++ b/backup.sh @@ -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!" \ No newline at end of file diff --git a/config.tpl.env b/config.tpl.env index 524b89e87c..7a73f15ec6 100644 --- a/config.tpl.env +++ b/config.tpl.env @@ -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=