2019-10-06 20:55:56 +00:00
|
|
|
---
|
|
|
|
# Server/Borgbackup: Install and Setup Borgbackup Backup Crobjob
|
|
|
|
# Variables (must be set!):
|
2019-11-12 20:06:04 +00:00
|
|
|
# - borgbackup_passphrase
|
|
|
|
# - borgbackup_repo
|
|
|
|
# - borgbackup_hostname
|
2019-10-06 20:55:56 +00:00
|
|
|
|
|
|
|
- name: borgbackup - Install
|
|
|
|
include_tasks: "{{ item }}"
|
|
|
|
with_first_found:
|
|
|
|
- "borgbackup-{{ ansible_distribution }}.{{ ansible_distribution_release }}.yml"
|
|
|
|
- "borgbackup-{{ ansible_distribution }}.yml"
|
|
|
|
- "borgbackup-{{ ansible_os_family }}.yml"
|
|
|
|
|
|
|
|
|
|
|
|
# copy backup script and enable cronjob
|
|
|
|
- name: borgbackup - Copy Borgbackup script
|
|
|
|
become: yes
|
|
|
|
template:
|
|
|
|
src: "{{ role_path }}/templates/borgbackup.sh"
|
|
|
|
dest: /usr/local/bin/borgbackup.sh
|
|
|
|
owner: "{{ ansible_user_id }}"
|
|
|
|
group: "{{ ansible_user_id }}"
|
|
|
|
mode: 0775
|
|
|
|
when:
|
2019-11-12 20:06:04 +00:00
|
|
|
- borgbackup_passphrase is defined
|
|
|
|
- borgbackup_repo is defined
|
|
|
|
- borgbackup_hostname is defined
|
2019-10-06 20:55:56 +00:00
|
|
|
- name: borgbackup - Run Borgbackup script at 1:00 daily
|
|
|
|
become: yes
|
|
|
|
cron:
|
|
|
|
name: "Create Backup"
|
|
|
|
minute: "0"
|
|
|
|
hour: "1"
|
|
|
|
job: "/usr/local/bin/borgbackup.sh"
|
|
|
|
when:
|
2019-11-12 20:06:04 +00:00
|
|
|
- borgbackup_passphrase is defined
|
|
|
|
- borgbackup_repo is defined
|
|
|
|
- borgbackup_hostname is defined
|
2019-10-06 20:55:56 +00:00
|
|
|
|
|
|
|
# safeguard, if the host variables were removed
|
2019-11-12 20:06:04 +00:00
|
|
|
- name: borgbackup - Uninstall
|
|
|
|
block:
|
|
|
|
- name: borgbackup - Remove Borgbackup script if no borgbackup config
|
|
|
|
become: yes
|
|
|
|
file:
|
|
|
|
path: /usr/local/bin/borgbackup.sh
|
|
|
|
state: absent
|
|
|
|
- name: borgbackup - Remove Cronjob if no borgbackup config
|
|
|
|
become: yes
|
|
|
|
cron:
|
|
|
|
name: "Create Backup"
|
|
|
|
minute: "0"
|
|
|
|
hour: "1"
|
|
|
|
job: "/usr/local/bin/borgbackup.sh"
|
|
|
|
state: absent
|
|
|
|
when: (borgbackup_passphrase is not defined) or (borgbackup_repo is not defined) or (borgbackup_hostname is not defined)
|