polishing

This commit is contained in:
Frank Dornheim 2023-03-18 12:43:34 +01:00
parent 8fa8d7f4d7
commit 368d8ec893
9 changed files with 66 additions and 51 deletions

View File

@ -183,7 +183,6 @@ Main features:
```
## Installation
Download from Ansible Galaxy
@ -197,6 +196,20 @@ $ git clone https://github.com/borgbase/ansible-role-borgbackup.git roles/ansibl
```
## Tags:
This Role supports the following ansible tags:
- `install_backup`: Tag for only run that part.
- `backup_install_helper` Tag to additionally install the backup helper skripts. Currently only docker.
### Example
To install the helper scrit.
```
$ ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook test.example.com -t backup_install_helper
```
## Role Variables
### Required Arguments

View File

@ -18,19 +18,19 @@ borg_retention_policy:
keep_monthly: 6
borg_version: false
borgmatic_timer_cron_name: "borgmatic"
borgmatic_timer: systemd
borgmatic_timer: cron
borgmatic_timer_hour: "{{ range(0, 5) | random(seed=inventory_hostname) }}"
borgmatic_timer_minute: "{{ range(0, 59) | random(seed=inventory_hostname) }}"
borg_install_method: pip
borg_install_method: "pip"
borgmatic_config_name: config.yaml
borgmatic_hooks:
on_error:
- echo "`date` - Error while creating a backup."
- echo "`date` - Error while creating a backup."
before_backup:
- echo "`date` - Starting backup."
- echo "`date` - Starting backup."
after_backup:
- echo "`date` - Finished backup."
- echo "`date` - Finished backup."
# See: https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/#check-frequency
borgmatic_checks:
- name: repository

View File

@ -1,27 +1,34 @@
---
- name: Create borgmatic command in /usr/local/bin
ansible.builtin.copy:
content: |
#!/bin/bash
. "{{ borg_venv_path }}"/bin/activate
borgmatic "$@"
dest: /usr/local/bin/borgmatic
mode: "0755"
owner: "{{ borgbackup_user }}"
group: "{{ borgbackup_group }}"
- name: Create links to the Borgmatic and Borg binarys
tags:
- install_backup
block:
- name: Create borgmatic command in /usr/local/bin
ansible.builtin.copy:
content: |
#!/bin/bash
. "{{ borg_venv_path }}"/bin/activate
borgmatic "$@"
dest: /usr/local/bin/borgmatic
mode: "0755"
owner: "{{ borgbackup_user }}"
group: "{{ borgbackup_group }}"
- name: Create borg command in /usr/local/bin
ansible.builtin.copy:
content: |
#!/bin/bash
. "{{ borg_venv_path }}"/bin/activate
borg "$@"
dest: /usr/local/bin/borg
mode: "0755"
owner: "{{ borgbackup_user }}"
group: "{{ borgbackup_group }}"
- name: Create borg command in /usr/local/bin
ansible.builtin.copy:
content: |
#!/bin/bash
. "{{ borg_venv_path }}"/bin/activate
borg "$@"
dest: /usr/local/bin/borg
mode: "0755"
owner: "{{ borgbackup_user }}"
group: "{{ borgbackup_group }}"
- name: Install helper scripts
tags:
- never
- backup_install_helper
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"

View File

@ -1,20 +1,10 @@
---
- name: Create borgbackup timer
when:
- borgmatic_timer is defined and borgmatic_timer == "systemd"
- borgmatic_timer is defined and borgmatic_timer | length > 0
tags:
- install_backup
block:
- name: Timer Systemd
- name: Start timer install script
ansible.builtin.include_tasks:
file: noauto_create_timer.yml
- name: Create borgbackup cron
when:
- borgmatic_timer is defined or borgmatic_timer == "cron"
tags:
- install_backup
block:
- name: Install cron backup job
ansible.builtin.include_tasks:
file: noauto_create_cronjobs.yml
file: noauto_create_timer_{{ borgmatic_timer }}.yml

View File

@ -1,8 +1,8 @@
---
- name: Add and run all plays
include_tasks: "{{ element }}"
include_tasks: "{{ bak_element }}"
with_items: "{{ lookup('ansible.builtin.fileglob', '*.yml').split(',') | reject('search', 'main.yml') | reject('search', 'noauto_*') | sort }}"
loop_control:
loop_var: element
loop_var: bak_element
tags: always
...

View File

@ -1,7 +1,8 @@
---
- name: Create borgbackup timer
when:
- borgmatic_timer is defined and borgmatic_timer == "systemd"
- borgmatic_timer is defined
- borgmatic_timer == "systemd"
tags:
- install_backup
block:
@ -14,18 +15,22 @@
backup: true
mode: "{{ item.mode }}"
with_items:
- { src: "backup.timer.j2", dest: "/usr/lib/systemd/system/backup.timer", mode: "0644" }
- { src: "backup.service.j2", dest: "/usr/lib/systemd/system/backup.service", mode: "0644" }
- { src: "borgmatic.timer.j2", dest: "/usr/lib/systemd/system/borgmatic.timer", mode: "0644" }
- { src: "borgmatic.service.j2", dest: "/usr/lib/systemd/system/borgmatic.service", mode: "0644" }
- name: Populate service facts
ansible.builtin.service_facts:
- name: Print service facts
ansible.builtin.debug:
var: ansible_facts.services
# If the role is running and the repo is not yet initialized, an error will occur.
# Therefore the service is stopped by default and must be started manually.
- name: Stop fresh installed backup.timer and backup.service
when: ('backup.service' not in services)
- name: Stop fresh installed borgmatic.timer and borgmatic.service
when: ('borgmatic.service' not in services)
block:
- name: Stop borgmatic services
- name: Set borgmatic services to stopped - fresh installed
ansible.builtin.systemd:
name: "{{ item }}"
state: stopped
@ -34,20 +39,20 @@
daemon_reload: true
when: "item in services"
with_items:
- backup.service
- borgmatic.service
# bug: Need own section without masked else the timer are skipped
- name: Stop borgmatic timers
- name: Set borgmatic timers to stopped - fresh installed
ansible.builtin.systemd:
name: "{{ item }}"
state: stopped
enabled: false
daemon_reload: true
with_items:
- "backup.timer"
- "borgmatic.timer"
- name: Show hints
when: "'backup_init_repo' not in ansible_run_tags"
ansible.builtin.debug:
msg: "Attention: Since the repo was not initialized automatically, the systemd service (backup.service) and the timer (backup.timer) are not activated."
msg: "Attention: Since the repo was not initialized automatically, the systemd service (borgmatic.service) and the timer (bborgmatic.timer) are not activated."
...