2015-08-11 15:22:58 +07:00
|
|
|
---
|
|
|
|
|
|
|
|
# Doc: https://www.percona.com/doc/percona-xtrabackup/2.1/howtos/recipes_ibkx_gtid.html
|
|
|
|
- name: WAIT_FOR | source data (prevent rsync bug) - TODO find another hack
|
2018-03-18 00:28:56 +07:00
|
|
|
wait_for:
|
|
|
|
host: "{{ mariadb_slave_import_from }}"
|
|
|
|
port: 22
|
2015-08-11 15:22:58 +07:00
|
|
|
|
|
|
|
- name: COMMAND | Prepare backup another server
|
2019-04-16 18:55:38 +07:00
|
|
|
command: innobackupex --no-timestamp {{ mariadb_backup_dir }}
|
|
|
|
args:
|
|
|
|
creates: "{{ mariadb_backup_dir }}"
|
2018-03-17 23:28:54 +07:00
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
2015-08-11 15:22:58 +07:00
|
|
|
register: backup
|
|
|
|
|
|
|
|
- name: SHELL | Dump
|
2018-03-18 00:28:56 +07:00
|
|
|
shell: "innobackupex --apply-log {{ mariadb_backup_dir }}"
|
2018-03-17 23:28:54 +07:00
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
2015-08-11 15:22:58 +07:00
|
|
|
when: backup.changed
|
|
|
|
|
|
|
|
- name: FILE | Remove mysql db from backup
|
2018-03-18 00:28:56 +07:00
|
|
|
file:
|
|
|
|
path: "{{ mariadb_backup_dir }}/mysql"
|
|
|
|
state: absent
|
2018-03-17 23:28:54 +07:00
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
|
|
|
when: backup.changed and not mariadb_slave_replicate_mysqldb
|
2015-08-11 15:22:58 +07:00
|
|
|
|
|
|
|
- name: MYSQL_VARIABLES | Get datadir
|
2019-04-16 18:55:38 +07:00
|
|
|
mysql_variables:
|
|
|
|
variable: datadir
|
2015-08-11 15:22:58 +07:00
|
|
|
register: datadir
|
|
|
|
|
|
|
|
- name: SET_FACT | related to mysql datadir
|
|
|
|
set_fact:
|
2018-03-18 00:28:56 +07:00
|
|
|
mariadb_datadir: "{{ datadir.msg }}"
|
2018-03-17 23:28:54 +07:00
|
|
|
mariadb_binlog_info: "{{ datadir.msg }}/xtrabackup_binlog_info"
|
2015-08-11 15:22:58 +07:00
|
|
|
|
2018-03-18 00:47:35 +07:00
|
|
|
- name: SERVICE | Stop MariaDB before importing data
|
2018-03-18 00:28:56 +07:00
|
|
|
service:
|
|
|
|
name: mysql
|
|
|
|
state: stopped
|
2015-08-11 15:22:58 +07:00
|
|
|
|
2017-06-28 21:15:44 +07:00
|
|
|
# TODO: add an "ignore warning"
|
2018-03-17 23:28:54 +07:00
|
|
|
- name: COMMAND | Sync backup to slave - TODO remove vagrant as static user (see why mariadb_backup_user is not working)
|
2018-03-18 00:28:56 +07:00
|
|
|
shell: "sudo -E rsync --rsync-path='sudo rsync' -a -e 'ssh -o StrictHostKeyChecking=no' {{ mariadb_backup_user }}@{{ mariadb_slave_import_from }}:{{ mariadb_backup_dir }}/ {{ mariadb_datadir }}/"
|
2015-08-11 15:22:58 +07:00
|
|
|
become: no
|
|
|
|
|
|
|
|
- name: FILE | Re-apply owner
|
2018-03-18 00:28:56 +07:00
|
|
|
file:
|
|
|
|
path: "{{ mariadb_datadir }}"
|
|
|
|
state: directory
|
|
|
|
owner: mysql
|
|
|
|
group: mysql
|
|
|
|
recurse: yes
|
|
|
|
|
|
|
|
- name: SERVICE | Start MariaDB
|
|
|
|
service:
|
|
|
|
name: mysql
|
|
|
|
state: started
|
2015-08-11 15:22:58 +07:00
|
|
|
|
|
|
|
- name: SHELL | Get master_log_file
|
2018-03-18 00:28:56 +07:00
|
|
|
command: "awk '{ print $1 }' {{ mariadb_binlog_info }}"
|
2015-08-11 15:22:58 +07:00
|
|
|
register: master_log_file
|
|
|
|
|
|
|
|
- name: SHELL | Get master_log_pos
|
2018-03-18 00:28:56 +07:00
|
|
|
command: "awk '{ print $2 }' {{ mariadb_binlog_info }}"
|
2015-08-11 15:22:58 +07:00
|
|
|
register: master_log_pos
|
|
|
|
|
|
|
|
- name: SHELL | Get master GTID
|
2018-03-18 00:28:56 +07:00
|
|
|
command: "awk '{ print $3 }' {{ mariadb_binlog_info }}"
|
2015-08-11 15:22:58 +07:00
|
|
|
register: master_gtid
|
|
|
|
|
|
|
|
- name: SET_FACT | master_log_file
|
|
|
|
set_fact:
|
2018-03-17 23:28:54 +07:00
|
|
|
mariadb_master_log_file: "{{ master_log_file.stdout }}"
|
|
|
|
mariadb_master_log_pos: "{{ master_log_pos.stdout }}"
|
|
|
|
mariadb_master_gtid: "{{ master_gtid.stdout }}"
|
2015-08-11 15:22:58 +07:00
|
|
|
|
|
|
|
- name: FILE | Delete dump
|
2019-04-16 18:55:38 +07:00
|
|
|
file:
|
|
|
|
path: "{{ mariadb_backup_dir }}"
|
|
|
|
state: absent
|
2018-03-17 23:28:54 +07:00
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
|
|
|
when: mariadb_slave_import_flush_dump
|