From 12ff2735a12c5ea9b8d97fd40929bbde57e524a3 Mon Sep 17 00:00:00 2001 From: Adrien Luxey Date: Sun, 3 May 2020 18:35:42 +0200 Subject: [PATCH] added backup and backup rotation to wordpress --- deployer/group_vars/all/vars.yml | 37 ++++++++++++------------ deployer/roles/build/tasks/wordpress.yml | 32 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/deployer/group_vars/all/vars.yml b/deployer/group_vars/all/vars.yml index bbf82c2..f9fc6db 100644 --- a/deployer/group_vars/all/vars.yml +++ b/deployer/group_vars/all/vars.yml @@ -5,6 +5,7 @@ adrien_serenity_password: "{{ vault_adrien_serenity_password }}" www_path: /vault/www sites_path: /vault/sites +backups_path: /vault/backups wordpress: version: 5.4 @@ -101,21 +102,21 @@ sites: mysql_username: lexperimental mysql_password: "{{ vault_lexperimental_mysql_password }}" - # - slug: mts # Shorthand name to use as directory/file name - # # The site URL (without www) - # url: editionsmangetasoupe.fr - # # Ask nginx to redirect url to www - # # Else, we redirect www to url - # redirect_to_www: no - # # What kind of site is that? - # type: drupal - # # Subnet addresses - # subnet_cidr_address: 172.27.5.0/24 - # subnet_gateway_ip: 172.27.5.1 - # subnet_site_ip: 172.27.5.2 - # # This will allow setting up MySQL - # # Configuration on Drupal's side must be done by hand: - # # Edit your /sites/default/settings.php - # mysql_database: mts8 - # mysql_username: mts - # mysql_password: "{{ vault_mts_mysql_password }}" + - slug: mts # Shorthand name to use as directory/file name + # The site URL (without www) + url: editionsmangetasoupe.fr + # Ask nginx to redirect url to www + # Else, we redirect www to url + redirect_to_www: no + # What kind of site is that? + type: drupal + # Subnet addresses + subnet_cidr_address: 172.27.5.0/24 + subnet_gateway_ip: 172.27.5.1 + subnet_site_ip: 172.27.5.2 + # This will allow setting up MySQL + # Configuration on Drupal's side must be done by hand: + # Edit your /sites/default/settings.php + mysql_database: mts8 + mysql_username: mts + mysql_password: "{{ vault_mts_mysql_password }}" diff --git a/deployer/roles/build/tasks/wordpress.yml b/deployer/roles/build/tasks/wordpress.yml index eb47b24..673fb0e 100644 --- a/deployer/roles/build/tasks/wordpress.yml +++ b/deployer/roles/build/tasks/wordpress.yml @@ -52,6 +52,38 @@ when: wpcontent.stat.exists is not defined or wpcontent.stat.exists == False tags: [docker, nginx] +################# +# Setup backups # +################# + +- name: Setup weekly backup of wp-content + cron: + name: "backup {{ item.slug }}_wp-content" + # hour: "17" + # minute: "37" + special_time: weekly + user: "www-data" + job: "tar czf {{ backups_path }}/{{ item.slug }}_wp-content.tar.gz {{ www_path }}/{{ item.slug }}_wp-content" + become: yes + tags: backup + +- name: Configure logrotate to rotate backups + blockinfile: + path: "/etc/logrotate.d/{{ item.slug }}" + create: yes + block: | + {{ backups_path }}/{{ item.slug }}_wp-content.tar.gz { + rotate 5 + nocompress + dateext + dateformat _%Y-%m-%d + extension .tar.gz + missingok + } + become: yes + tags: backup + + #################### # Render templates # ####################