Closed apmarshall closed 7 years ago
Have you tested this ? I am pretty confident this won't work : backup_mysql_user
and backup_mysql_pass
is global to the backup role, so it will fail if you have several websites.
Closing the issue for the moment.
Fair enough, I have only tested this using trellis configs with one site, not trellis configs backing multiple sites. It worked fine, but it only had one option to choose from, so not sure how it would behave if we had multiple sites defined.
Can we make this a loop so that we create a backup_mysql_user
and pass
for each site in trellis's wordpress_sites
file? I'm looking at how trellis makes mysql users in the wordpress-setup
role, looks like they use site_env.**
and with_dict: "{{ wordpress_sites }}"
to loop through each site and create database and user for them all. I'm relatively new to tinkering with Ansible roles, so I'm not sure how this would work with defining a variable in Ansible, but maybe we move this step into the profile creation instead of using it as a global?
Something like this:
# Backup database
- name: "{{ item.key }}_database"
schedule: "{{ item.value.backup.schedule | default(omit) }}"
source: "mysql://{{ item.key | underscore }}_{{ env }}"
backup_mysql_user: "{{ site_env.db_user }}"
backup_mysql_pass: "{{ site_env.db_password }}"
target: "{{ item.value.backup.target }}/database"
target_user: "{{ site_env.backup_target_user }}"
target_pass: "{{ site_env.backup_target_pass }}"
params: "{{ item.value.backup.params | default([]) }}"
action: "{{ site_purge_backup | ternary('purge_backup --force', 'backup') }}"
Trellis handily provides us with an existing database user and password that we can borrow for running backups, which avoids either needing to use root (or mysql root) or needing to create a new database user.