Skip to content

Commit

Permalink
Add toggle for globals backup
Browse files Browse the repository at this point in the history
  • Loading branch information
yurihs committed Aug 20, 2019
1 parent c16d7cc commit 5ff97e8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

## What is backed up?

- Global objects (roles and tablespaces), compressed using gzip. `pg_dumpall --globals-only | gzip`
- All readable databases, to separate files, using the "custom" PostgreSQL format. `pg_dump --format=custom database`
- Global objects (roles and tablespaces), compressed using gzip. May be disabled. Equivalent to `pg_dumpall --globals-only | gzip`
- All readable databases, to separate files, using the "custom" PostgreSQL format. Equivalent to `pg_dump --format=custom database`


## Role variables (default values)
Expand All @@ -21,6 +21,7 @@ postgres_backup_list:
pg_username: postgres
pg_hostname: localhost
pg_port: 5432
do_backup_globals: true
cron:
minute: '0'
hour: '*'
Expand Down Expand Up @@ -71,6 +72,7 @@ postgres_backup_list:
pg_username: postgres
pg_hostname: localhost
pg_port: 5432
do_backup_globals: true
cron:
minute: '0'
hour: '*'
Expand Down Expand Up @@ -114,6 +116,7 @@ postgres_backup_list:
pg_password: "hunter2"
pg_hostname: db.example.com
pg_port: 5432
do_backup_globals: false
output_dir: /opt/prod_db_bak
cron:
minute: '0'
Expand All @@ -129,11 +132,9 @@ This configuration will result in the following structure:
/opt/
prod_db_bak/
2019-01-01_00-00/
globals.sql.gz
users.custom
posts.custom
2019-01-02_00-00/
globals.sql.gz
users.custom
posts.custom
~~~
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ postgres_backup_list:
pg_username: postgres
pg_hostname: localhost
pg_port: 5432
do_backup_globals: true
cron:
minute: '0'
hour: '*'
Expand Down
14 changes: 9 additions & 5 deletions files/postgres_backup_script
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ main() {
pushd . >/dev/null
cd "$output_dir"

echo "Starting globals backup."
if backup_globals; then
echo "Globals backup is done."
if [[ "$DO_BACKUP_GLOBALS" = true ]]; then
echo "Starting globals backup."
if backup_globals; then
echo "Globals backup is done."
else
echo "Globals backup failed. Exiting."
exit 1;
fi;
else
echo "Globals backup failed. Exiting."
exit 1;
echo "Skipping globals backup."
fi;

echo "Starting databases backup."
Expand Down
2 changes: 2 additions & 0 deletions templates/postgres_backup_config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ export PGPASSWORD="{{ item.pg_password }}"
PG_HOSTNAME="{{ item.pg_hostname }}"
PG_PORT="{{ item.pg_port }}"

DO_BACKUP_GLOBALS={% if item.do_backup_globals|default(true) %}true{% else %}false{% endif %}

OUTPUT_DIR_BASE="{{ item.output_dir | default(postgres_backup_default_output_dir + '/' + item.name) }}"
DATE_FORMAT="{{ item.date_format | default(postgres_backup_default_date_format) }}"

0 comments on commit 5ff97e8

Please sign in to comment.