added extra backup tasks to playbook

This commit is contained in:
muppeth 2024-05-24 10:50:10 +02:00
parent 15430ce3d2
commit 4abdfe530a
Signed by: muppeth
GPG key ID: 0EBC7B9848D04031

View file

@ -1,6 +1,53 @@
---
- name: 'Create backup directories'
hosts: forgejo
tasks:
- name: '[BACKUP] - Create backup dir'
file:
path: '{{ forgejo_db_dump_path }}'
state: directory
mode: '0775'
- name: '[BACKUP] - Create db backup dir'
file:
path: '{{ forgejo_db_dump_path }}/db'
state: directory
mode: '0755'
- name: '[BACKUP] - Create code backup dir'
file:
path: '{{ forgejo_db_dump_path }}/code'
state: directory
owner: '{{ forgejo_user }}'
mode: '0755'
- hosts: forgejo
- name: 'Create db backup for forgejo'
hosts: forgejo
tasks:
- name: '[BACKUP] - Run db backup for forgejo'
shell:
cmd: 'sudo -u postgres pg_dump {{ forgejo_db_name }} | gzip -c > {{ forgejo_db_dump_path }}/{{ forgejo_db_name }}-{{ ansible_date_time.iso8601_basic_short }}.sql.gz'
- name: '[BACKUP] - Remove all but two latest backup files'
shell:
cmd: 'ls -t |tail -n +3 | xargs --no-run-if-empty rm'
chdir: '{{ forgejo_db_dump_path }}'
vars_files:
- ../defaults/main.yml
- name: 'Make backup of forgejo'
hosts: 'forgejo'
tasks:
- name: '[BACKUP] - Remove all but two latest backup files'
shell:
cmd: 'ls -t |tail -n +2 | xargs --no-run-if-empty rm'
chdir: '/srv/forgejo_dump'
- name: '[BACKUP] - Make backup of forgejo'
shell:
cmd: 'sudo -u {{ forgejo_user }} {{ forgejo_bindir }}/forgejo dump -c {{ forgejo_confdir }}'
chdir: '/srv/forgejo_dump'
vars_files:
- ../defaults/main.yml
- name: 'Run Forgejo role'
hosts: forgejo
roles:
- postgresql
- forgejo