ansible-infra/roles/common/tasks/backup_borg.yml

62 lines
1.8 KiB
YAML

- name: Install Borg packages
package:
name: "{{ borg_package }}"
state: present
loop: "{{ borg_packages }}"
loop_control:
loop_var: borg_package
- name: Initialize Borg repository
command: borg init --make-parent-dirs --umask "{{ borgmatic_config.storage.umask }}" -e "{{ borg_encryption_mode }}" "{{ borg_repository }}"
environment:
BORG_PASSPHRASE: "{{ borgmatic_config.storage.encryption_passphrase }}"
changed_when: "'A repository already exists' not in _borg_backup_init.stderr"
failed_when: _borg_backup_init.rc >= 2 and 'A repository already exists' not in _borg_backup_init.stderr
register: _borg_backup_init
- name: Create Borgmatic config directory
file:
path: "{{ borgmatic_config_dir }}"
state: directory
owner: root
group: root
mode: "755"
- name: Copy Borgmatic config files
copy:
content: "{{ borgmatic_config | to_nice_yaml(indent=2) }}"
dest: "{{ borgmatic_config_dir }}/config.yaml"
owner: root
group: root
mode: "600"
- name: Add cron job for regular Borgmatic create and prune
cron:
user: root
name: borgmatic-create
cron_file: borgmatic
hour: "{{ borgmatic_cron_hour }}"
minute: "{{ borgmatic_cron_minute }}"
state: present
job: borgmatic --create --prune
- name: Add cron job for unfrequent Borgmatic check
cron:
user: root
name: borgmatic-check
cron_file: borgmatic
weekday: "{{ borgmatic_check_cron_weekday }}"
hour: "{{ borgmatic_check_cron_hour }}"
minute: "{{ borgmatic_check_cron_minute }}"
state: present
job: borgmatic --check
- name: Set PATH for Borgmatic cron job.
cron:
user: root
name: PATH
cron_file: borgmatic
env: yes
state: present
value: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin