Add backups for mariadb nightly like we do for postgres.
This allows us to back up /backups and get a good few days database dumps on mariadb servers.
This commit is contained in:
parent
9d31407e01
commit
ef817b7d0c
3 changed files with 30 additions and 0 deletions
10
roles/mariadb_server/files/backup-database
Normal file
10
roles/mariadb_server/files/backup-database
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Backup a database *locally* to /backups/.
|
||||||
|
|
||||||
|
DB=$1
|
||||||
|
|
||||||
|
# Make our latest backup
|
||||||
|
/bin/mysqldump --add-drop-database $DB | /usr/bin/xz > /backups/$DB-$(date +%F).dump.xz
|
||||||
|
|
||||||
|
# Also, delete the backup from a few days ago.
|
||||||
|
rm -f /backups/$DB-$(date --date="3 days ago" +%F).dump.xz
|
|
@ -27,4 +27,23 @@
|
||||||
- name: create .my.cnf file for future logins
|
- name: create .my.cnf file for future logins
|
||||||
template: src=dotmy.cnf.j2 dest=/root/.my.cnf owner=root group=root mode=0700
|
template: src=dotmy.cnf.j2 dest=/root/.my.cnf owner=root group=root mode=0700
|
||||||
|
|
||||||
|
- name: Ensure mariadb has a place to backup to
|
||||||
|
file: dest=/backups state=directory owner=mysql
|
||||||
|
tags:
|
||||||
|
- mariadb-server
|
||||||
|
|
||||||
|
- name: Copy over backup scriplet
|
||||||
|
copy: src=backup-database dest=/usr/local/bin/backup-database mode=0755
|
||||||
|
tags:
|
||||||
|
- mariadb-server
|
||||||
|
|
||||||
|
- name: Set up some cronjobs to backup databases as configured
|
||||||
|
template: >
|
||||||
|
src=cron-backup-database
|
||||||
|
dest=/etc/cron.d/cron-backup-database-{{ item }}
|
||||||
|
with_items:
|
||||||
|
- "{{ dbs_to_backup }}"
|
||||||
|
when: dbs_to_backup != []
|
||||||
|
tags:
|
||||||
|
- cron
|
||||||
|
- mariadb-server
|
||||||
|
|
1
roles/mariadb_server/templates/cron-backup-database
Normal file
1
roles/mariadb_server/templates/cron-backup-database
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0 0 * * * mysql /usr/local/bin/backup-database {{ item }}
|
Loading…
Add table
Add a link
Reference in a new issue