From 89085c5d17ca9e77b94ebe769c255dea376f1f0d Mon Sep 17 00:00:00 2001 From: Luc Stroobant Date: Sun, 1 Oct 2017 13:05:59 +0200 Subject: [PATCH] prepend all vars with role name --- README.md | 4 ++-- defaults/main.yml | 18 ++++++++++-------- tasks/borg-client.yml | 2 +- tasks/borg-server.yml | 4 ++-- tasks/install.yml | 4 ++-- tasks/main.yml | 6 +++--- templates/borg-backup.sh.j2 | 6 +++--- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index f1f8bcf..9bdbe7b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ The role supports both self hosted and rsync.net as Borg server. ## Required variables -Define a group backupservers in your inventory with one or multiple hosts. The default location where the backups will be saved is /var/backup/repos/. +Define a group backupservers in your inventory with one or multiple hosts. ``` infra: [backupservers] @@ -34,7 +34,7 @@ Allows to override backup servers on group or host level. Define a borg\_passphrase for every host. host\_vars\client1: ``` -borg_passphrase: Ahl9EiNohr5koosh1Wohs3Shoo3ooZ6p +borgbackup_passphrase: Ahl9EiNohr5koosh1Wohs3Shoo3ooZ6p ``` *Make sure to check the configured defaults for this role, which contains the list of default locations being backed up in backup_include.* Override this in your inventory where required. diff --git a/defaults/main.yml b/defaults/main.yml index 11b89bd..efb8154 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,24 +1,26 @@ --- -backup_required: True -restore: False +borgbackup_required: True +borgbackup_do_restore: False -borg_version: "1.0.11" -borg_checksum: "sha256:fbdc0e0d6d05a0935551f2f408f370236a76b7a30d3bb90a31c3628fe3611359" -borg_download_url: "https://github.com/borgbackup/borg/releases/download/{{ borg_version }}/borg-linux64" +borgbackup_version: "1.0.11" +borgbackup_checksum: "sha256:fbdc0e0d6d05a0935551f2f408f370236a76b7a30d3bb90a31c3628fe3611359" +borgbackup_download_url: "https://github.com/borgbackup/borg/releases/download/{{ borgbackup_version }}/borg-linux64" -backup_pre_commands: +borgbackup_pre_commands: - '[[ ! -f "/usr/sbin/automysqlbackup" ]] || /usr/sbin/automysqlbackup' -backup_include: +borgbackup_include: - "/etc" - "/home" - "/root" - "/var/www" - "/var/log" -retention: +borgbackup_retention: hourly: 12 daily: 7 weekly: 4 monthly: 6 yearly: 1 + +borgbackup_management_station: '' diff --git a/tasks/borg-client.yml b/tasks/borg-client.yml index c5642f8..654a246 100644 --- a/tasks/borg-client.yml +++ b/tasks/borg-client.yml @@ -11,7 +11,7 @@ lineinfile: dest: "/root/.borg.passphrase" state: "present" - line: 'export BORG_PASSPHRASE="{{ borg_passphrase }}"' + line: 'export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"' create: "yes" - name: client | template sshconfig for backup-hosts (no strict key checking) diff --git a/tasks/borg-server.yml b/tasks/borg-server.yml index 0646970..8127678 100644 --- a/tasks/borg-server.yml +++ b/tasks/borg-server.yml @@ -2,11 +2,11 @@ - name: server | install borg backup get_url: dest: "/usr/local/bin/borg" - checksum: "{{ borg_checksum }}" + checksum: "{{ borgbackup_checksum }}" owner: "root" group: "root" mode: "0755" - url: "{{ borg_download_url }}" + url: "{{ borgbackup_download_url }}" delegate_to: "{{ item.fqdn }}" with_items: "{{ backupservers }}" when: item.type == 'normal' diff --git a/tasks/install.yml b/tasks/install.yml index f534fcd..87ff287 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -2,9 +2,9 @@ - name: install borg backup get_url: dest: "/usr/local/bin/borg" - checksum: "{{ borg_checksum }}" + checksum: "{{ borgbackup_checksum }}" owner: "root" group: "root" mode: "0755" - url: "{{ borg_download_url }}" + url: "{{ borgbackup_download_url }}" tags: borginstall diff --git a/tasks/main.yml b/tasks/main.yml index f73803a..605f061 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,7 +2,7 @@ - include: install.yml when: > - backup_required == True or + borgbackup_required == True or inventory_hostname in groups.backupservers or restore == True @@ -11,10 +11,10 @@ - include: borg-client.yml when: > - backup_required == True and + borgbackup_required == True and inventory_hostname not in groups.backupservers - include: restore.yml when: > - restore == True and + borgbackup_do_restore == True and inventory_hostname not in groups.backupservers diff --git a/templates/borg-backup.sh.j2 b/templates/borg-backup.sh.j2 index f88c336..5290243 100644 --- a/templates/borg-backup.sh.j2 +++ b/templates/borg-backup.sh.j2 @@ -58,7 +58,7 @@ if [ "$1" = "backup" ] date=`date +%Y%m%d-%H%M` # Running some commands pre-backup -{% for precommand in backup_pre_commands %} +{% for precommand in borgbackup_pre_commands %} {{ precommand }} {% endfor %} @@ -66,13 +66,13 @@ if [ "$1" = "backup" ] printf "Backing up to {{ b.fqdn }} :\n" REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }} - /usr/local/bin/borg create --compression zlib,6 --stats $REPOSITORY::$date {{ b.options }} {% for dir in backup_include %}{{ dir }} {% endfor %}{% if automysql.stat.isdir is defined and automysql.stat.isdir == True %}/var/lib/automysqlbackup{% endif %} + /usr/local/bin/borg create --compression zlib,6 --stats $REPOSITORY::$date {{ b.options }} {% for dir in borgbackup_include %}{{ dir }} {% endfor %}{% if automysql.stat.isdir is defined and automysql.stat.isdir == True %}/var/lib/automysqlbackup{% endif %} if [ "$?" -eq "0" ]; then printf "Backup succeeded on $date\n" >> /var/log/borg-backup.log; fi # Use the `prune` subcommand to maintain 7 daily, 4 weekly # and 6 monthly archives. - /usr/local/bin/borg prune -v $REPOSITORY {{ b.options }} -H {{ retention.hourly }} -d {{ retention.daily }} -w {{ retention.weekly }} -m {{ retention.monthly }} -y {{ retention.yearly }} + /usr/local/bin/borg prune -v $REPOSITORY {{ b.options }} -H {{ borgbackup_retention.hourly }} -d {{ borgbackup_retention.daily }} -w {{ borgbackup_retention.weekly }} -m {{ borgbackup_retention.monthly }} -y {{ borgbackup_retention.yearly }} {% endfor %} fi