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

98 lines
2.8 KiB
YAML
Raw Normal View History

2020-05-05 09:08:24 +00:00
---
# Needs variables:
# - 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-06-30 11:46:59 +00:00
- 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 {
2020-11-29 21:33:26 +00:00
firstaction
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"
2020-11-29 21:33:26 +00:00
owner: www-data
group: www-data
state: touch
2020-06-30 11:46:59 +00:00
become: yes
2020-05-05 09:08:24 +00:00
when: site_data_path is defined
2020-06-30 11:46:59 +00:00
- 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"
2020-11-29 21:33:26 +00:00
owner: www-data
group: www-data
state: touch
2020-06-30 11:46:59 +00:00
become: yes
when: site.mysql_database is defined
2020-06-01 06:21:27 +00:00
2020-06-30 11:46:59 +00:00
- 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"
2020-11-29 21:33:26 +00:00
owner: www-data
group: www-data
state: touch
2020-06-30 11:46:59 +00:00
become: yes
2020-06-01 06:21:27 +00:00
when: site.postgres_database is defined