2015-08-11 15:22:58 +07:00
|
|
|
---
|
|
|
|
|
2019-12-29 01:02:41 +07:00
|
|
|
- name: FILE | Create SSH client dir
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.file:
|
2019-12-29 01:02:41 +07:00
|
|
|
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
|
2024-08-26 15:12:09 +07:00
|
|
|
community.crypto.openssh_keypair:
|
2019-12-29 01:02:41 +07:00
|
|
|
path: "{{ ansible_env.HOME }}/.ssh/id_rsa"
|
|
|
|
register: gen_ssh
|
|
|
|
|
2024-08-26 15:12:09 +07:00
|
|
|
- name: BLOCK | Prepare backup
|
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
|
|
|
block:
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2021-09-02 23:17:54 +07:00
|
|
|
- name: AUTHORIZED_KEY | Auth slave to backup host
|
|
|
|
ansible.posix.authorized_key:
|
|
|
|
user: "{{ mariadb_backup_user }}"
|
|
|
|
state: present
|
|
|
|
key: "{{ gen_ssh.public_key }}"
|
|
|
|
|
|
|
|
- name: FILE | Create backup directory
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ mariadb_backup_dir }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0755
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
- name: COMMAND | Prepare backup another server
|
|
|
|
ansible.builtin.command: "mariabackup --backup -u root --target-dir={{ mariadb_backup_dir }}"
|
|
|
|
args:
|
|
|
|
creates: "{{ mariadb_backup_dir }}/xtrabackup_info"
|
|
|
|
register: backup
|
|
|
|
|
2024-08-26 15:12:09 +07:00
|
|
|
- name: COMMAND | Dump # noqa: no-handler
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.command: "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
|
|
|
|
|
|
|
- name: MYSQL_VARIABLES | Get datadir
|
2021-09-02 23:17:54 +07:00
|
|
|
community.mysql.mysql_variables:
|
2019-04-16 18:55:38 +07:00
|
|
|
variable: datadir
|
2022-03-04 16:56:27 +07:00
|
|
|
login_unix_socket: "{{ mariadb_socket }}"
|
2015-08-11 15:22:58 +07:00
|
|
|
register: datadir
|
|
|
|
|
2019-12-29 01:02:41 +07:00
|
|
|
- name: SET_FACT | Get MariaDB datadir
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.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
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.service:
|
|
|
|
name: "{{ mariadb_service_name }}"
|
2018-03-18 00:28:56 +07:00
|
|
|
state: stopped
|
2015-08-11 15:22:58 +07:00
|
|
|
|
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)
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.command: "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 }}/"
|
|
|
|
become: false
|
|
|
|
tags:
|
|
|
|
- skip_ansible_lint
|
2015-08-11 15:22:58 +07:00
|
|
|
|
|
|
|
- name: FILE | Re-apply owner
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.file:
|
2018-03-18 00:28:56 +07:00
|
|
|
path: "{{ mariadb_datadir }}"
|
|
|
|
state: directory
|
2021-09-02 23:17:54 +07:00
|
|
|
mode: 0755
|
2018-03-18 00:28:56 +07:00
|
|
|
owner: mysql
|
|
|
|
group: mysql
|
2021-09-02 23:17:54 +07:00
|
|
|
recurse: true
|
2018-03-18 00:28:56 +07:00
|
|
|
|
2019-12-29 01:02:41 +07:00
|
|
|
- name: SHELL | Remove InnoDB redo logs
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.shell: "rm -f {{ mariadb_datadir }}/ib_logfile*"
|
2019-12-29 01:02:41 +07:00
|
|
|
args:
|
|
|
|
removes: "{{ mariadb_datadir }}/ib_logfile0"
|
|
|
|
warn: false
|
|
|
|
|
2018-03-18 00:28:56 +07:00
|
|
|
- name: SERVICE | Start MariaDB
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.service:
|
|
|
|
name: "{{ mariadb_service_name }}"
|
2018-03-18 00:28:56 +07:00
|
|
|
state: started
|
2015-08-11 15:22:58 +07:00
|
|
|
|
|
|
|
- name: FILE | Delete dump
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.file:
|
2019-04-16 18:55:38 +07:00
|
|
|
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
|