2024-11-10 21:17:33 +00:00
|
|
|
- name: Create backup directory
|
|
|
|
file:
|
|
|
|
path: '{{ backup_dir }}'
|
|
|
|
state: directory
|
|
|
|
owner: postgres
|
|
|
|
group: postgres
|
|
|
|
mode: '0755'
|
|
|
|
|
|
|
|
- name: Perform database backup
|
|
|
|
command: >
|
|
|
|
pg_dump -U {{ postgres_user }} -F c -f "{{ backup_dir }}/db_backup_{{ postgres_db }}_{{ ansible_date_time.iso8601 }}.sql" {{ postgres_db }}
|
|
|
|
become_user: postgres
|
|
|
|
environment:
|
|
|
|
PGPASSWORD: '{{ postgres_password }}'
|
|
|
|
|
|
|
|
- name: Daily cron full backup
|
|
|
|
cron:
|
2024-12-08 19:11:48 +00:00
|
|
|
name: 'PostgreSQL daily full backup {{ postgres_user }}'
|
2024-11-10 21:17:33 +00:00
|
|
|
user: postgres
|
|
|
|
minute: '0'
|
|
|
|
hour: '1'
|
|
|
|
job: "pg_dump -U {{ postgres_user }} -F c {{ postgres_db }} > {{ backup_dir }}/full_db_backup_{{ postgres_db }}_$(date +\\%F-\\%H-%M).sql"
|
|
|
|
environment:
|
|
|
|
PGPASSWORD: '{{ postgres_password }}'
|
|
|
|
|
|
|
|
- name: Hourly cron incremental backup
|
|
|
|
cron:
|
2024-12-08 19:11:48 +00:00
|
|
|
name: 'PostgreSQL hourly incremental backup {{ postgres_user }}'
|
2024-11-10 21:17:33 +00:00
|
|
|
user: postgres
|
|
|
|
minute: '0'
|
|
|
|
job: "pg_dump -U {{ postgres_user }} -F c --data-only --file=\"{{ backup_dir }}/incremental_db_backup_{{ postgres_db }}_$(date +\\%F-\\%H-%M).sql\" {{ postgres_db }}"
|
|
|
|
environment:
|
2024-12-08 19:11:48 +00:00
|
|
|
PGPASSWORD: '{{ postgres_password }}'
|