90 lines
2.6 KiB
YAML
90 lines
2.6 KiB
YAML
---
|
|
|
|
- name: FILE | Create SSH client dir
|
|
ansible.builtin.file:
|
|
path: "{{ ansible_env.HOME }}/.ssh"
|
|
state: directory
|
|
mode: 0700
|
|
|
|
- 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
|
|
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
|
|
|
|
- name: COMMAND | Dump
|
|
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"
|
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
|
|
|
- name: MYSQL_VARIABLES | Get datadir
|
|
community.mysql.mysql_variables:
|
|
variable: datadir
|
|
register: datadir
|
|
|
|
- name: SET_FACT | Get MariaDB datadir
|
|
ansible.builtin.set_fact:
|
|
mariadb_datadir: "{{ datadir.msg }}"
|
|
|
|
- name: SERVICE | Stop MariaDB before importing data
|
|
ansible.builtin.service:
|
|
name: "{{ mariadb_service_name }}"
|
|
state: stopped
|
|
|
|
- name: COMMAND | Sync backup to slave - TODO remove vagrant as static user (see why mariadb_backup_user is not working)
|
|
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
|
|
|
|
- name: FILE | Re-apply owner
|
|
ansible.builtin.file:
|
|
path: "{{ mariadb_datadir }}"
|
|
state: directory
|
|
mode: 0755
|
|
owner: mysql
|
|
group: mysql
|
|
recurse: true
|
|
|
|
- name: SHELL | Remove InnoDB redo logs
|
|
ansible.builtin.shell: "rm -f {{ mariadb_datadir }}/ib_logfile*"
|
|
args:
|
|
removes: "{{ mariadb_datadir }}/ib_logfile0"
|
|
warn: false
|
|
|
|
- name: SERVICE | Start MariaDB
|
|
ansible.builtin.service:
|
|
name: "{{ mariadb_service_name }}"
|
|
state: started
|
|
|
|
- name: FILE | Delete dump
|
|
ansible.builtin.file:
|
|
path: "{{ mariadb_backup_dir }}"
|
|
state: absent
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
|
when: mariadb_slave_import_flush_dump
|