mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2025-04-13 01:15:56 +02:00
Fix cron job, add assert to prevent duplicate timers
This commit is contained in:
parent
f9fc12be61
commit
761d628ca5
@ -26,7 +26,7 @@ Installs and configures the Borgmatic client and also initializes the repo on th
|
||||
borg_user: "srv_backup"
|
||||
borg_group: "srv_backup"
|
||||
borg_ssh_key_file_path: "{{ backup_user_info.home }}/.ssh/backup"
|
||||
borg_ssh_command: "ssh -i {{ borg_ssh_key_file_path }} -o StrictHostKeyChecking=no"
|
||||
borg_ssh_command: "ssh -i {{ borg_ssh_key_file_path }} -o StrictHostKeyChecking=accept-new"
|
||||
borgmatic_timer: systemd
|
||||
borg_source_directories:
|
||||
- /srv/www
|
||||
|
@ -7,8 +7,9 @@ Set up encrypted, compressed and deduplicated backups using [BorgBackup](https:/
|
||||
Works great with [BorgBase.com](https://www.borgbase.com) - Simple and Secure Hosting for your Borg Repositories. To manage BorgBase repos via Ansible, also see Andy Hawkins' [BorgBase Collection](https://galaxy.ansible.com/adhawkins/borgbase).
|
||||
|
||||
Main features:
|
||||
- Set up Borg and Borgmatic
|
||||
- Schedule regular backups using Cron or Systemd timer.
|
||||
- Install Borg and Borgmatic from PyPi or distro package
|
||||
- Set up Borgmatic config
|
||||
- Schedule regular backups using Cron or Systemd timer
|
||||
|
||||
|
||||
## Example Playbook with root as backup user and Cron timer
|
||||
@ -40,7 +41,7 @@ Main features:
|
||||
```
|
||||
|
||||
## Example Playbook with service user and Systemd timer
|
||||
`` Attention: `` The following implementation leads to problems.
|
||||
**Attention**: The following implementation leads to problems.
|
||||
If you already use this role and use the user: "root" or the SSH key id_ed25519!
|
||||
|
||||
```
|
||||
@ -51,7 +52,7 @@ If you already use this role and use the user: "root" or the SSH key id_ed25519!
|
||||
borg_repository: ssh://m5vz9gp4@m5vz9gp4.repo.borgbase.com/./repo
|
||||
borgmatic_timer: systemd
|
||||
borg_ssh_key_file_path: "{{ backup_user_info.home }}/.ssh/backup"
|
||||
borg_ssh_command: "ssh -i {{ borg_ssh_key_file_path }} -o StrictHostKeyChecking=no"
|
||||
borg_ssh_command: "ssh -i {{ borg_ssh_key_file_path }} -o StrictHostKeyChecking=accept-new"
|
||||
borg_user: "srv_backup"
|
||||
borg_group: "srv_backup"
|
||||
borg_source_directories:
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
- name: Add Cron job for borgmatic
|
||||
block:
|
||||
- name: Add cron job for create, check and prune
|
||||
- name: Add single Cron job for borgmatic
|
||||
cron:
|
||||
name: "{{ borgmatic_timer_cron_name }}"
|
||||
hour: "{{ borgmatic_timer_hour }}"
|
||||
@ -18,6 +18,7 @@
|
||||
- name: Ensure separate check cron job is absent
|
||||
cron:
|
||||
name: "{{ borgmatic_timer_cron_name }}-check"
|
||||
cron_file: "{{ borgmatic_timer_cron_name }}"
|
||||
state: absent
|
||||
|
||||
- name: Set PATH for borgmatic cron job.
|
||||
|
@ -1,4 +1,18 @@
|
||||
---
|
||||
- name: Register existence of Borgmatic cron file.
|
||||
cron:
|
||||
name: "{{ borgmatic_timer_cron_name }}"
|
||||
cron_file: "{{ borgmatic_timer_cron_name }}"
|
||||
state: absent
|
||||
check_mode: true
|
||||
register: cron_file_exists
|
||||
|
||||
- name: Ensure no Borgmatic Cron file exists.
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- not cron_file_exists.changed
|
||||
fail_msg: Found an existing Borgmatic Cron job. Please remove before using Systemd timer.
|
||||
|
||||
- name: Create borgbackup timer
|
||||
block:
|
||||
- name: Copy systemd files
|
||||
@ -21,7 +35,7 @@
|
||||
- name: Stop fresh installed borgmatic.timer and borgmatic.service
|
||||
when: "'borgmatic.service' not in ansible_facts.services"
|
||||
block:
|
||||
- name: Set borgmatic services to stopped - fresh installed
|
||||
- name: Set borgmatic services to stopped - newly installed
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
@ -33,7 +47,7 @@
|
||||
- borgmatic.service
|
||||
|
||||
# bug: Need own section without masked else the timer are skipped
|
||||
- name: Set borgmatic timers to stopped - fresh installed
|
||||
- name: Set borgmatic timers to stopped - newly installed
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
|
Loading…
Reference in New Issue
Block a user