-
Notifications
You must be signed in to change notification settings - Fork 1
/
playbook.yml
137 lines (129 loc) · 4 KB
/
playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
#
# Create sync folder in all involved server
#
- name: "Create atom sync folder"
hosts: "atom_sites"
gather_facts: False
become: "true"
tasks:
- name: "Create folder"
file:
path: "{{ replication_path }}"
state: "directory"
- name: "get current date and time string"
command: "date +%Y%m%d-%H%M%S"
run_once: true
register: date_result
- name: "Create replication subfolder"
file:
path: "{{ replication_path }}/{{ date_result.stdout }}"
state: directory
- name: "Create replication symlink"
file:
src: "{{ replication_path }}/{{ date_result.stdout }}"
dest: "{{ replication_path }}/last"
state: link
force: yes
#
# Configure ES snapshots in both servers
#
- name: "Setup Elasticsearch snapshot repository"
hosts: "atom_es_source_site,atom_es_destination_site"
become: "yes"
gather_facts: False
tags: ["atom-repository"]
roles:
- role: "atom-repository-config"
es_server_ip: "{{ es_source_site.server }}"
es_server_port: "{{ es_source_site.port }}"
es_path_repo: "{{ elasticsearch_repo_path }}"
es_repo_name: "{{ elasticsearch_repo_name }}"
#
# Create ES snapshot for source site
#
- name: "Take snapshots"
hosts: "atom_es_source_site"
gather_facts: False
become: "yes"
tags: ["atom-snapshot"]
roles:
- role: "atom-snapshot"
es_server_ip: "{{ es_source_site.server }}"
es_server_port: "{{ es_source_site.port }}"
es_path_repo: "{{ elasticsearch_repo_path }}"
es_repo_name: "{{ elasticsearch_repo_name }}"
es_index_name: "{{ es_source_site.index }}"
es_snapshot_name: "{{ elasticsearch_snapshot_name }}"
tasks:
- name: "Fetch ES backup"
fetch:
src: "{{ atom_sync_folder }}/snapshot.tgz"
dest: "replication/snapshot.tgz"
flat: "true"
#
# Create mysql dump for source site
#
- name: "Create mysqldump and get it"
hosts: "atom_mysql_source_site"
gather_facts: False
become: "yes"
vars:
atom_mysql_user: "{{ atom_source_site.atom_db_user }}"
atom_mysql_password: "{{ atom_source_site.atom_db_password }}"
atom_mysql_host: "{{ atom_source_site.atom_db_host }}"
atom_mysql_db: "{{ atom_source_site.atom_db_name }}"
tasks:
- name: "Create source mysqldump"
mysql_db:
name: "{{ atom_source_site.atom_db_name }}"
state: dump
target: "{{ atom_sync_folder }}/{{ atom_mysql_db }}.sql.gz"
- name: "Fetch mysql backup"
fetch:
src: "{{ atom_sync_folder }}/{{ atom_source_site.atom_db_name }}.sql.gz"
dest: "replication/"
flat: "true"
#
# Restore es snapshot in destination site
#
- name: "Restore ES snapshot"
hosts: "atom_es_destination_site"
tags: ["atom-restore"]
gather_facts: False
become: yes
pre_tasks:
- name: "Transfer ES backup"
copy:
src: "replication/snapshot.tgz"
dest: "{{ atom_sync_folder }}/snapshot.tgz"
owner: "elasticsearch"
roles:
- role: "atom-restore"
es_server_ip: "{{ es_dest_site.server }}"
es_server_port: "{{ es_dest_site.port }}"
es_path_repo: "{{ elasticsearch_repo_path }}"
es_repo_name: "{{ elasticsearch_repo_name }}"
es_index_name: "{{ es_source_site.index }}"
es_dest_index_name: "{{ es_dest_site.index }}"
es_snapshot_name: "{{ elasticsearch_snapshot_name }}"
#
# Restore mysql database in destination site
#
- name: "Restore mysql snapshot"
hosts: "atom_mysql_destination_site"
tags: ["atom-restore-mysql"]
gather_facts: False
become: yes
tasks:
- name: "Transfer mysql backup"
copy:
src: "replication/{{ atom_source_site.atom_db_name }}.sql.gz"
dest: "{{ atom_sync_folder }}/"
- name: "Restore mysql database"
mysql_db:
name: "{{ atom_dest_site.atom_db_name }}"
login_user: "{{ atom_dest_site.atom_db_user }}"
login_password: "{{ atom_dest_site.atom_db_password }}"
state: import
target: "{{ atom_sync_folder }}/atom.sql.gz"