1
0
Fork 0
mirror of https://github.com/roles-ansible/role-postgresql-backup.git synced 2024-08-16 10:19:49 +02:00

Change path and add compression

This commit is contained in:
L3D 2020-07-09 10:45:12 +02:00 committed by L3D
parent c6c36ac64f
commit 00e4de0225
No known key found for this signature in database
GPG key ID: 5215C3441797AB2B
4 changed files with 13 additions and 6 deletions

View file

@ -10,6 +10,7 @@ postgresql_backup:
user: root user: root
cron_minute: '*' cron_minute: '*'
cron_hour: '0' cron_hour: '0'
compress: false
databases: [] databases: []
# - name: psql_database_name # - name: psql_database_name
# user: psql_database_user # user: psql_database_user

View file

@ -12,7 +12,7 @@
become: true become: true
template: template:
src: templates/postgresql-backup-script.sh src: templates/postgresql-backup-script.sh
dest: /etc/postgresql-backup-script.sh dest: /opt/postgresql-backup-script.sh
owner: "{{ postgresql_backup.user }}" owner: "{{ postgresql_backup.user }}"
backup: true backup: true
mode: 0755 mode: 0755
@ -24,5 +24,5 @@
cron_file: /etc/crontab cron_file: /etc/crontab
minute: "{{ postgresql_backup.cron_minute | default( '*' ) }}" minute: "{{ postgresql_backup.cron_minute | default( '*' ) }}"
hour: "{{ postgresql_backup.cron_hour | default( '0' ) }}" hour: "{{ postgresql_backup.cron_hour | default( '0' ) }}"
job: /etc/postgresql-backup-script.sh job: /etc/postgresql-backup-script.sh >/dev/null 2>&1
user: "{{ postgresql_backup.user }}" user: "{{ postgresql_backup.user }}"

View file

@ -19,8 +19,14 @@ backup_databases() {
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 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 postgresql_backup.compress %}
tar -czvf "{{ db.name }}.psql.tar.gz" "{{ db.name }}.in_progress.psql"
{% else %}
mv "{{ db.name }}.in_progress.psql" "{{ db.name }}.psql" mv "{{ db.name }}.in_progress.psql" "{{ db.name }}.psql"
{% endif %}
echo "backup of {{ db.name }} successful"
else else
echo "failed to export {{ db.name }}"
return 1 return 1
fi; fi;
{% endfor %} {% endfor %}

View file

@ -1,8 +1,4 @@
--- ---
# versionscheck
playbook_version_number: 17 # should be int
playbook_version_path: 'role-postgresql-backup_roles-ansible_github.com.version' # unique string
_postgresql_backup: _postgresql_backup:
required_packages: required_packages:
- postgresql-client - postgresql-client
@ -12,3 +8,7 @@ _postgresql_backup:
cron_minute: '*' cron_minute: '*'
cron_hour: '0' cron_hour: '0'
databases: [] databases: []
# versionscheck
playbook_version_number: 18 # should be int
playbook_version_path: 'role-postgresql-backup_roles-ansible_github.com.version' # unique string