Skip to content

Commit fd7c17d

Browse files
authored
Making syncs safer and more efficient. (#273)
1 parent aa9d3b0 commit fd7c17d

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

roles/sync/database_sync/database_sync-mysql/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
mysql_sync:
33
mysqldump_params: "{{ _mysqldump_params }}" # set in _init but you can override here
4+
cleanup: true # if false leaves tmp database dump on deploy server for debugging purposes
45
databases:
56
- source:
67
# Name of the database to take a dump from.

roles/sync/database_sync/database_sync-mysql/tasks/sync.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@
104104
delegate_to: localhost
105105
when: database.target.type == 'rolling'
106106

107-
- name: Register target database name.
107+
- name: Register target rolling database name.
108108
ansible.builtin.set_fact:
109109
mysql_sync_target_database: "{{ database.target.database }}_{{ mysql_sync_target_build_number.stdout }}"
110110
when: database.target.type == 'rolling'
111111

112-
- name: Register target database name.
112+
- name: Register target static database name.
113113
ansible.builtin.set_fact:
114114
mysql_sync_target_database: "{{ database.target.database }}"
115115
when: not database.target.type == 'rolling'
@@ -139,11 +139,25 @@
139139
args:
140140
executable: /bin/bash
141141

142-
- name: Remove tmp dump file.
142+
- name: Delete temporary dump file on target.
143143
ansible.builtin.file:
144144
path: "{{ mysql_sync_target_dump_path }}"
145145
state: absent
146146

147+
- name: Delete temporary dump file on source.
148+
ansible.builtin.file:
149+
path: "{{ mysql_sync_source_dump_path }}"
150+
state: absent
151+
delegate_to: "{{ database.source.host }}"
152+
153+
- name: Delete temporary dump file on deploy server.
154+
ansible.builtin.file:
155+
path: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.bz2"
156+
state: absent
157+
delegate_to: localhost
158+
when:
159+
- mysql_sync.cleanup
160+
147161
- name: Enable all autoscale processes on source ASG.
148162
ansible.builtin.command: >
149163
aws autoscaling resume-processes --auto-scaling-group-name {{ database.source.asg }} --region {{ mysql_sync_source_database_host_info.ansible_facts.ansible_ec2_instance_identity_document_region }}

roles/sync/files_sync/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
22
files_sync:
3+
unique_workspace: false # set to true to grab a complete full set of files every sync
4+
# Generally speaking you will *not* want to clean up after file syncs, as leaving the files there makes the next rsync far quicker.
5+
cleanup: false # set to true to delete the synced files after a sync
36
directories:
47
- source:
58
# Location of the files to sync from. DO NOT INCLUDE TRAILING SLASH!

roles/sync/files_sync/tasks/sync.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
---
22
- name: Register file sync location.
3+
ansible.builtin.set_fact:
4+
file_sync_path: "{{ files.source.temp_dir }}/{{ files.source.build_id }}"
5+
6+
- name: Register unique file sync location.
37
ansible.builtin.set_fact:
48
file_sync_path: "{{ files.source.temp_dir }}/{{ files.source.build_id }}_{{ build_number }}"
9+
when: files_sync.unique_workspace
510

611
- name: Create a temporary directory for source files on localhost.
712
ansible.builtin.file:
@@ -15,11 +20,19 @@
1520
- name: Copy the source files onto the deploy server.
1621
ansible.builtin.command:
1722
cmd: "rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -aHPv {{ files.source.host }}:{{ files.source.files_dir }}/ {{ file_sync_path }}/"
18-
delegate_to: "localhost"
23+
delegate_to: localhost
1924
run_once: true
2025

2126
- name: Copy the source files from the deploy server onto the destination server.
2227
ansible.builtin.command:
2328
cmd: "rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -aHPv {{ file_sync_path }}/ {{ ansible_play_hosts[0] }}:{{ files.target.files_dir }}/"
24-
delegate_to: "localhost"
29+
delegate_to: localhost
2530
run_once: true
31+
32+
- name: Delete synced files on deploy server.
33+
ansible.builtin.file:
34+
path: "{{ file_sync_path }}"
35+
state: absent
36+
delegate_to: localhost
37+
when:
38+
- files_sync.cleanup

0 commit comments

Comments
 (0)