-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_reseed-innobackupex.yml
148 lines (106 loc) · 4.77 KB
/
db_reseed-innobackupex.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
138
139
140
141
142
143
144
145
146
147
148
---
- hosts: dbtraining002
remote_user: me
become: yes
become_user: root
become_method: sudo
gather_facts: True
vars_files:
- vars/main.yml
tasks:
- name: Stop MySQL on the Slave
service: name=mysql state=stopped
delegate_to: dbtraining003
- name: Delete data in data01 logs01
shell: rm -rf /db/{data01/*,logs01/*}
delegate_to: dbtraining003
- name: wait for ibdata01 to be deleted
wait_for: path=/db/data01/ibdata1 state=absent
delegate_to: dbtraining003
- name: Clean any failed screen sessions on the slave
shell: screen -ls | grep migrate | cut -d. -f1 | awk '{print $1}' | xargs kill 2>>/dev/null
delegate_to: dbtraining003
ignore_errors: yes
- name: Clean any failed screen sessions on the Master
command: screen -wipe
ignore_errors: yes
- name: start listener on slave
shell: screen -S migrate -md bash -c 'nc -l 4000 > data01-$(date +%F).xbstream && sha1sum data01-$(date +%F).xbstream > destination_checksum' chdir=/db/backup
#shell: screen -S migrate -md bash -c 'nc -l 4000 | tee >( sha1sum > dvd.sha1 ) >( sha1sum > dvd.sha2 ) > data01-$( date +%F ).xbstream' chdir=/db/backup
#shell: screen -S migrate -md bash -c 'nc -l 4000 | tee >(sha1sum > destination_checksum) > data01-$(date +%F).tgz' chdir=/db/backup
async: 45
poll: 0
register: migrate_nc
delegate_to: dbtraining003
failed_when: migrate_nc.rc != 0
changed_when: migrate_nc.rc == 0
- name: start transfer on master
shell: screen -S migrate2 -md bash -c 'innobackupex --compress --compress-threads=1 --stream=xbstream --parallel=1 /db/data01 | tee >( sha1sum > source_checksum ) | nc x.x.x.x 4000'
#args:
# chdir: /db
register: migrate_nc2
failed_when: migrate_nc2.rc != 0
changed_when: migrate_nc2.rc == 0
#- name: Pause for 10 seconds
# pause: seconds=10
- name: Get pid of screen session on the Master
command: pgrep screen
register: p_screen
#ignore_errors: yes
#- debug: p_screen
- name: Wait for screen session on Master to complete
wait_for: path=/proc/{{ p_screen.stdout }}/status state=absent
- hosts: dbtraining003
remote_user: me
become: yes
become_user: root
become_method: sudo
gather_facts: True
vars_files:
- vars/main.yml
tasks:
- name: extract the xbstream files
shell: xbstream -xv < data01-$(date +%F).xbstream -C /db/data01
args:
chdir: /db/backup
- name: extract qpress files
command: find /db/data01 -name "*.qp" -execdir qpress -dv \{\} . \; -exec rm {} \;
- name: apply logs
command: innobackupex --apply-log --use-memory=2G /db/data01/
- name: move logs to /db/logs01
command: mv ib_logfile0 ib_logfile1 ib_logfile2 /db/logs01/
args:
chdir: /db/data01
- name: Change owner ship to mysql of directories under /db
file:
path: /db
state: directory
recurse: True
mode: 0750
owner: mysql
group: mysql
- name: change owner ship to mysql of files under /db
command: find /db/data01/ -type f -exec chmod 640 '{}' \;
- name: Remove auto.cnf from /db/data01 dir on Slave
file: path=/db/data01/auto.cnf state=absent
- name: Start MySQL on the Slave
service: name=mysql state=started
- name: cat xtrabackup_binlog file
shell: cat xtrabackup_binlog_pos_innodb | awk '{ print $1 }' | cut -d'/' -f4
args:
chdir: /db/data01
register: xtra1_file
- debug: var=xtra1_file.stdout
- name: cat xtrabackup_binlog2 file
shell: cat xtrabackup_binlog_pos_innodb | awk '{ print $2 }'
args:
chdir: /db/data01
register: xtra2_file
- debug: var=xtra2_file.stdout
- name: Stop Replication
mysql_replication: mode=stopslave login_user=root login_password={{ mysql_root_pass }}
- name: Change master to start replication on Slave
mysql_replication: mode=changemaster master_host=x.x.x.x master_user=repl master_password={{ mysql_repl_pass }} master_log_file={{ xtra1_file.stdout }} master_log_pos={{ xtra2_file.stdout }} login_user=root login_password={{ mysql_root_pass }}
ignore_errors: yes
- name: Start Replication on Slave
mysql_replication: mode=startslave login_user=root login_password={{ mysql_root_pass }}