automation/deployer/roles/build/tasks/backup.yml

66 lines
2 KiB
YAML

---
# Needs variables:
# - site: dict describing the site install (cf group_vars/all/vars.yml)
# - site_data_path: path of the site's data
- name: "Data backups"
block:
- name: "Setup weekly backup of site's data"
cron:
name: "backup {{ site.slug }} data"
# hour: "{{ 24 | random }}"
# minute: "{{ 60 | random }}"
special_time: weekly
user: "root"
job: "tar czf {{ backups_path }}/{{ site.slug }}.tar.gz {{ site_data_path }}"
become: yes
- name: "Setup data backup rotation with logrotate"
blockinfile:
path: "/etc/logrotate.d/{{ site.slug }}"
marker: "# {mark} DATA BACKUP"
create: yes
block: |
{{ backups_path }}/{{ site.slug }}.tar.gz {
weekly
rotate 4
nocompress
dateext
dateformat _%Y-%m-%d
extension .tar.gz
missingok
}
become: yes
when: site_data_path is defined
- name: "MySQL Database backups"
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:
name: "backup {{ site.slug }} database"
special_time: weekly
user: "root" # need root for passwordless mysqldump
job: "mysqldump {{ site.mysql_database }} | gzip -c > {{ backups_path }}/{{ site.slug }}.sql.gz"
become: yes
- name: "Setup database backup rotation with logrotate"
blockinfile:
path: "/etc/logrotate.d/{{ site.slug }}"
marker: "# {mark} DATABASE BACKUP"
create: yes
block: |
{{ backups_path }}/{{ site.slug }}.sql.gz {
weekly
rotate 4
nocompress
dateext
dateformat _%Y-%m-%d
extension .sql.gz
missingok
}
become: yes
when: site.mysql_database is defined
- name: "PostgreSQL Database backups"
debug: msg="TODO PUTAIN BOSSE LÀ"
when: site.postgres_database is defined