Files
ansible/hetzner.yaml
2021-11-22 05:48:32 +01:00

47 lines
1.3 KiB
YAML

---
# This playbook backups the customers on hetzner server.
- name: Backup hetzner
hosts: all
gather_facts: true
tasks:
- include_vars: vars/hetzner/secret.yaml
- include_vars: vars/hetzner/variable.yaml
- name: Create backup directory
file:
path: "{{ backup_dir }}"
state: directory
- name: Create customer directories
file:
path: "{{ backup_dir }}/{{ item.key }}"
state: directory
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Backup databases
shell: mysqldump -u{{ mysql_user }} -p{{ mysql_password }} {{ item.value.database }} > {{ backup_dir }}/{{ item.key }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Compress database backups
shell: gzip {{ backup_dir }}/{{ item.key }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
loop: "{{ lookup('dict', customers) }}"
loop_control:
label: "{{ item.key }}"
- name: Fetch backups
fetch:
src: "{{ backup_dir }}"
dest: "{{ local_backup }}"
flat: yes
- name: Clean backup directory
file:
path: "{{ backup_dir }}"
state: absent