Wrap backup script in systemd service and timer

This commit is contained in:
Thomas Kleinendorst 2025-01-14 17:16:21 +01:00
parent cf23a37aa0
commit b7183ceeae
3 changed files with 52 additions and 8 deletions

View file

@ -0,0 +1,10 @@
[Unit]
Description=BorgBase backup timer
[Timer]
OnCalendar=daily
RandomizedDelaySec=900
Persistent=true
[Install]
WantedBy=timers.target

View file

@ -15,14 +15,14 @@
owner: root
group: root
mode: '0700'
# - name: Copy over script
# become: true
# ansible.builtin.copy:
# src: backup_script.sh
# dest: "{{ backups_script_path }}"
# owner: root
# group: root
# mode: '0700'
- name: Copy over script
become: true
ansible.builtin.copy:
src: backup_script.sh
dest: "{{ backups_script_path }}"
owner: root
group: root
mode: '0700'
- name: Ensure directory for configuration file exists
become: true
ansible.builtin.file:
@ -39,3 +39,22 @@
owner: root
group: root
mode: '0400'
- name: Install BorgBase backup service file
become: true
ansible.builtin.template:
src: borg_backup.service.j2
dest: "/lib/systemd/system/borg_backup.service"
mode: '0644'
- name: Install BorgBase backup timer file
become: true
ansible.builtin.copy:
src: borg_backup.timer
dest: "/lib/systemd/system/borg_backup.timer"
mode: '0644'
- name: Enable the newly added systemd timer
become: true
ansible.builtin.systemd_service:
daemon_reload: true
name: "borg_backup.timer"
state: started
enabled: true

View file

@ -0,0 +1,15 @@
[Unit]
Description=BorgBase backup service
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
User=root
Group=root
ExecStart={{ backups_script_path }} {{ backups_configuration_path }}
Environment="BORG_REPO={{ borg_base.repo_url }}"
Environment="BORG_PASSPHRASE={{ borg_backup_password }}"
[Install]
WantedBy=default.target