Working on adding mysql backups to the new docker_borg_backup role
This commit is contained in:
1 parent
c577141055
commit
bc21a7bf42
8 files changed
+94
-13
No files matched your search
@@ -5,3 +5,4 @@ borg_password: ""
|
|||||||
borg_async_time: 7200
|
borg_async_time: 7200
|
||||||
borg_poll_time: 30
|
borg_poll_time: 30
|
||||||
directories_to_backup: "{{ [] }}"
|
directories_to_backup: "{{ [] }}"
|
||||||
|
mysql_backups: "{{ [] }}"
|
||||||
@@ -36,6 +36,20 @@
|
|||||||
async: "{{ borg_async_time }}"
|
async: "{{ borg_async_time }}"
|
||||||
poll: "{{ borg_poll_time }}"
|
poll: "{{ borg_poll_time }}"
|
||||||
|
|
||||||
|
- name: Take mysql backups
|
||||||
|
ansible.builtin.import_role:
|
||||||
|
name: mysql_borg_backup
|
||||||
|
vars:
|
||||||
|
mysql_target: "{{ item['mysql_backup_target'] }}"
|
||||||
|
mysql_target_port: "{{ item['mysql_backup_target_port'] }}"
|
||||||
|
mysql_target_username: "{{ item['mysql_backup_target_username'] }}"
|
||||||
|
mysql_target_password: "{{ item['mysql_backup_target_password'] }}"
|
||||||
|
mysql_target_database_name: "{{ item['mysql_backup_target_database_name'] }}"
|
||||||
|
mysql_borg_repo_name: "{{ item['mysql_backup_borg_repo_name'] }}"
|
||||||
|
mysql_borg_password: "{{ item['mysql_backup_borg_password'] }}"
|
||||||
|
loop: "{{ mysql_backups }}"
|
||||||
|
when: mysql_backups | default([]) | length != 0
|
||||||
|
|
||||||
- name: Start containers
|
- name: Start containers
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
|
|||||||
@@ -1,2 +1,9 @@
|
|||||||
---
|
---
|
||||||
# defaults file for mysql_borg_backup
|
mysql_target: ""
|
||||||
|
mysql_target_port: 3306
|
||||||
|
mysql_target_username: ""
|
||||||
|
mysql_target_password: ""
|
||||||
|
mysql_target_database_name: ""
|
||||||
|
temp_backup_location: "/tmp"
|
||||||
|
mysql_borg_repo_name: ""
|
||||||
|
mysql_borg_password: ""
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
---
|
|
||||||
# handlers file for mysql_borg_backup
|
|
||||||
@@ -1,2 +1,72 @@
|
|||||||
---
|
---
|
||||||
# tasks file for mysql_borg_backup
|
- name: Fail if a target is not specified
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "You must specify a mysql_target address"
|
||||||
|
when: mysql_target | default("") | length == 0
|
||||||
|
|
||||||
|
- name: Fail if a target port is not specified
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "You must specify a mysql_target_port"
|
||||||
|
when: mysql_target_port | default(0) == 0
|
||||||
|
|
||||||
|
- name: Fail if a target username is not specified
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "You must specify a mysql_target_username"
|
||||||
|
when: mysql_target_username | default("") | length == 0
|
||||||
|
|
||||||
|
- name: Fail if a target password is not specified
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "You must specify a mysql_target_password"
|
||||||
|
when: mysql_target_password | default("") | length == 0
|
||||||
|
|
||||||
|
- name: Fail if target database name is not specified
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "You must specify a mysql_target_database_name"
|
||||||
|
when: mysql_target_database_name | default("") | length == 0
|
||||||
|
|
||||||
|
- name: Fail if borg repo name is not specified
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "You must specify a mysql_borg_repo_name"
|
||||||
|
when: mysql_borg_repo_name | default("") | length == 0
|
||||||
|
|
||||||
|
- name: Fail if borg repo password is not specified
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "You must specify a mysql_borg_password"
|
||||||
|
when: mysql_borg_password | default("") | length == 0
|
||||||
|
|
||||||
|
- name: Ensure necessary packages are installed
|
||||||
|
ansible.builtin.package:
|
||||||
|
name:
|
||||||
|
- "python3-PyMySQL"
|
||||||
|
- "mysql"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Make sure backup dir exists
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ temp_backup_location }}"
|
||||||
|
state: directory
|
||||||
|
recurse: true
|
||||||
|
|
||||||
|
- name: Take a backup of the specified database
|
||||||
|
ansible.mysql.mysql_db:
|
||||||
|
name: "{{ mysql_target_database_name }}"
|
||||||
|
state: dump
|
||||||
|
target: "{{ temp_backup_location }}/{{ mysql_target_database_name }}.sql.gz"
|
||||||
|
login_host: "{{ mysql_target }}"
|
||||||
|
login_port: "{{ mysql_target_port }}"
|
||||||
|
login_user: "{{ mysql_target_username }}"
|
||||||
|
login_password: "{{ mysql_target_password }}"
|
||||||
|
|
||||||
|
- name: Attempt to trigger a borg backup
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: >
|
||||||
|
export BORG_PASSPHRASE={{ mysql_borg_password }};
|
||||||
|
borg create --stats --progress --compression lz4
|
||||||
|
ssh://borg@10.42.0.3:2222/var/backups/borg/{{ mysql_borg_repo_name }}::{now:%Y-%m-%d-%H-%M-%S}
|
||||||
|
{{ temp_backup_location }}/{{ mysql_target_database_name }}.sql.gz
|
||||||
|
register: mysql_borg_backup
|
||||||
|
|
||||||
|
- name: Remove the backup file now that it's backed up
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ temp_backup_location }}/{{ mysql_target_database_name }}.sql.gz"
|
||||||
|
state: absent
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
localhost
|
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
- hosts: localhost
|
|
||||||
remote_user: root
|
|
||||||
roles:
|
|
||||||
- mysql_borg_backup
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
---
|
|
||||||
# vars file for mysql_borg_backup
|
|
||||||
Reference in new issue
Block a user