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

92 lines
2.7 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: "Setup periodic site files backup"
block:
- name: "Create logrotate configuration"
blockinfile:
path: "/etc/logrotate.d/{{ site.slug }}"
marker: "# {mark} DATA BACKUP"
create: yes
block: |
{{ backups_path }}/{{ site.slug }}.tar.gz {
prerotate
tar czf {{ backups_path }}/{{ site.slug }}.tar.gz {{ site_data_path }}
endscript
weekly
rotate 4
nocompress
dateext
dateformat _%Y-%m-%d
extension .tar.gz
missingok
su www-data www-data
}
- name: "Touch empty backup file"
file:
path: "{{ backups_path }}/{{ site.slug }}.tar.gz"
mode: "0644"
state: touch
become: yes
when: site_data_path is defined
- name: "Setup periodic MySQL database backup"
block:
- name: "Create logrotate configuration"
blockinfile:
path: "/etc/logrotate.d/{{ site.slug }}"
marker: "# {mark} DATABASE BACKUP"
create: yes
block: |
{{ backups_path }}/{{ site.slug }}.sql.gz {
firstaction
mysqldump {{ site.mysql_database }} | gzip -c > {{ backups_path }}/{{ site.slug }}.sql.gz
endscript
weekly
rotate 4
nocompress
dateext
dateformat _%Y-%m-%d
extension .sql.gz
missingok
su www-data www-data
}
- name: "Touch empty backup file"
file:
path: "{{ backups_path }}/{{ site.slug }}.sql.gz"
mode: "0644"
state: touch
become: yes
when: site.mysql_database is defined
- name: "Setup periodic PostgreSQL database backup"
block:
- name: "Create logrotate configuration"
blockinfile:
path: "/etc/logrotate.d/{{ site.slug }}"
marker: "# {mark} DATABASE BACKUP"
create: yes
block: |
{{ backups_path }}/{{ site.slug }}.sql.gz {
firstaction
sudo -u postgres pg_dump {{ site.postgres_database }} | gzip -c > {{ backups_path }}/{{ site.slug }}.sql.gz
endscript
weekly
rotate 4
nocompress
dateext
dateformat _%Y-%m-%d
extension .sql.gz
missingok
su www-data www-data
}
- name: "Touch empty backup file"
file:
path: "{{ backups_path }}/{{ site.slug }}.sql.gz"
mode: "0644"
state: touch
become: yes
when: site.postgres_database is defined