automation/deployer/roles/build/tasks/backup.yml
2020-06-30 13:46:59 +02:00

74 lines
No EOL
1.9 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"
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
nocreate
}
become: yes
when: site_data_path is defined
- name: "Setup periodic MySQL database backup"
blockinfile:
path: "/etc/logrotate.d/{{ site.slug }}"
marker: "# {mark} DATABASE BACKUP"
create: yes
block: |
{{ backups_path }}/{{ site.slug }}.sql.gz {
prerotate
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
nocreate
}
become: yes
when: site.mysql_database is defined
- name: "Setup periodic PostgreSQL database backup"
blockinfile:
path: "/etc/logrotate.d/{{ site.slug }}"
marker: "# {mark} DATABASE BACKUP"
create: yes
block: |
{{ backups_path }}/{{ site.slug }}.sql.gz {
prerotate
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
nocreate
}
become: yes
when: site.postgres_database is defined