mirror of
https://github.com/roles-ansible/role-postgresql-backup.git
synced 2024-08-16 10:19:49 +02:00
update linting and adding hostname to backup file
This commit is contained in:
parent
a37febde0a
commit
a3bcbd491c
5 changed files with 31 additions and 27 deletions
|
@ -1,29 +1,32 @@
|
||||||
---
|
---
|
||||||
- name: combine postgresql_backup configuration
|
- name: Combine postgresql_backup configuration
|
||||||
set_fact:
|
ansible.builtin.set_fact:
|
||||||
postgresql_backup: "{{ _postgresql_backup|combine(postgresql_backup, recursive=True) }}"
|
postgresql_backup: "{{ _postgresql_backup | combine(postgresql_backup, recursive=true) }}"
|
||||||
|
|
||||||
- include_tasks: versioncheck.yml
|
- name: Run optional versionscheck
|
||||||
|
ansible.builtin.include_tasks: versioncheck.yml
|
||||||
when: submodules_versioncheck|bool
|
when: submodules_versioncheck|bool
|
||||||
|
|
||||||
- include_tasks: packages.yml
|
- name: Install required Packages
|
||||||
|
ansible.builtin.include_tasks: packages.yml
|
||||||
|
|
||||||
- name: generate backup script
|
- name: Generate backup script
|
||||||
become: true
|
become: true
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: templates/postgresql-backup-script.sh.j2
|
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
|
||||||
mode: 0755
|
mode: 0755
|
||||||
|
|
||||||
- name: add backup script as cronjob
|
# TODO: Change to systemd timer!
|
||||||
|
- name: Add backup script as cronjob
|
||||||
become: true
|
become: true
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: backup postgres database
|
name: backup postgres database
|
||||||
cron_file: 'wingcon_psql'
|
cron_file: 'wingcon_psql'
|
||||||
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: /opt/postgresql-backup-script.sh >/dev/null 2>&1
|
job: /opt/postgresql-backup-script.sh >/dev/null 2>&1
|
||||||
user: "{{ postgresql_backup.user }}"
|
user: "{{ postgresql_backup.user }}"
|
||||||
when: postgresql_backup.cron
|
when: postgresql_backup.cron
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
---
|
---
|
||||||
- name: "Install PostgreSQL client"
|
- name: "Install PostgreSQL client"
|
||||||
become: true
|
become: true
|
||||||
package:
|
ansible.builtin.package:
|
||||||
name: "{{ postgresql_backup.required_packages }}"
|
name: "{{ postgresql_backup.required_packages }}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: "Install tar and gzip"
|
- name: "Install tar and gzip"
|
||||||
become: true
|
become: true
|
||||||
package:
|
ansible.builtin.package:
|
||||||
name: "{{ postgresql_backup.optional_packages }}"
|
name: "{{ postgresql_backup.optional_packages }}"
|
||||||
state: present
|
state: present
|
||||||
when: postgresql_backup.create_tar_gz | bool
|
when: postgresql_backup.create_tar_gz | bool
|
||||||
|
|
|
@ -8,37 +8,38 @@
|
||||||
path: '/etc/.ansible-version'
|
path: '/etc/.ansible-version'
|
||||||
state: directory
|
state: directory
|
||||||
mode: 0755
|
mode: 0755
|
||||||
when: submodules_versioncheck|bool
|
when: submodules_versioncheck | bool
|
||||||
|
|
||||||
- name: check playbook version
|
- name: Check playbook version
|
||||||
become: true
|
become: true
|
||||||
ansible.builtin.slurp:
|
ansible.builtin.slurp:
|
||||||
src: "/etc/.ansible-version/{{ playbook_version_path }}"
|
src: "/etc/.ansible-version/{{ playbook_version_path }}"
|
||||||
register: playbook_version
|
register: playbook_version
|
||||||
when: submodules_versioncheck|bool
|
when: submodules_versioncheck | bool
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
||||||
- name: Print remote role version
|
- name: Print remote role version
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}"
|
msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}"
|
||||||
when: submodules_versioncheck|bool
|
when: submodules_versioncheck | bool
|
||||||
|
|
||||||
- name: Print locale role version
|
- name: Print locale role version
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "Local role version: '{{ playbook_version_number|string }}'."
|
msg: "Local role version: '{{ playbook_version_number | string }}'."
|
||||||
when: submodules_versioncheck|bool
|
when: submodules_versioncheck | bool
|
||||||
|
|
||||||
- name: Check if your version is outdated
|
- name: Check if your version is outdated
|
||||||
ansible.builtin.fail:
|
ansible.builtin.fail:
|
||||||
msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!"
|
msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!"
|
||||||
when:
|
when:
|
||||||
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck|bool
|
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck | bool
|
||||||
|
|
||||||
- name: write new version to remote disk
|
- name: Write new version to remote disk
|
||||||
become: true
|
become: true
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: "{{ playbook_version_number }}"
|
content: "{{ playbook_version_number }}"
|
||||||
dest: "/etc/.ansible-version/{{ playbook_version_path }}"
|
dest: "/etc/.ansible-version/{{ playbook_version_path }}"
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
when: submodules_versioncheck|bool
|
when: submodules_versioncheck | bool
|
||||||
|
tags: skip_ansible_lint_template-instead-of-copy
|
||||||
|
|
|
@ -20,11 +20,11 @@ backup_databases() {
|
||||||
{% endif %}
|
{% endif %}
|
||||||
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 (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 %}
|
{% if postgresql_backup.create_tar_gz %}
|
||||||
mv "{{ db.name }}.in_progress.psql" "{{ db.name }}.psql"
|
mv "{{ db.name }}.in_progress.psql" "{{ db.name }}_{{ db.host | default( 'localhost' )}}.psql"
|
||||||
tar -czvf "{{ db.name }}.psql.tar.gz" "{{ db.name }}.psql"
|
tar -czvf "{{ db.name }}_{{ db.host | default( 'localhost' )}}.psql.tar.gz" "{{ db.name }}_{{ db.host | default( 'localhost' )}}.psql"
|
||||||
rm "{{ db.name }}.psql"
|
rm "{{ db.name }}_{{ db.host | default( 'localhost' )}}.psql"
|
||||||
{% else %}
|
{% else %}
|
||||||
mv "{{ db.name }}.in_progress.psql" "{{ db.name }}.psql"
|
mv "{{ db.name }}.in_progress.psql" "{{ db.name }}_{{ db.host | default( 'localhost' )}}.psql"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
echo "backup of {{ db.name }} successful"
|
echo "backup of {{ db.name }} successful"
|
||||||
else
|
else
|
||||||
|
|
|
@ -17,5 +17,5 @@ _postgresql_backup:
|
||||||
databases: []
|
databases: []
|
||||||
|
|
||||||
# versionscheck
|
# versionscheck
|
||||||
playbook_version_number: 25 # should be int
|
playbook_version_number: 26 # should be int
|
||||||
playbook_version_path: 'role-postgresql-backup_roles-ansible_github.com.version'
|
playbook_version_path: 'role-postgresql-backup_roles-ansible_github.com.version'
|
||||||
|
|
Loading…
Reference in a new issue