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-06-30 11:46:59 +00:00
|
|
|
|
|
|
|
- name: "Setup periodic site files backup"
|
2020-07-13 09:36:23 +00:00
|
|
|
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
|
2020-07-13 09:36:23 +00:00
|
|
|
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
|
2020-07-13 09:36:23 +00:00
|
|
|
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"
|
2020-07-13 09:36:23 +00:00
|
|
|
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
|
2020-07-13 09:36:23 +00:00
|
|
|
state: touch
|
2020-06-30 11:46:59 +00:00
|
|
|
become: yes
|
2020-05-06 10:12:09 +00:00
|
|
|
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"
|
2020-07-13 09:36:23 +00:00
|
|
|
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
|
2020-07-13 09:36:23 +00:00
|
|
|
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
|