Start of zrepl role.

Currently only doing FreeBSD.
This commit is contained in:
Tom Alexander 2022-10-10 22:31:22 -04:00
parent a271d1c756
commit 87c6ad5c5a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
10 changed files with 74 additions and 0 deletions

View File

@ -1 +1,3 @@
os_flavor: "freebsd"
zfs_snapshot_datasets:
- zroot/freebsd/computer/be/default

View File

@ -10,3 +10,6 @@ users:
- name: users
- name: docker
- name: libvirt
zfs_snapshot_datasets:
- zroot/linux/archmain/home
- zroot/linux/archmain/be

View File

@ -4,3 +4,4 @@
roles:
- sudo
- users
- zrepl

View File

@ -0,0 +1,4 @@
- name: restart zrepl
service:
name: zrepl
state: restarted

View File

@ -0,0 +1,2 @@
dependencies:
- users

View File

@ -0,0 +1,31 @@
- name: Install packages
package:
name:
- zrepl
state: present
- name: Create directories
file:
name: "{{ item }}"
state: directory
mode: 0750
owner: root
group: wheel
loop:
- /usr/local/etc/zrepl
- name: Configure zrepl
template:
src: templates/zrepl.yml.j2
dest: /usr/local/etc/zrepl/zrepl.yml
mode: 0440
owner: root
group: wheel
validate: "zrepl configcheck --config %s"
notify: "restart zrepl"
- include: tasks/freebsd.yaml
when: 'os_flavor == "freebsd"'
- include: tasks/linux.yaml
when: 'os_flavor == "linux"'

View File

View File

View File

@ -0,0 +1,2 @@
- include: tasks/common.yaml
when: zfs_snapshot_datasets is defined

View File

@ -0,0 +1,29 @@
jobs:
# this job takes care of snapshot creation + pruning
- name: snapjob
type: snap
filesystems: {
{% for dataset in zfs_snapshot_datasets %}
"{{dataset}}<": true,
{% endfor %}
}
# create snapshots with prefix `zrepl_` every 15 minutes
snapshotting:
type: periodic
interval: 15m
prefix: zrepl_
pruning:
keep:
# fade-out scheme for snapshots starting with `zrepl_`
# - keep all created in the last hour
# - then destroy snapshots such that we keep 24 each 1 hour apart
# - then destroy snapshots such that we keep 14 each 1 day apart
# - then destroy all older snapshots
- type: grid
grid: 1x1h(keep=all) | 24x1h | 14x1d
regex: "^zrepl_.*"
# keep all snapshots that don't have the `zrepl_` prefix
- type: regex
negate: true
regex: "^zrepl_.*"