From a80f0acb8884666fba7a91d9ed8ddf89a6931e63 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 31 Oct 2020 05:23:51 +0100 Subject: [PATCH] Documentation & example --- .gitlab-ci.yml | 8 ++++++ README.md | 12 ++++++-- docs/group_vars/dbms/dirvish_client.yml | 12 ++++++++ docs/group_vars/servers/dirvish_client.yml | 5 ++++ docs/group_vars/servers/dirvish_server.yml | 14 ++++++++++ docs/inventory.ini | 32 ++++++++++++++++++++++ docs/playbook.yml | 10 +++++++ docs/requirements.yml | 5 ++++ docs/templates/mysql-snapshot.sh.j2 | 21 ++++++++++++++ roles/dirvish_server/tasks/config.yml | 6 ++++ 10 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 docs/group_vars/dbms/dirvish_client.yml create mode 100644 docs/group_vars/servers/dirvish_client.yml create mode 100644 docs/group_vars/servers/dirvish_server.yml create mode 100644 docs/inventory.ini create mode 100644 docs/playbook.yml create mode 100644 docs/requirements.yml create mode 100644 docs/templates/mysql-snapshot.sh.j2 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..7f69e48 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,8 @@ +--- + +image: yokogawa/ansible-lint@sha256:410af7d376066c7f352943e016de78df0b5580b09e63e38440909c30c5fd67b8 + +lint: + script: + - ansible-galaxy install -r requirements.yml + - ansible-lint --force-color . diff --git a/README.md b/README.md index e53113a..bb75de9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # Ansible Collection - s3lph.dirvish -Documentation for the collection. +WIP -WIP, TBD \ No newline at end of file +## Usage + +1. Use the contents of `docs/` as a template for your playbook directory +1. Run `ansible-galaxy install -r requirements.yml` +1. Add your backup servers as well as backed-up clients to the inventory + - Don't add the clients all at once; instead run the playbook after adding each client and initialize the client +1. Add the snapshot scripts required for your services to the `templates/` directory +1. Configure the variables in `group_vars/` and `host_vars/` +1. TBD ... \ No newline at end of file diff --git a/docs/group_vars/dbms/dirvish_client.yml b/docs/group_vars/dbms/dirvish_client.yml new file mode 100644 index 0000000..a91b04a --- /dev/null +++ b/docs/group_vars/dbms/dirvish_client.yml @@ -0,0 +1,12 @@ +--- + +# List of snapshot scripts to install and include in the snapshot +# cronjob Snapshot scripts must be declared as templates, e.g. in the +# templates directory. +dirvish_client_snapshot_scripts: + - mysql-snapshot.sh + +# Exclude the MariaDB data directory, as that's already covered by the snapshot +dirvish_server_client_exclude: + - 'var/lib/mysql/' + diff --git a/docs/group_vars/servers/dirvish_client.yml b/docs/group_vars/servers/dirvish_client.yml new file mode 100644 index 0000000..4e7cc2a --- /dev/null +++ b/docs/group_vars/servers/dirvish_client.yml @@ -0,0 +1,5 @@ +--- + +# Additionally exclude dirvish vaults when taking backups of other servers +dirvish_server_client_exclude: + - 'data/' diff --git a/docs/group_vars/servers/dirvish_server.yml b/docs/group_vars/servers/dirvish_server.yml new file mode 100644 index 0000000..603c713 --- /dev/null +++ b/docs/group_vars/servers/dirvish_server.yml @@ -0,0 +1,14 @@ +--- + +# Ensure that these mount points exist before writing any config changes +dirvish_server_bank_mounts: + - '/data' + +# Exclude the following files/directories on all clients +dirvish_server_exclude: + - 'lost+found/' + - 'dev/' + - 'proc/' + - 'run/' + - 'sys/' + - 'tmp/' diff --git a/docs/inventory.ini b/docs/inventory.ini new file mode 100644 index 0000000..a94a43f --- /dev/null +++ b/docs/inventory.ini @@ -0,0 +1,32 @@ +[all:children] +clients + +# Clients to be backed up +[clients:children] +lb +web +db +# Backup servers should have backups as well. Just make sure to +# exclude the dirvish vaults... +servers + +[lb] +lb01.example.com +lb02.example.com + +[web] +web01.example.com +web02.example.com +web03.example.com + +[dbms] +dbms01.example.com +dbms02.example.com +dbms03.example.com + +# Backup servers +[servers] +vault01.example.com +vault02.example.com +vault03.example.com + diff --git a/docs/playbook.yml b/docs/playbook.yml new file mode 100644 index 0000000..005bc88 --- /dev/null +++ b/docs/playbook.yml @@ -0,0 +1,10 @@ +--- + +- hosts: clients + strategy: free + roles: + - s3lph.dirvish.dirvish_client + +- hosts: servers + roles: + - s3lph.dirvish.dirvish_server diff --git a/docs/requirements.yml b/docs/requirements.yml new file mode 100644 index 0000000..305dab6 --- /dev/null +++ b/docs/requirements.yml @@ -0,0 +1,5 @@ +--- +collections: + - name: https://gitlab.com/s3lph/ansible-collection-dirvish + type: git + version: master diff --git a/docs/templates/mysql-snapshot.sh.j2 b/docs/templates/mysql-snapshot.sh.j2 new file mode 100644 index 0000000..8b6f10e --- /dev/null +++ b/docs/templates/mysql-snapshot.sh.j2 @@ -0,0 +1,21 @@ +#!/bin/bash +{{ ansible_managed | comment }} + +# +# THIS IS AN EXAMPLE +# If you want to use this, adapt to your needs and remove the "exit 1" +# +exit 1 + +set -e +BACKUPDIR={{ dirvish_client_mysql_backupdir | quote }} +MYSQL_BACKUP_CONFIG=/root/.my.cnf + +DATABASES=$(mysql --defaults-extra-file=${MYSQL_BACKUP_CONFIG} --skip-column-names --batch --execute 'SHOW DATABASES') + +for DB in $DATABASES; do + if [[ "$DB" == "mysql" || "$DB" == "information_schema" || "$DB" == "performance_schema" ]]; then + continue + fi + mysqldump --defaults-extra-file=${MYSQL_BACKUP_CONFIG} --databases "${DB}" | xz > "${BACKUPDIR}/${DB}.xz" +done diff --git a/roles/dirvish_server/tasks/config.yml b/roles/dirvish_server/tasks/config.yml index 334f5cb..c6b026a 100644 --- a/roles/dirvish_server/tasks/config.yml +++ b/roles/dirvish_server/tasks/config.yml @@ -34,12 +34,18 @@ file: path: "{{ hostvars[item].dirvish_server_bank }}/{{ item }}/dirvish" state: directory + owner: root + group: root + mode: '0755' loop: "{{ groups[dirvish_server_clients_group] }}" - name: render all client configs template: src: client_default.conf.j2 dest: "{{ hostvars[item].dirvish_server_bank }}/{{ item }}/dirvish/default.conf" + owner: root + group: root + mode: '0644' loop: "{{ groups[dirvish_server_clients_group] }}" - name: render dirvish crontab