support enable/disable timed backups

This commit is contained in:
Nils Norman Haukås 2024-02-23 12:07:16 +01:00
parent 3b0406131b
commit 87724e3d14
5 changed files with 35 additions and 33 deletions

View file

@ -8,6 +8,7 @@
- (cd "/tmp" && forgejo.sh dump --file="forgejo.zip")
restic_backup_targets:
- /tmp/forgejo.zip
restic_backup_frequency: daily
sendmail_mta_user: "{{ vault_mta_user }}"
sendmail_mta_user_pw: "{{ vault_mta_user_pw }}"
sendmail_mailhub: "box.nilsnh.no:465"
@ -31,20 +32,3 @@
- forgejo
- caddy
# - hosts: this_machine
# handlers:
# vars:
# restic_repo_pw: "{{ vault_restic_pw_mrmittens }}"
# restic_repo_url: "{{ vault_restic_url_mrmittens }}"
# sendmail_mta_user: "{{ vault_mta_user }}"
# sendmail_mta_user_pw: "{{ vault_mta_user_pw }}"
# sendmail_mailhub: "box.nilsnh.no:465"
# sendmail_hostname: mr-mittens.box.nilsnh.no
# sendmail_rewrite_domain: "nilsnh.no"
# sendmail_revaliases:
# root: "{{ machine_from_email }}"
# machine_from_email: "noreply+mr-mittens@nilsnh.no"
# machine_notifications_receiver: "mail@nilsnh.no"
# roles:
# - sendmail
# - backup

View file

@ -1,9 +0,0 @@
[Unit]
Description=Run backups daily
[Timer]
OnCalendar=daily
Persistent=false
[Install]
WantedBy=timers.target

View file

@ -77,14 +77,32 @@
- name: upload systemd unit files
copy:
src: "{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
loop:
- backup.service
- backup.timer
src: backup.service
dest: /etc/systemd/system/backup.service
- name: Enable backup.timer
- name: upload backup.timer
ansible.builtin.template:
src: backup.timer.j2
dest: /etc/systemd/system/backup.timer
when: restic_backup_frequency
- name: enable backup.timer
ansible.builtin.systemd:
name: backup.timer
state: started
enabled: true
enabled: true
when: restic_backup_frequency
- name: disable backup.timer, if restic_backup_frequency is set to false
ansible.builtin.systemd:
name: backup.timer
state: stopped
enabled: false
when: not restic_backup_frequency
- name: remove backup.timer, if restic_backup_frequency is set to false
ansible.builtin.file:
path: /etc/systemd/system/backup.timer
state: absent
when: not restic_backup_frequency

View file

@ -0,0 +1,9 @@
[Unit]
Description=Run backups, on schedule: "{{ restic_backup_frequency }}".
[Timer]
OnCalendar={{ restic_backup_frequency }}
Persistent=false
[Install]
WantedBy=timers.target