2020-05-05 09:08:24 +00:00
|
|
|
---
|
|
|
|
# Needs variables:
|
2020-05-06 10:12:09 +00:00
|
|
|
# - site: dict describing the site install (cf group_vars/all/vars.yml)
|
2020-05-05 09:08:24 +00:00
|
|
|
# - site_data_path: path of the site's data
|
|
|
|
|
2020-05-06 10:11:46 +00:00
|
|
|
- name: "Data backups"
|
2020-05-05 09:08:24 +00:00
|
|
|
block:
|
|
|
|
- name: "Setup weekly backup of site's data"
|
|
|
|
cron:
|
2020-05-06 10:12:09 +00:00
|
|
|
name: "backup {{ site.slug }} data"
|
2020-05-05 09:08:24 +00:00
|
|
|
# hour: "{{ 24 | random }}"
|
|
|
|
# minute: "{{ 60 | random }}"
|
|
|
|
special_time: weekly
|
|
|
|
user: "root"
|
2020-05-06 10:12:09 +00:00
|
|
|
job: "tar czf {{ backups_path }}/{{ site.slug }}.tar.gz {{ site_data_path }}"
|
2020-05-05 09:08:24 +00:00
|
|
|
become: yes
|
|
|
|
- name: "Setup data backup rotation with logrotate"
|
|
|
|
blockinfile:
|
2020-05-06 10:12:09 +00:00
|
|
|
path: "/etc/logrotate.d/{{ site.slug }}"
|
2020-05-05 09:08:24 +00:00
|
|
|
marker: "# {mark} DATA BACKUP"
|
|
|
|
create: yes
|
|
|
|
block: |
|
2020-05-06 10:12:09 +00:00
|
|
|
{{ backups_path }}/{{ site.slug }}.tar.gz {
|
2020-05-05 09:08:24 +00:00
|
|
|
weekly
|
|
|
|
rotate 4
|
|
|
|
nocompress
|
|
|
|
dateext
|
|
|
|
dateformat _%Y-%m-%d
|
|
|
|
extension .tar.gz
|
|
|
|
missingok
|
|
|
|
}
|
|
|
|
become: yes
|
|
|
|
when: site_data_path is defined
|
|
|
|
|
2020-05-06 10:11:46 +00:00
|
|
|
- name: "Database backups"
|
2020-05-05 09:08:24 +00:00
|
|
|
block:
|
|
|
|
# You need your root MySQL password stored in /root/.my.cnf to avoid
|
|
|
|
# putting the password in the crontab
|
|
|
|
- name: "Setup weekly backup of database"
|
|
|
|
cron:
|
2020-05-06 10:12:09 +00:00
|
|
|
name: "backup {{ site.slug }} database"
|
2020-05-05 09:08:24 +00:00
|
|
|
special_time: weekly
|
|
|
|
user: "root" # need root for passwordless mysqldump
|
2020-05-06 10:12:09 +00:00
|
|
|
job: "mysqldump {{ site.mysql_database }} | gzip -c > {{ backups_path }}/{{ site.slug }}.sql.gz"
|
2020-05-05 09:08:24 +00:00
|
|
|
become: yes
|
|
|
|
- name: "Setup database backup rotation with logrotate"
|
|
|
|
blockinfile:
|
2020-05-06 10:12:09 +00:00
|
|
|
path: "/etc/logrotate.d/{{ site.slug }}"
|
2020-05-05 09:08:24 +00:00
|
|
|
marker: "# {mark} DATABASE BACKUP"
|
|
|
|
create: yes
|
|
|
|
block: |
|
2020-05-06 10:12:09 +00:00
|
|
|
{{ backups_path }}/{{ site.slug }}.sql.gz {
|
2020-05-05 09:08:24 +00:00
|
|
|
weekly
|
|
|
|
rotate 4
|
|
|
|
nocompress
|
|
|
|
dateext
|
|
|
|
dateformat _%Y-%m-%d
|
|
|
|
extension .sql.gz
|
|
|
|
missingok
|
|
|
|
}
|
|
|
|
become: yes
|
2020-05-06 10:12:09 +00:00
|
|
|
when: site.mysql_database is defined
|