2015-08-11 15:22:58 +07:00
|
|
|
---
|
|
|
|
|
2019-12-29 01:02:41 +07:00
|
|
|
- name: FILE | Create SSH client dir
|
|
|
|
file:
|
|
|
|
path: "{{ ansible_env.HOME }}/.ssh"
|
|
|
|
state: directory
|
|
|
|
mode: 0700
|
2015-08-11 15:22:58 +07:00
|
|
|
|
2019-12-29 01:02:41 +07:00
|
|
|
- name: OPENSSH_KEYPAIR | Create SSH key
|
|
|
|
openssh_keypair:
|
|
|
|
path: "{{ ansible_env.HOME }}/.ssh/id_rsa"
|
|
|
|
register: gen_ssh
|
|
|
|
|
|
|
|
- block:
|
|
|
|
|
|
|
|
- name: AUTHORIZED_KEY | Auth slave to backup host
|
|
|
|
authorized_key:
|
|
|
|
user: "{{ mariadb_backup_user }}"
|
|
|
|
state: present
|
|
|
|
key: "{{ gen_ssh.public_key }}"
|
|
|
|
|
|
|
|
- name: FILE | Create backup directory
|
|
|
|
file:
|
|
|
|
path: "{{ mariadb_backup_dir }}"
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: COMMAND | Prepare backup another server
|
|
|
|
command: "mariabackup --backup -u root --target-dir={{ mariadb_backup_dir }}"
|
|
|
|
args:
|
|
|
|
creates: "{{ mariadb_backup_dir }}/xtrabackup_info"
|
|
|
|
register: backup
|
|
|
|
|
|
|
|
- name: SHELL | Dump
|
|
|
|
shell: "mariabackup --prepare --target-dir={{ mariadb_backup_dir }}"
|
|
|
|
when: backup.changed
|
|
|
|
register: prep
|
|
|
|
changed_when: "'This target seems to be not prepared yet' in prep.stderr"
|
2015-08-11 15:22:58 +07:00
|
|
|
|
2018-03-17 23:28:54 +07:00
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
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
|
|
|
|
|
2019-12-29 01:02:41 +07:00
|
|
|
- name: SET_FACT | Get MariaDB datadir
|
2015-08-11 15:22:58 +07:00
|
|
|
set_fact:
|
2018-03-18 00:28:56 +07:00
|
|
|
mariadb_datadir: "{{ datadir.msg }}"
|
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
|
|
|
|
|
2019-12-29 01:02:41 +07:00
|
|
|
- name: SHELL | Remove InnoDB redo logs
|
|
|
|
shell: "rm -f {{ mariadb_datadir }}/ib_logfile*"
|
|
|
|
args:
|
|
|
|
removes: "{{ mariadb_datadir }}/ib_logfile0"
|
|
|
|
warn: false
|
|
|
|
|
2018-03-18 00:28:56 +07:00
|
|
|
- name: SERVICE | Start MariaDB
|
|
|
|
service:
|
|
|
|
name: mysql
|
|
|
|
state: started
|
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
|