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
@@ -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