58 lines
1.5 KiB
YAML
58 lines
1.5 KiB
YAML
---
|
|
# Server/Borgbackup: Install and Setup Borgbackup Backup Crobjob
|
|
# Variables (must be set!):
|
|
# - borgbackup_host
|
|
# - borgbackup_sub
|
|
|
|
- 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:
|
|
- borgbackup_host is defined
|
|
- borgbackup_sub is defined
|
|
- 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:
|
|
- borgbackup_host is defined
|
|
- borgbackup_sub is defined
|
|
|
|
# safeguard, if the host variables were removed
|
|
- name: borgbackup - Remove Borgbackup script if no borgbackup config
|
|
become: yes
|
|
file:
|
|
path: /usr/local/bin/borgbackup.sh
|
|
state: absent
|
|
when:
|
|
- borgbackup_host is not defined
|
|
- borgbackup_sub is not defined
|
|
- 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_host is not defined
|
|
- borgbackup_sub is not defined
|