Add backups für strato production server.

This commit is contained in:
2024-02-24 08:59:41 +01:00
parent 4ae10c26a6
commit 3decc1be88
2 changed files with 96 additions and 0 deletions

64
strato-production.yaml Normal file
View File

@@ -0,0 +1,64 @@
---
# This playbook backups the odroid docker containers.
- name: Backup Strato Production
hosts: all
gather_facts: true
tasks:
- name: Backup odroid
block:
- include_vars: vars/mattermost.yaml
- include_vars: vars/strato-production.yaml
- name: Check if directories exist
stat:
path: "{{ backup_dir }}/{{ item }}"
register: dirs
loop: "{{ systems }}"
- name: Create not existing directories
file:
path: "{{ backup_dir }}/{{ item.item }}"
state: directory
mode: 0755
group: chris
owner: chris
when: item.stat.exists == false
with_items: "{{ dirs.results }}"
loop_control:
label: "{{ item.item }}"
- name: Backup mysql databases
shell: docker exec {{ item }}-db mysqldump -u{{ item }} -p{{ lookup('vars', item ~ '-password') }} {{ item }} > {{ backup_dir }}/{{ item }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
loop: "{{ mysql_databases }}"
- name: Compress database backup files
shell: gzip {{ backup_dir }}/{{ item }}/db-{{ ansible_date_time.iso8601_basic_short }}.sql
loop: "{{ databases }}"
- name: Inform Mattermost about success
uri:
url: "{{ mattermost_url }}"
method: POST
body_format: json
body:
channel_id: "{{ channel_id }}"
message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}: Playbook ran successful ({{ ansible_play_name }})"
headers:
Content-Type: application/json
Authorization: "Bearer {{ semaphore_token }}"
status_code: [200, 201]
rescue:
- name: Inform Mattermost about error
uri:
url: "{{ mattermost_url }}"
method: POST
body_format: json
body:
channel_id: "{{ channel_id }}"
message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}: Playbook ran with error ({{ ansible_play_name }})"
headers:
Content-Type: application/json
Authorization: "Bearer {{ error_token }}"
status_code: [200, 201]