Skip to content

Commit

Permalink
initial role
Browse files Browse the repository at this point in the history
  • Loading branch information
haslersn committed Nov 6, 2024
1 parent ce11ad7 commit 8d69e8b
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 64 deletions.
227 changes: 164 additions & 63 deletions files/zfs-restic-uploader

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Reload systemd configuration
service:
daemon_reload: True
52 changes: 51 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
---
- name: Install dependencies
apt:
name:
- proot
- python3-udatetime
- restic

- name: Install zfs-restic-uploader
copy:
src: zfs-restic-uploader
dest: /opt/zfs-restic-uploader
mode: 0755

- name: Create config directory
file:
path: /etc/zfs-restic-uploader
state: directory

- name: Place restic password
copy:
content: "{{ zru_restic_repo_password }}"
dest: /etc/zfs-restic-uploader/restic-password
mode: 0600

- name: Place env file
template:
src: env.j2
dest: /etc/zfs-restic-uploader/env
mode: 0600

- name: Create systemd service
template:
src: service.j2
dest: /etc/systemd/system/zfs-restic-uploader.service
mode: 0644
notify:
- Reload systemd configuration

- name: Create systemd timer
template:
src: timer.j2
dest: /etc/systemd/system/zfs-restic-uploader.timer
mode: 0644
notify:
- Reload systemd configuration

- meta: flush_handlers

- name: Enable zfs-restic-uploader timer
systemd:
name: zfs-restic-uploader.timer
enabled: true
6 changes: 6 additions & 0 deletions templates/env.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# {{ ansible_managed }}
AWS_ACCESS_KEY_ID={{ zru_access_key_id | quote }}
AWS_SECRET_ACCESS_KEY={{ zru_secret_access_key | quote }}
XDG_CACHE_HOME={{ zru_cache_directory }}
GOMAXPROCS=1
RESTIC_READ_CONCURRENCY=1
21 changes: 21 additions & 0 deletions templates/service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# {{ ansible_managed }}
[Unit]
Description=upload ZFS snapshots to restic repository
Requires=zfs.target
After=zfs.target

[Service]
EnvironmentFile=/etc/zfs-restic-uploader/env
ExecStart=/opt/zfs-restic-uploader \
-r {{ zru_restic_repo_prefix | quote }} \
-p /etc/zfs-restic-uploader/restic-password \
-c {{ zru_zfs_dataset_common_prefix | quote }} \
--exclude-snapnames-regex {{ zru_exclude_snapnames_regex | quote }} \
{% if zru_restic_check %}
--check \
{% endif %}
dataset {{ zru_zfs_datasets | map("quote") | join(" ") }} \
--keep-last-n {{ zru_keep_last_n | quote }} \
--keep-weekly-n {{ zru_keep_weekly_n | quote }} \
--keep-monthly-n {{ zru_keep_monthly_n | quote }}
Restart=on-failure
10 changes: 10 additions & 0 deletions templates/timer.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# {{ ansible_managed }}
[Unit]
Description=upload ZFS snapshots to restic repository

[Timer]
OnCalendar={{ zru_schedule }}
Unit=zfs-restic-uploader.service

[Install]
WantedBy=timers.target

0 comments on commit 8d69e8b

Please sign in to comment.