Wrap backup script in systemd service and timer
This commit is contained in:
parent
cf23a37aa0
commit
b7183ceeae
3 changed files with 52 additions and 8 deletions
10
roles/backups/files/borg_backup.timer
Normal file
10
roles/backups/files/borg_backup.timer
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[Unit]
|
||||
Description=BorgBase backup timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
RandomizedDelaySec=900
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
|
|
@ -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
|
||||
|
|
|
|||
15
roles/backups/templates/borg_backup.service.j2
Normal file
15
roles/backups/templates/borg_backup.service.j2
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue