diff --git a/docs/roles/_init.md b/docs/roles/_init.md index d561aac2..98179138 100644 --- a/docs/roles/_init.md +++ b/docs/roles/_init.md @@ -16,6 +16,8 @@ deploy_user: "deploy" _mysqldump_params: "--max-allowed-packet=128M --single-transaction --skip-opt -e --quick --skip-disable-keys --skip-add-locks -C -a --add-drop-table" drupal: drush_verbose_output: false + # when set to true - truncate database table cache_container, a workaround to resolve the 'Cannot redeclare ...' error. + truncate_cache_table: false sites: - folder: "default" public_files: "sites/default/files" diff --git a/docs/roles/database_backup/database_backup-mysql.md b/docs/roles/database_backup/database_backup-mysql.md index 1200f97f..b2c79799 100644 --- a/docs/roles/database_backup/database_backup-mysql.md +++ b/docs/roles/database_backup/database_backup-mysql.md @@ -1,5 +1,20 @@ # MySQL backups Generate MySQL backups for each build. + +## Replicas +If you are using a read only replica in your application and you need to add it to `databases` in order to have access to the credentials for your app settings, be sure to set the database up in a similar way to this: + +```yaml +mysql_backup: + databases: + - database: "{{ (project_name + '_' + build_type) | regex_replace('-', '_') }}" + user: "{{ (project_name + '_' + build_type) | truncate(32, true, '', 0) }}" + credentials_file: "/home/{{ deploy_user }}/.mysql.creds" + handling: none # prevents the replica from being backed up + is_replica: true # tells ce-deploy we are working with a replica, so it will implement a pause + pause_seconds: 30 # duration of the pause in seconds +``` + ## Default variables ```yaml @@ -27,7 +42,9 @@ mysql_backup: - database: "{{ (project_name + '_' + build_type) | regex_replace('-', '_') }}" # avoid hyphens in MySQL database names user: "{{ (project_name + '_' + build_type) | truncate(32, true, '', 0) }}" # 32 char limit credentials_file: "/home/{{ deploy_user }}/.mysql.creds" - #handling: static # optional override to the main handling method on a per database basis + #handling: none # optional override to the main handling method on a per database basis - must be 'none' for replicas + #is_replica: true # tell ce-deploy this database is a replica + #pause_seconds: 30 # how long to allow for replication to catch up, required if 'is_replica' is set to 'true' ``` diff --git a/roles/_init/README.md b/roles/_init/README.md index d561aac2..98179138 100644 --- a/roles/_init/README.md +++ b/roles/_init/README.md @@ -16,6 +16,8 @@ deploy_user: "deploy" _mysqldump_params: "--max-allowed-packet=128M --single-transaction --skip-opt -e --quick --skip-disable-keys --skip-add-locks -C -a --add-drop-table" drupal: drush_verbose_output: false + # when set to true - truncate database table cache_container, a workaround to resolve the 'Cannot redeclare ...' error. + truncate_cache_table: false sites: - folder: "default" public_files: "sites/default/files" diff --git a/roles/database_backup/database_backup-mysql/README.md b/roles/database_backup/database_backup-mysql/README.md index 1200f97f..b2c79799 100644 --- a/roles/database_backup/database_backup-mysql/README.md +++ b/roles/database_backup/database_backup-mysql/README.md @@ -1,5 +1,20 @@ # MySQL backups Generate MySQL backups for each build. + +## Replicas +If you are using a read only replica in your application and you need to add it to `databases` in order to have access to the credentials for your app settings, be sure to set the database up in a similar way to this: + +```yaml +mysql_backup: + databases: + - database: "{{ (project_name + '_' + build_type) | regex_replace('-', '_') }}" + user: "{{ (project_name + '_' + build_type) | truncate(32, true, '', 0) }}" + credentials_file: "/home/{{ deploy_user }}/.mysql.creds" + handling: none # prevents the replica from being backed up + is_replica: true # tells ce-deploy we are working with a replica, so it will implement a pause + pause_seconds: 30 # duration of the pause in seconds +``` + ## Default variables ```yaml @@ -27,7 +42,9 @@ mysql_backup: - database: "{{ (project_name + '_' + build_type) | regex_replace('-', '_') }}" # avoid hyphens in MySQL database names user: "{{ (project_name + '_' + build_type) | truncate(32, true, '', 0) }}" # 32 char limit credentials_file: "/home/{{ deploy_user }}/.mysql.creds" - #handling: static # optional override to the main handling method on a per database basis + #handling: none # optional override to the main handling method on a per database basis - must be 'none' for replicas + #is_replica: true # tell ce-deploy this database is a replica + #pause_seconds: 30 # how long to allow for replication to catch up, required if 'is_replica' is set to 'true' ``` diff --git a/roles/database_backup/database_backup-mysql/defaults/main.yml b/roles/database_backup/database_backup-mysql/defaults/main.yml index 1091f8d7..23fa413a 100644 --- a/roles/database_backup/database_backup-mysql/defaults/main.yml +++ b/roles/database_backup/database_backup-mysql/defaults/main.yml @@ -22,4 +22,6 @@ mysql_backup: - database: "{{ (project_name + '_' + build_type) | regex_replace('-', '_') }}" # avoid hyphens in MySQL database names user: "{{ (project_name + '_' + build_type) | truncate(32, true, '', 0) }}" # 32 char limit credentials_file: "/home/{{ deploy_user }}/.mysql.creds" - #handling: static # optional override to the main handling method on a per database basis + #handling: none # optional override to the main handling method on a per database basis - must be 'none' for replicas + #is_replica: true # tell ce-deploy this database is a replica + #pause_seconds: 30 # how long to allow for replication to catch up, required if 'is_replica' is set to 'true' diff --git a/roles/database_backup/database_backup-mysql/tasks/deploy-none.yml b/roles/database_backup/database_backup-mysql/tasks/deploy-none.yml index 4c4b1624..aa8c7317 100644 --- a/roles/database_backup/database_backup-mysql/tasks/deploy-none.yml +++ b/roles/database_backup/database_backup-mysql/tasks/deploy-none.yml @@ -4,6 +4,13 @@ - ansible.builtin.set_fact: _mysql_previous_build_database_name: "{{ database.database }}" +- name: Pause to allow replication to catch up. + ansible.builtin.pause: + seconds: "{{ database.pause_seconds }}" + when: + - database.is_replica is defined + - database.is_replica + - name: Check if the database exists already. ansible.builtin.shell: "set -o pipefail && mysql --defaults-extra-file={{ database.credentials_file }} -e 'SHOW DATABASES;' | grep -w {{ _mysql_build_database_name }}" register: _build_db_status