diff --git a/README.md b/README.md index aecf48a..98a95d6 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,23 @@ postgresql_backup: port: 5432 ``` ++ Export Option for pg_dump. + +> ``p`` – plain-text SQL script +> ``c`` – custom-format archive +> ``d`` – directory-format archive +> ``t`` – tar-format archive +```yaml +postgresql_backup: + export_option: "p" +``` + ++ save backup as tar.gz +```yaml +postgresql_backup: + create_tar_gz: true +``` + + Perform basic versionscheck *(true is recomended)* ``` submodules_versioncheck: false diff --git a/defaults/main.yml b/defaults/main.yml index 8fe5ef4..9fa665e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,6 +12,8 @@ postgresql_backup: cron: true cron_minute: '*' cron_hour: '0' + export_option: 'p' + create_tar_gz: true databases: [] # - name: psql_database_name # user: psql_database_user diff --git a/tasks/main.yml b/tasks/main.yml index bccafbf..e54594d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,7 +11,7 @@ - name: generate backup script become: true template: - src: templates/postgresql-backup-script.sh + src: templates/postgresql-backup-script.sh.j2 dest: /opt/postgresql-backup-script.sh owner: "{{ postgresql_backup.user }}" backup: true diff --git a/templates/postgresql-backup-script.sh b/templates/postgresql-backup-script.sh.j2 similarity index 67% rename from templates/postgresql-backup-script.sh rename to templates/postgresql-backup-script.sh.j2 index 65e87a4..250a8aa 100644 --- a/templates/postgresql-backup-script.sh +++ b/templates/postgresql-backup-script.sh.j2 @@ -18,8 +18,12 @@ backup_databases() { {% if db.password %} export PGPASSWORD="{{ db.password }}" {% endif %} - if (umask 077 && pg_dump -F c -h "{{ db.host | default( 'localhost' ) }}" -U "{{ db.user | default( 'postgres' ) }}" -p "{{ db.port | default( '5432' ) }}" "{{ db.name }}" -f "{{ db.name }}.in_progress.psql"); then - mv "{{ db.name }}.in_progress.psql" "{{ db.name }}.psql" + if (umask 077 && pg_dump -F {{ postgresql_backup.export_option | string }} -h "{{ db.host | default( 'localhost' ) }}" -U "{{ db.user | default( 'postgres' ) }}" -p "{{ db.port | default( '5432' ) }}" "{{ db.name }}" -f "{{ db.name }}.in_progress.psql"); then + {% if postgresql_backup.create_tar_gz %} + tar -czvf "{{ db.name }}.psql.tar.gz" "{{ db.name }}.in_progress.psql" + {% else %} + mv "{{ db.name }}.in_progress.psql" "{{ db.name }}.psql" + {% endif %} echo "backup of {{ db.name }} successful" else echo "failed to export {{ db.name }}" diff --git a/vars/main.yml b/vars/main.yml index 190481a..eb1b736 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -9,8 +9,10 @@ _postgresql_backup: cron: true cron_minute: '*' cron_hour: '0' + export_option: 'p' + create_tar_gz: true databases: [] # versionscheck -playbook_version_number: 21 # should be int +playbook_version_number: 22 # should be int playbook_version_path: 'role-postgresql-backup_roles-ansible_github.com.version' # unique string