Skip to content

Commit

Permalink
Create autorestic backup services
Browse files Browse the repository at this point in the history
  • Loading branch information
claha committed Jul 22, 2023
1 parent 9f4eefa commit 7f7a125
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
6 changes: 2 additions & 4 deletions main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@
tags: traefik
- role: homepage
tags: homepage
- role: autorestic
tags: autorestic
- role: homeassistant
tags: homeassistant
tags: homeassistant, autorestic
- role: github_deploy
tags: deploy

Expand All @@ -86,7 +84,7 @@
- role: bash
tags: never, init
- role: zigbee2mqtt
tags: zigbee2mqtt
tags: zigbee2mqtt, autorestic

- name: Setup nixos
hosts: nixos
Expand Down
31 changes: 31 additions & 0 deletions roles/autorestic/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,34 @@
src: "files/justfile"
dest: "{{ service_path }}/justfile"
mode: "0640"

- name: Create periodic backup service
when: autorestic_location is defined
block:
- name: Create backup script
become: true
ansible.builtin.template:
src: autorestic_backup.sh.j2
dest: "/usr/bin/autorestic_backup_{{ autorestic_location }}.sh"
mode: "0755"

- name: Create backup service file
become: true
ansible.builtin.template:
src: autorestic_backup.service.j2
dest: "/etc/systemd/system/autorestic_backup_{{ autorestic_location }}.service" # yamllint disable-line rule:line-length
mode: "0755"

- name: Create backup timer file
become: true
ansible.builtin.template:
src: autorestic_backup.timer.j2
dest: "/etc/systemd/system/autorestic_backup_{{ autorestic_location }}.timer" # yamllint disable-line rule:line-length
mode: "0755"

- name: Enable and start the backup timer
become: true
ansible.builtin.service:
name: "autorestic_backup_{{ autorestic_location }}.timer"
enabled: true
state: started
6 changes: 6 additions & 0 deletions roles/autorestic/templates/autorestic_backup.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Unit]
Description=Backup {{ autorestic_location }} using autorestic

[Service]
Type=simple
ExecStart=/usr/bin/autorestic_backup_{{ autorestic_location }}.sh
4 changes: 4 additions & 0 deletions roles/autorestic/templates/autorestic_backup.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cd {{ service_path }}
docker compose run autorestic autorestic backup --verbose --location {{ autorestic_location }}
9 changes: 9 additions & 0 deletions roles/autorestic/templates/autorestic_backup.timer.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Backup {{ autorestic_location }} timer

[Timer]
OnCalendar=*-*-* 12:00:00
Unit=autorestic_backup_{{ autorestic_location }}.service

[Install]
WantedBy=timers.target
6 changes: 6 additions & 0 deletions roles/homeassistant/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@
dest: "{{ service_path }}/config/secrets.yaml"
mode: "0600"
notify: "Recreate {{ service_name }}"

- name: Create backups with autorestic
ansible.builtin.include_role:
name: autorestic
vars:
autorestic_location: "homeassistant"
6 changes: 6 additions & 0 deletions roles/zigbee2mqtt/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@
- devices.yaml
- groups.yaml
notify: "Recreate {{ service_name }}"

- name: Create backups with autorestic
ansible.builtin.include_role:
name: autorestic
vars:
autorestic_location: "zigbee2mqtt"

0 comments on commit 7f7a125

Please sign in to comment.