From e1cc8f6d35f8f80bb188cf1793dd35f32e7c8898 Mon Sep 17 00:00:00 2001 From: mg Date: Wed, 30 Dec 2020 23:49:26 +0100 Subject: [PATCH] "Refactor" Sanoid Role (#18) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Datasets können einzeln mit verschiedenen Templates konfiguriert werden Co-authored-by: Michael Grote <38253905+quotengrote@users.noreply.github.com> Reviewed-on: https://git.mgrote.net/mg/ansible/pulls/18 Co-Authored-By: mg Co-Committed-By: mg --- group_vars/virt.yml | 10 ++-- playbooks/service/fileserver.yml | 2 +- roles/mgrote.sanoid/defaults/main.yml | 54 +++++++++++--------- roles/mgrote.sanoid/templates/sanoid.conf.j2 | 48 ++++++++++++----- 4 files changed, 68 insertions(+), 46 deletions(-) diff --git a/group_vars/virt.yml b/group_vars/virt.yml index 2b67dbaa..c061ffec 100644 --- a/group_vars/virt.yml +++ b/group_vars/virt.yml @@ -11,13 +11,9 @@ - .tmux.conf - .gitconfig ### mgrote.sanoid - sanoid_zfs_recursive: 'yes' - sanoid_zfs_dataset: "hdd_data_raidz/data" - sanoid_snapshot_interval_underhour: '5' - sanoid_snapshot_keep_underhour: '36' - sanoid_snapshot_keep_daily: '31' - sanoid_snapshot_keep_monthly: '6' - sanoid_snapshot_keep_hourly: '24' + sanoid_datasets: + - { path: 'hdd_data_raidz/data', template: 'fiveminutes', recursive: ' no' } + - { path: 'hdd_data_raidz/videos', template: 'hourly', recursive: ' yes' } ### mgrote.smart smart_smartctlmail_cron_minutes: "15" smart_smartctlmail_cron_hours: "6" diff --git a/playbooks/service/fileserver.yml b/playbooks/service/fileserver.yml index 33a4e68c..760f449c 100644 --- a/playbooks/service/fileserver.yml +++ b/playbooks/service/fileserver.yml @@ -8,7 +8,7 @@ ############################################################################### # in PVE # pct set 109 -mp1 /hdd_data_raidz/data,mp=/shares/ -# pct set 109 -mp0 /hdd_data_raidz/data_videos,mp=/shares_videos +# pct set 109 -mp0 /hdd_data_raidz/videos,mp=/shares_videos ############################################################################### --- diff --git a/roles/mgrote.sanoid/defaults/main.yml b/roles/mgrote.sanoid/defaults/main.yml index 40d3182f..78c32a67 100644 --- a/roles/mgrote.sanoid/defaults/main.yml +++ b/roles/mgrote.sanoid/defaults/main.yml @@ -1,30 +1,34 @@ --- - # Default Value for Sanoid Cron Hours + # Wann soll das sanoid-script mit cron ausgeführt werden? (Stunden) sanoid_cron_hours: '*' - - # Default Value for Sanoid Cron Minutes + # Wann soll das sanoid-script mit cron ausgeführt werden? (Minuten) sanoid_cron_minutes: '*' - # Default Value for Sanoid Keep Hourly Snapshot - sanoid_snapshot_keep_hourly: '1' + ### Definition der Variablen für die sanoid-templates- + # template_fiveminutes + sanoid_template_fiveminutes_snapshot_keep_hourly: '24' # Aufheben (Stunde) + sanoid_template_fiveminutes_snapshot_keep_daily: '31' # Aufheben (Tage) + sanoid_template_fiveminutes_snapshot_keep_monthly: '6' # Aufheben (Monate) + sanoid_template_fiveminutes_snapshot_keep_yearly: '0' # Aufheben (Jahre) + sanoid_template_fiveminutes_snapshot_interval_underhour: '5' # Intervall (alle 5 Minuten) + sanoid_template_fiveminutes_snapshot_keep_underhour: '36' # Aufheben (Minuten) + sanoid_template_fiveminutes_auto_snap: 'yes' # Automatisches erstellen von Snapshots + sanoid_template_fiveminutes_prune: 'yes' # Automatisches Löschen/Prunen alter Snapshots + # template_hourly + sanoid_template_hourly_snapshot_keep_hourly: '24' + sanoid_template_hourly_snapshot_keep_daily: '31' + sanoid_template_hourly_snapshot_keep_monthly: '6' + sanoid_template_hourly_snapshot_keep_yearly: '1' + sanoid_template_hourly_auto_snap: 'yes' + sanoid_template_hourly_prune: 'yes' + # template_daily + sanoid_template_daily_snapshot_keep_daily: '31' + sanoid_template_daily_snapshot_keep_monthly: '6' + sanoid_template_daily_snapshot_keep_yearly: '1' + sanoid_template_daily_auto_snap: 'yes' + sanoid_template_daily_prune: 'yes' - # Default Value for Sanoid Keep Daily Snapshot - sanoid_snapshot_keep_daily: '14' - - # Default Value for Sanoid Keep Monthly Snapshot - sanoid_snapshot_keep_monthly: '3' - - # Default Value for Sanoid Keep Yearly Snapshot - sanoid_snapshot_keep_yearly: '0' - - # Default Value for Sanoid Auto Snapshot - sanoid_auto_snap: 'yes' - - # Default Value for Sanoid Auto Prune - sanoid_auto_prune: 'yes' - - # Default Value for Sanoid ZFS Dataset Name - sanoid_zfs_dataset: 'hdd_data_raidz/data' - - # Default Value for Sanoid ZFS Recursive Snapshot - sanoid_zfs_recursive: 'yes' + ### "Default" Datasets + sanoid_datasets: + - { path: 'hdd_data_raidz/data', template: 'fiveminutes', recursive: ' no' } + - { path: 'hdd_data_raidz/videos', template: 'hourly', recursive: ' yes' } diff --git a/roles/mgrote.sanoid/templates/sanoid.conf.j2 b/roles/mgrote.sanoid/templates/sanoid.conf.j2 index 57dff5e2..a8afb290 100644 --- a/roles/mgrote.sanoid/templates/sanoid.conf.j2 +++ b/roles/mgrote.sanoid/templates/sanoid.conf.j2 @@ -1,18 +1,40 @@ ## ZFS Section ## -[{{ sanoid_zfs_dataset }}] - use_template = production - recursive = {{ sanoid_zfs_recursive }} +{% for item in sanoid_datasets %} +[{{ item.path }}] + use_template = {{ item.template }} + recursive = {{ item.recursive }} +## ----------- ## +{% endfor %} + + ## Template Section ## -[template_production] +[template_fiveminutes] ## Keep-Rules - hourly = {{ sanoid_snapshot_keep_hourly }} - daily = {{ sanoid_snapshot_keep_daily }} - monthly = {{ sanoid_snapshot_keep_monthly }} - yearly = {{ sanoid_snapshot_keep_yearly }} - ## Underhour - Snapshots - frequent_period = {{ sanoid_snapshot_interval_underhour }} - frequently = {{ sanoid_snapshot_keep_underhour }} + hourly = {{ sanoid_template_fiveminutes_snapshot_keep_hourly }} + daily = {{ sanoid_template_fiveminutes_snapshot_keep_daily }} + monthly = {{ sanoid_template_fiveminutes_snapshot_keep_monthly }} + yearly = {{ sanoid_template_fiveminutes_snapshot_keep_yearly }} + frequently = {{ sanoid_template_fiveminutes_snapshot_keep_underhour }} + ## Underhour intervall + frequent_period = {{ sanoid_template_fiveminutes_snapshot_interval_underhour }} ## Other Options - autosnap = {{ sanoid_auto_snap }} - autoprune = {{ sanoid_auto_prune }} + autosnap = {{ sanoid_template_fiveminutes_auto_snap }} + autoprune = {{ sanoid_template_fiveminutes_prune }} +[template_hourly] + ## Keep-Rules + hourly = {{ sanoid_template_hourly_snapshot_keep_hourly }} + daily = {{ sanoid_template_hourly_snapshot_keep_daily }} + monthly = {{ sanoid_template_hourly_snapshot_keep_monthly }} + yearly = {{ sanoid_template_hourly_snapshot_keep_yearly }} + ## Other Options + autosnap = {{ sanoid_template_hourly_auto_snap }} + autoprune = {{ sanoid_template_hourly_prune }} +[template_daily] + ## Keep-Rules + daily = {{ sanoid_template_daily_snapshot_keep_daily }} + monthly = {{ sanoid_template_daily_snapshot_keep_monthly }} + yearly = {{ sanoid_template_daily_snapshot_keep_yearly }} + ## Other Options + autosnap = {{ sanoid_template_daily_auto_snap }} + autoprune = {{ sanoid_template_daily_prune }}