added backup support

This commit is contained in:
nd 2020-04-19 11:52:30 +02:00
parent 44235447fc
commit 14713a0030
No known key found for this signature in database
GPG key ID: 21B5CD4DEE3670E9
3 changed files with 28 additions and 0 deletions

21
tasks/backup.yml Normal file
View file

@ -0,0 +1,21 @@
- name: add mysql backup folder
file:
path: /opt/mysqlbackup/
state: directory
owner: root
group: root
mode: '750'
- name: add backup cronjob for easier backup/restore
cron:
name: db backup
job: '/usr/bin/mysqldump --all-databases --single-transaction | gzip > /opt/mysqlbackup/$(date "+\%Y\%m\%d-\%H\%M.sql.gz")'
user: root
hour: "*/4"
minute: 45
- name: add backup cleanup cronjob
cron:
name: db backup cleanup
job: 'find /opt/mysqlbackup/* -mtime +{{ mariadb.backup.keep_days }} -type f -exec rm {} \;'
special_time: daily

View file

@ -20,3 +20,7 @@
password: "{{ item.value.password }}"
priv: "{{ item.value.priv | default('*.*:USAGE') }}"
with_dict: "{{ mariadb.users }}"
- include_tasks: backup.yml
when:
- mariadb.backup.enable