From 64dcfb2fbd370a130210d3d52e264b4959c9d501 Mon Sep 17 00:00:00 2001 From: phil Date: Fri, 10 Mar 2023 20:14:32 +0100 Subject: [PATCH] Add variables to configure automysqlbackup Translate Readme --- README.md | 30 ++++++++++++++++++------------ defaults/main.yml | 2 ++ tasks/backup.yml | 18 ++++++------------ templates/automysqlbackup | 24 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 templates/automysqlbackup diff --git a/README.md b/README.md index 550890a..d30cae2 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,31 @@ MariaDB ======= -Diese Rolle installiert MariaDB, inkl. - - Monit-Überwachung - - Munin-Überwachung - - lokale Backups mit automysqlbackup +This role installs MariaDB, including: + - Monitoring with Monit and Munin + - Backups with automysqlbackup -Eine Einrichtung des Datenbankservers erfolgt nicht. +No configuration of the database server will take place. -## Verfügbare Variablen +## Variables -Folgende Variablen können über die jeweilige `host_vars` im Dictionary `mariadb` gesetzt werden: +You can use the following variables to adopt the role to your needs. Place them in a dictionary called `mariadb`: -| Varible | Wert | Beschreibung | +| Varible | Value | Notes | |--|--|--| -| local_backupdir | string | Lokales Verzeichnis der sql-Backups | -| bind_address | string | Listen-Adresse des Mariadb-Servers, wird bisher nicht konfiguriert | +| `bind_address` | string | Address to bind the MariaDB server to | -Beispiel: +Ecample: ```YAML mariadb: - local_backupdir: /var/lib/backups/mariadb bind_address: "10.0.0.2" ``` + +There are additional variables to configure automysqlbackup: + +| Varibles | Defaults | Notes | +|--|--|--| +| `automysqlbackup_backupdir` | `/var/lib/automysqlbackup` | Directory to save backups | +| `automysqlbackup_dbhost` | `localhost` | Database host | +| `automysqlbackup_mailaddr` | `root` | Mail address to send reports to | +| `automysqlbackup_postbackup` | `/usr/local/bin/automysqlbackup_post_script` | Complete path to a post backup script | diff --git a/defaults/main.yml b/defaults/main.yml index 565c58c..cd1fc62 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -10,3 +10,5 @@ mysql_socket: /run/mysqld/mysqld.sock slowlog_query_log_file: /var/log/mysql/mariadb-slow.logA slowlog_query_time: 10 slowlog_log_slow_rate_limit: 1000 + +automysqlbackup_postbackup: /usr/local/bin/automysqlbackup_post_script diff --git a/tasks/backup.yml b/tasks/backup.yml index edb279f..c1c31cb 100644 --- a/tasks/backup.yml +++ b/tasks/backup.yml @@ -1,18 +1,12 @@ --- -- name: "Backup | Set automysqlbackup postbackup script" - ansible.builtin.lineinfile: - path: /etc/default/automysqlbackup - regexp: '^#POSTBACKUP=' - line: POSTBACKUP="/usr/local/bin/automysqlbackup_post_script" - -- name: "Backup | Dest automysqlbackup backupdir" - ansible.builtin.lineinfile: - path: /etc/default/automysqlbackup - regexp: '^BACKUPDIR=' - line: 'BACKUPDIR="{{ mariadb.local_backupdir | default("/var/lib/automysqlbackup") }}"' +- name: "Backup | Copy automysqlbackup configuration" + ansible.builtin.template: + src: automysqlbackup + dest: /etc/default/automysqlbackup + mode: 0644 - name: "Backup | Copy automysqlbackup postbackup script" ansible.builtin.copy: src: automysqlbackup_post_script - dest: /usr/local/bin/ + dest: "{{ automysqlbackup_postbackup }}" mode: 0755 diff --git a/templates/automysqlbackup b/templates/automysqlbackup new file mode 100644 index 0000000..bf0094f --- /dev/null +++ b/templates/automysqlbackup @@ -0,0 +1,24 @@ +# Managed by ansible + +DBHOST={{ automysqlbackiup_dbhost | default("localhost") }} +DBNAMES=`mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW DATABASES" | awk '{print $1}' | grep -v ^Database$ | grep -v ^mysql$ | grep -v ^performance_schema$ | grep -v ^information_schema$ | tr \\\r\\\n ,\ ` +BACKUPDIR="{{ automysqlbackup_backupdir | default("/var/lib/automysqlbackup") }}" +MAILCONTENT="quiet" +MAXATTSIZE="4000" +MAILADDR="{{ automysqlbackup_mailaddr | default(root) }}" +MDBNAMES="mysql $DBNAMES" +DBEXCLUDE="" +CREATE_DATABASE=yes +SEPDIR=yes +DOWEEKLY=6 +DOMONTHLY=01 +COMP=gzip +COMPDIRECT=no +COMMCOMP=no +LATEST=no +MAX_ALLOWED_PACKET= +SOCKET= +PREBACKUP= +POSTBACKUP="{{ automysqlbackup_postbackup }}" +ROUTINES=yes +OPTIONS=""