mirror of
https://github.com/roles-ansible/role-postgresql-backup.git
synced 2024-08-16 10:19:49 +02:00
enable different export types
This commit is contained in:
parent
8ea34f07a6
commit
6c33640a34
5 changed files with 29 additions and 4 deletions
17
README.md
17
README.md
|
@ -59,6 +59,23 @@ postgresql_backup:
|
||||||
port: 5432
|
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)*
|
+ Perform basic versionscheck *(true is recomended)*
|
||||||
```
|
```
|
||||||
submodules_versioncheck: false
|
submodules_versioncheck: false
|
||||||
|
|
|
@ -12,6 +12,8 @@ postgresql_backup:
|
||||||
cron: true
|
cron: true
|
||||||
cron_minute: '*'
|
cron_minute: '*'
|
||||||
cron_hour: '0'
|
cron_hour: '0'
|
||||||
|
export_option: 'p'
|
||||||
|
create_tar_gz: true
|
||||||
databases: []
|
databases: []
|
||||||
# - name: psql_database_name
|
# - name: psql_database_name
|
||||||
# user: psql_database_user
|
# user: psql_database_user
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
- name: generate backup script
|
- name: generate backup script
|
||||||
become: true
|
become: true
|
||||||
template:
|
template:
|
||||||
src: templates/postgresql-backup-script.sh
|
src: templates/postgresql-backup-script.sh.j2
|
||||||
dest: /opt/postgresql-backup-script.sh
|
dest: /opt/postgresql-backup-script.sh
|
||||||
owner: "{{ postgresql_backup.user }}"
|
owner: "{{ postgresql_backup.user }}"
|
||||||
backup: true
|
backup: true
|
||||||
|
|
|
@ -18,8 +18,12 @@ backup_databases() {
|
||||||
{% if db.password %}
|
{% if db.password %}
|
||||||
export PGPASSWORD="{{ db.password }}"
|
export PGPASSWORD="{{ db.password }}"
|
||||||
{% endif %}
|
{% 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
|
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
|
||||||
mv "{{ db.name }}.in_progress.psql" "{{ db.name }}.psql"
|
{% 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"
|
echo "backup of {{ db.name }} successful"
|
||||||
else
|
else
|
||||||
echo "failed to export {{ db.name }}"
|
echo "failed to export {{ db.name }}"
|
|
@ -9,8 +9,10 @@ _postgresql_backup:
|
||||||
cron: true
|
cron: true
|
||||||
cron_minute: '*'
|
cron_minute: '*'
|
||||||
cron_hour: '0'
|
cron_hour: '0'
|
||||||
|
export_option: 'p'
|
||||||
|
create_tar_gz: true
|
||||||
databases: []
|
databases: []
|
||||||
|
|
||||||
# versionscheck
|
# 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
|
playbook_version_path: 'role-postgresql-backup_roles-ansible_github.com.version' # unique string
|
||||||
|
|
Loading…
Reference in a new issue