prepend all vars with role name

This commit is contained in:
Luc Stroobant 2017-10-01 13:05:59 +02:00
parent 11b3efb8ba
commit 89085c5d17
7 changed files with 23 additions and 21 deletions

View File

@ -4,7 +4,7 @@ The role supports both self hosted and rsync.net as Borg server.
## Required variables ## 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: infra:
[backupservers] [backupservers]
@ -34,7 +34,7 @@ Allows to override backup servers on group or host level.
Define a borg\_passphrase for every host. Define a borg\_passphrase for every host.
host\_vars\client1: 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. *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.

View File

@ -1,24 +1,26 @@
--- ---
backup_required: True borgbackup_required: True
restore: False borgbackup_do_restore: False
borg_version: "1.0.11" borgbackup_version: "1.0.11"
borg_checksum: "sha256:fbdc0e0d6d05a0935551f2f408f370236a76b7a30d3bb90a31c3628fe3611359" borgbackup_checksum: "sha256:fbdc0e0d6d05a0935551f2f408f370236a76b7a30d3bb90a31c3628fe3611359"
borg_download_url: "https://github.com/borgbackup/borg/releases/download/{{ borg_version }}/borg-linux64" 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' - '[[ ! -f "/usr/sbin/automysqlbackup" ]] || /usr/sbin/automysqlbackup'
backup_include: borgbackup_include:
- "/etc" - "/etc"
- "/home" - "/home"
- "/root" - "/root"
- "/var/www" - "/var/www"
- "/var/log" - "/var/log"
retention: borgbackup_retention:
hourly: 12 hourly: 12
daily: 7 daily: 7
weekly: 4 weekly: 4
monthly: 6 monthly: 6
yearly: 1 yearly: 1
borgbackup_management_station: ''

View File

@ -11,7 +11,7 @@
lineinfile: lineinfile:
dest: "/root/.borg.passphrase" dest: "/root/.borg.passphrase"
state: "present" state: "present"
line: 'export BORG_PASSPHRASE="{{ borg_passphrase }}"' line: 'export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"'
create: "yes" create: "yes"
- name: client | template sshconfig for backup-hosts (no strict key checking) - name: client | template sshconfig for backup-hosts (no strict key checking)

View File

@ -2,11 +2,11 @@
- name: server | install borg backup - name: server | install borg backup
get_url: get_url:
dest: "/usr/local/bin/borg" dest: "/usr/local/bin/borg"
checksum: "{{ borg_checksum }}" checksum: "{{ borgbackup_checksum }}"
owner: "root" owner: "root"
group: "root" group: "root"
mode: "0755" mode: "0755"
url: "{{ borg_download_url }}" url: "{{ borgbackup_download_url }}"
delegate_to: "{{ item.fqdn }}" delegate_to: "{{ item.fqdn }}"
with_items: "{{ backupservers }}" with_items: "{{ backupservers }}"
when: item.type == 'normal' when: item.type == 'normal'

View File

@ -2,9 +2,9 @@
- name: install borg backup - name: install borg backup
get_url: get_url:
dest: "/usr/local/bin/borg" dest: "/usr/local/bin/borg"
checksum: "{{ borg_checksum }}" checksum: "{{ borgbackup_checksum }}"
owner: "root" owner: "root"
group: "root" group: "root"
mode: "0755" mode: "0755"
url: "{{ borg_download_url }}" url: "{{ borgbackup_download_url }}"
tags: borginstall tags: borginstall

View File

@ -2,7 +2,7 @@
- include: install.yml - include: install.yml
when: > when: >
backup_required == True or borgbackup_required == True or
inventory_hostname in groups.backupservers or inventory_hostname in groups.backupservers or
restore == True restore == True
@ -11,10 +11,10 @@
- include: borg-client.yml - include: borg-client.yml
when: > when: >
backup_required == True and borgbackup_required == True and
inventory_hostname not in groups.backupservers inventory_hostname not in groups.backupservers
- include: restore.yml - include: restore.yml
when: > when: >
restore == True and borgbackup_do_restore == True and
inventory_hostname not in groups.backupservers inventory_hostname not in groups.backupservers

View File

@ -58,7 +58,7 @@ if [ "$1" = "backup" ]
date=`date +%Y%m%d-%H%M` date=`date +%Y%m%d-%H%M`
# Running some commands pre-backup # Running some commands pre-backup
{% for precommand in backup_pre_commands %} {% for precommand in borgbackup_pre_commands %}
{{ precommand }} {{ precommand }}
{% endfor %} {% endfor %}
@ -66,13 +66,13 @@ if [ "$1" = "backup" ]
printf "Backing up to {{ b.fqdn }} :\n" printf "Backing up to {{ b.fqdn }} :\n"
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }} 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 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 # Use the `prune` subcommand to maintain 7 daily, 4 weekly
# and 6 monthly archives. # 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 %} {% endfor %}
fi fi