From ca080e8611234bb36518372209dcbe7d87f076b4 Mon Sep 17 00:00:00 2001 From: Nemo Date: Thu, 27 Aug 2020 18:01:08 +0200 Subject: [PATCH] Update backup_client role for OpenBSD --- roles/backup_client/defaults/main.yml | 9 ++++++++- roles/backup_client/tasks/package.yml | 2 +- roles/backup_client/tasks/script.yml | 2 +- roles/backup_client/templates/backup.sh.j2 | 10 +++++----- roles/backup_client/vars/Debian.yml | 4 ++++ roles/backup_client/vars/Gentoo.yml | 4 ++++ roles/backup_client/vars/OpenBSD.yml | 8 ++++++++ roles/backup_client/vars/RedHat.yml | 4 ++++ 8 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 roles/backup_client/vars/OpenBSD.yml diff --git a/roles/backup_client/defaults/main.yml b/roles/backup_client/defaults/main.yml index 758effb..773603b 100644 --- a/roles/backup_client/defaults/main.yml +++ b/roles/backup_client/defaults/main.yml @@ -14,8 +14,9 @@ backup_client_folders_to_backup: "" # Folder to deploy backup client scripts backup_client_scripts_folder: "/usr/local/sbin" -# Backup client user and home directory +# Backup client user, group and home directory backup_client_user: "root" +client_backup_group: "root" backup_client_user_home: "/root" # Crontask backup client scheduling @@ -31,3 +32,9 @@ backup_client_mail_target: "root" # Compression parameters backup_client_compression_param: "lzma,9" + +# Shell to use in script +backup_client_shell: /bin/bash + +# Bin Borgbackup +backup_client_borgbackup_bin: /usr/bin/borg diff --git a/roles/backup_client/tasks/package.yml b/roles/backup_client/tasks/package.yml index 1cf5aa4..6f0a7a9 100644 --- a/roles/backup_client/tasks/package.yml +++ b/roles/backup_client/tasks/package.yml @@ -3,7 +3,7 @@ package: name: "{{ cron_package }}" state: present - when: backup_client_folders_to_backup != "" + when: backup_client_folders_to_backup != "" and ansible_os_family != 'OpenBSD' notify: restart cron - name: BorgBackup installed diff --git a/roles/backup_client/tasks/script.yml b/roles/backup_client/tasks/script.yml index 150d259..a41d83d 100644 --- a/roles/backup_client/tasks/script.yml +++ b/roles/backup_client/tasks/script.yml @@ -4,7 +4,7 @@ src: backup.sh.j2 dest: "{{ backup_client_scripts_folder }}/backup.sh" owner: "{{ backup_client_user }}" - group: "{{ backup_client_user }}" + group: "{{ backup_client_group }}" mode: '0740' when: backup_client_folders_to_backup != "" diff --git a/roles/backup_client/templates/backup.sh.j2 b/roles/backup_client/templates/backup.sh.j2 index f94f5aa..3089eaa 100644 --- a/roles/backup_client/templates/backup.sh.j2 +++ b/roles/backup_client/templates/backup.sh.j2 @@ -1,4 +1,4 @@ -#!/bin/bash +#!{{ backup_client_shell }} {% for backup_serv in groups['backup_server'] %} # Check if {{ backup_serv }} is a known host @@ -7,15 +7,15 @@ if [ ! $? -eq 0 ]; then ssh-keygen -F {{ backup_serv }} || ssh-keyscan {{ backup_serv }} >>~/.ssh/known_hosts fi -borg list backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) &>/dev/null +{{ backup_client_borgbackup_bin }} list backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) &>/dev/null if [ $? -ne 0 ] then ssh backup-$(hostname -s)@{{ backup_serv }} mkdir -p {{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) -m 0700 export BORG_PASSPHRASE="" - borg init --encryption=repokey backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) + {{ backup_client_borgbackup_bin }} init --encryption=repokey backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) fi -borg prune -v backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) --keep-daily=7 --keep-weekly=4 --keep-monthly=1 -borg create --info --stats --compression {{ backup_client_compression_param }} backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s)::$(date +%F) $(find {{ backup_client_folders_to_backup }} -maxdepth 1 -type d | grep -Ev '^/$|^/tmp|^/lost\+found|^/run|^/proc|^/dev|^/sys' | tr '\n' ' ') +{{ backup_client_borgbackup_bin }} prune -v backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) --keep-daily=7 --keep-weekly=4 --keep-monthly=1 +{{ backup_client_borgbackup_bin }} create --info --stats --compression {{ backup_client_compression_param }} backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s)::$(date +%F) $(find {{ backup_client_folders_to_backup }} -maxdepth 1 -type d | grep -Ev '^/$|^/tmp|^/lost\+found|^/run|^/proc|^/dev|^/sys' | tr '\n' ' ') {% endfor %} diff --git a/roles/backup_client/vars/Debian.yml b/roles/backup_client/vars/Debian.yml index 0a7e0cf..695dfb6 100644 --- a/roles/backup_client/vars/Debian.yml +++ b/roles/backup_client/vars/Debian.yml @@ -2,3 +2,7 @@ cron_service_name: cron cron_package: cron aliases_config_file: /etc/aliases +backup_client_user: root +backup_client_group: root +backup_client_shell: /bin/bash +backup_client_borgbackup_bin: /usr/bin/borg diff --git a/roles/backup_client/vars/Gentoo.yml b/roles/backup_client/vars/Gentoo.yml index dffe71e..ae81d97 100644 --- a/roles/backup_client/vars/Gentoo.yml +++ b/roles/backup_client/vars/Gentoo.yml @@ -2,3 +2,7 @@ cron_service_name: cronie cron_package: cronie aliases_config_file: /etc/mail/aliases +backup_client_user: root +backup_client_group: root +backup_client_shell: /bin/bash +backup_client_borgbackup_bin: /usr/bin/borg diff --git a/roles/backup_client/vars/OpenBSD.yml b/roles/backup_client/vars/OpenBSD.yml new file mode 100644 index 0000000..542859c --- /dev/null +++ b/roles/backup_client/vars/OpenBSD.yml @@ -0,0 +1,8 @@ +--- +cron_service_name: cron +cron_package: cron +aliases_config_file: /etc/mail/aliases +backup_client_user: root +backup_client_group: wheel +backup_client_shell: /bin/ksh +backup_client_borgbackup_bin: /usr/local/bin/borg diff --git a/roles/backup_client/vars/RedHat.yml b/roles/backup_client/vars/RedHat.yml index 0c6e1bc..7b3b9ce 100644 --- a/roles/backup_client/vars/RedHat.yml +++ b/roles/backup_client/vars/RedHat.yml @@ -2,3 +2,7 @@ cron_service_name: crond cron_package: cronie aliases_config_file: /etc/aliases +backup_client_user: root +backup_client_group: root +backup_client_shell: /bin/bash +backup_client_borgbackup_bin: /usr/bin/borg