added backup support
This commit is contained in:
parent
44235447fc
commit
14713a0030
3 changed files with 28 additions and 0 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
mariadb:
|
mariadb:
|
||||||
|
backup:
|
||||||
|
enable: True
|
||||||
|
keep_days: 3
|
||||||
users: {}
|
users: {}
|
||||||
# mysql:
|
# mysql:
|
||||||
# host: localhost
|
# host: localhost
|
||||||
|
|
|
||||||
21
tasks/backup.yml
Normal file
21
tasks/backup.yml
Normal 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
|
||||||
|
|
@ -20,3 +20,7 @@
|
||||||
password: "{{ item.value.password }}"
|
password: "{{ item.value.password }}"
|
||||||
priv: "{{ item.value.priv | default('*.*:USAGE') }}"
|
priv: "{{ item.value.priv | default('*.*:USAGE') }}"
|
||||||
with_dict: "{{ mariadb.users }}"
|
with_dict: "{{ mariadb.users }}"
|
||||||
|
|
||||||
|
- include_tasks: backup.yml
|
||||||
|
when:
|
||||||
|
- mariadb.backup.enable
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue