Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5fefc81
db_import_speed_up
tymofiisobchenko Jun 21, 2023
69579e4
db_import_speed_up_fixed
tymofiisobchenko Jun 21, 2023
04e3098
Merge branch '1.x' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
2528b95
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
dbcd09e
db_import_speed_up_fix2
tymofiisobchenko Jun 21, 2023
d77f0a1
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
187e503
db_import_speed_up_fix3
tymofiisobchenko Jun 21, 2023
85ed194
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
d284adb
db_import_speed_up_fix4
tymofiisobchenko Jun 21, 2023
0f33ea8
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
5c845f8
db_import_speed_up_fix5_and_gzip
tymofiisobchenko Jun 21, 2023
ccdf4a3
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
0976176
db_import_speed_up_fix6
tymofiisobchenko Jun 21, 2023
5c6fa84
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
061b7ab
db_import_speed_up_fix7
tymofiisobchenko Jun 21, 2023
b858a08
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
43c8c74
db_import_speed_up_fix_typo
tymofiisobchenko Jun 21, 2023
ed9673c
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
f0aec2e
db_import_speed_up_fix8
tymofiisobchenko Jun 21, 2023
2de265e
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
5463a5b
db_import_speed_up_fix9
tymofiisobchenko Jun 21, 2023
1024820
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 21, 2023
85d648a
db_import_speed_up_refactoring
tymofiisobchenko Jun 22, 2023
5e67cdb
Merge branch 'db_import_speed_up' into db_import_speed_up-PR-1.x
tymofiisobchenko Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
---
- name: Unpack dump file.
ansible.builtin.unarchive:
src: "{{ mysql_backup.dumps_directory }}/{{ _mysql_host }}/{{ database.database }}-{{ previous_build_number }}.sql.bz2"
dest: "/tmp/{{ database.database }}-{{ previous_build_number }}.sql"
remote_src: true
run_once: true
when: previous_build_number > 0

- name: Revert database from dump.
ansible.builtin.shell: "set -o pipefail && bzcat {{ mysql_backup.dumps_directory }}/{{ _mysql_host }}/{{ database.database }}-{{ previous_build_number }}.sql.bz2 | mysql --defaults-extra-file={{ database.credentials_file }} {{ database.database }}"
ansible.builtin.shell: "mysql --defaults-extra-file={{ database.credentials_file }} {{ database.database }} < /tmp/{{ database.database }}-{{ previous_build_number }}.sql"
args:
executable: /bin/bash
run_once: true
when: previous_build_number > 0

- name: Delete unpacked dump file.
ansible.builtin.file:
path: "/tmp/{{ database.database }}-{{ previous_build_number }}.sql"
state: absent
run_once: true
when: previous_build_number > 0
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
mysql_sync:
mysqldump_params: "{{ _mysqldump_params }}" # set in _init but you can override here
cleanup: true # if false leaves tmp database dump on deploy server for debugging purposes
mysqldump_params: "{{ _mysqldump_params }}" # set in _init but you can override here.
cleanup: true # if false leaves tmp database dump on deploy server for debugging purposes.
archival_method: "bzip2" # oprions are "bzip2" or "gzip".
databases:
- source:
# Name of the database to take a dump from.
Expand Down
50 changes: 41 additions & 9 deletions roles/sync/database_sync/database_sync-mysql/tasks/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,24 @@
- database.target.asg is defined
- database.target.asg | length > 0


- name: Register bzip2 archive type vars.
ansible.builtin.set_fact:
archive_file_type: "bz2"
archival_command: "bzip2"
when:
- mysql_sync.archival_method == 'bzip2'

- name: Register gunzip archive type vars.
ansible.builtin.set_fact:
archive_file_type: "gz"
archival_command: "gzip"
when:
- mysql_sync.archival_method == 'gzip'

- name: Register remote dump name (from database).
ansible.builtin.set_fact:
mysql_sync_source_dump_path: "/tmp/{{ database.source.database }}_{{ build_number }}_source.sql.bz2"
mysql_sync_source_dump_path: "/tmp/{{ database.source.database }}_{{ build_number }}_source.sql.{{ archive_file_type }}"

- name: Get source last known good build number.
ansible.builtin.command:
Expand All @@ -61,7 +76,7 @@
when: not database.source.type == 'rolling'

- name: Take a dump from source database.
ansible.builtin.shell: "set -o pipefail && mysqldump --defaults-extra-file={{ database.source.credentials_file }} {{ mysql_sync.mysqldump_params }} {{ mysql_sync_source_database }} | bzip2 > {{ mysql_sync_source_dump_path }}"
ansible.builtin.shell: "set -o pipefail && mysqldump --defaults-extra-file={{ database.source.credentials_file }} {{ mysql_sync.mysqldump_params }} {{ mysql_sync_source_database }} | {{ archival_command }} > {{ mysql_sync_source_dump_path }}"
args:
executable: /bin/bash
delegate_to: "{{ database.source.host }}"
Expand Down Expand Up @@ -91,7 +106,11 @@

- name: Register tmp target dump name.
ansible.builtin.set_fact:
mysql_sync_target_dump_path: "/tmp/{{ database.target.database }}_{{ build_number }}_target.sql.bz2"
mysql_sync_target_dump_path: "/tmp/{{ database.target.database }}_{{ build_number }}_target.sql.{{ archive_file_type }}"

- name: Register tmp unpacked target dump name.
ansible.builtin.set_fact:
mysql_sync_target_dump_unpacked_path: "/tmp/{{ database.target.database }}_{{ build_number }}_target.sql"

- name: Get target last known good build number.
ansible.builtin.command:
Expand All @@ -117,15 +136,25 @@
- name: Fetch dump file.
ansible.builtin.fetch:
src: "{{ mysql_sync_source_dump_path }}"
dest: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.bz2"
dest: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.{{ archive_file_type }}"
flat: true
delegate_to: "{{ database.source.host }}"

- name: Copy dump file to destination.
ansible.builtin.copy:
src: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.bz2"
src: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.{{ archive_file_type }}"
dest: "{{ mysql_sync_target_dump_path }}"

- name: Unpack dump file.
ansible.builtin.shell: "{{ archival_command }} -d -c {{ mysql_sync_target_dump_path }} > {{ mysql_sync_target_dump_unpacked_path }}"
args:
executable: /bin/bash

- name: Delete temporary dump file on target.
ansible.builtin.file:
path: "{{ mysql_sync_target_dump_path }}"
state: absent

- name: Drop target database.
ansible.builtin.command:
cmd: "mysql --defaults-extra-file={{ database.target.credentials_file }} -e 'drop database if exists {{ mysql_sync_target_database }};'"
Expand All @@ -135,13 +164,13 @@
cmd: "mysql --defaults-extra-file={{ database.target.credentials_file }} -e 'create database {{ mysql_sync_target_database }};'"

- name: Repopulate database from dump.
ansible.builtin.shell: "set -o pipefail && bzcat {{ mysql_sync_target_dump_path }} | mysql --defaults-extra-file={{ database.target.credentials_file }} {{ mysql_sync_target_database }}"
ansible.builtin.shell: "mysql --defaults-extra-file={{ database.target.credentials_file }} {{ mysql_sync_target_database }} < {{ mysql_sync_target_dump_unpacked_path }}"
args:
executable: /bin/bash

- name: Delete temporary dump file on target.
- name: Delete temporary unpacked dump file on target.
ansible.builtin.file:
path: "{{ mysql_sync_target_dump_path }}"
path: "{{ mysql_sync_target_dump_unpacked_path }}"
state: absent

- name: Delete temporary dump file on source.
Expand All @@ -152,11 +181,14 @@

- name: Delete temporary dump file on deploy server.
ansible.builtin.file:
path: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.bz2"
path: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql{{ item }}"
state: absent
delegate_to: localhost
when:
- mysql_sync.cleanup
with_items:
- ".bz2"
- ".gz"

- name: Enable all autoscale processes on source ASG.
ansible.builtin.command: >
Expand Down