ansible-mysql/tasks/replication/slave/import_data.yml

85 lines
2.4 KiB
YAML
Raw Permalink Normal View History

---
- name: FILE | Create SSH client dir
ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.ssh"
state: directory
mode: 0700
- name: OPENSSH_KEYPAIR | Create SSH key
2024-08-26 15:12:09 +07:00
community.crypto.openssh_keypair:
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:
- 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
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"
- name: MYSQL_VARIABLES | Get datadir
community.mysql.mysql_variables:
variable: datadir
2022-03-04 16:56:27 +07:00
login_unix_socket: "{{ mariadb_socket }}"
register: datadir
- name: SET_FACT | Get MariaDB datadir
ansible.builtin.set_fact:
2018-03-18 00:28:56 +07:00
mariadb_datadir: "{{ datadir.msg }}"
2018-03-18 00:47:35 +07:00
- name: SERVICE | Stop MariaDB before importing data
ansible.builtin.service:
name: "{{ mariadb_service_name }}"
2018-03-18 00:28:56 +07:00
state: stopped
- name: COMMAND | Sync backup to slave
ansible.builtin.command: "sudo -E rsync --rsync-path='sudo rsync' --delete -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:
2018-03-18 00:28:56 +07:00
path: "{{ mariadb_datadir }}"
state: directory
mode: 0755
2018-03-18 00:28:56 +07:00
owner: mysql
group: mysql
recurse: true
2018-03-18 00:28:56 +07:00
- name: SERVICE | Start MariaDB
ansible.builtin.service:
name: "{{ mariadb_service_name }}"
2018-03-18 00:28:56 +07:00
state: started
- name: FILE | Delete dump
ansible.builtin.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