diff --git a/data/common/common.yaml b/data/common/common.yaml --- a/data/common/common.yaml +++ b/data/common/common.yaml @@ -3657,3 +3657,46 @@ postgresql::globals::version: "%{lookup('swh::postgresql::version')}" docker::compose::version: "1.29.2" + +sanoid::templates: + pg_backup: + frequent_period: 0 + pre_snapshot_script: /tmp/pre.sh + post_snapshot_script: /tmp/post.sh + pruning_script: /tmp/prune.sh + script_timeout: 10 + monthly: 3 + daily: 30 + hourly: 0 + frequently: 0 + autoprune: yes + + pg_raw_backup: + frequent_period: 0 + pre_snapshot_script: /root/start_pg_backup.sh + post_snapshot_script: /root/stop_pg_backup.sh + script_timeout: 30 + monthly: 3 + daily: 30 + hourly: 0 + frequently: 0 + autoprune: yes + + backup: # from the default sanoid configuration + autoprune: yes + frequently: 0 + hourly: 30 + daily: 30 + monthly: 3 + yearly: 0 + ### don't take new snapshots - snapshots on backup + ### datasets are replicated in from source, not + ### generated locally + autosnap: no + ### monitor hourlies and dailies, but don't warn or + ### crit until they're over 48h old, since replication + ### is typically daily only + hourly_warn: 2880 + hourly_crit: 3600 + daily_warn: 48 + daily_crit: 60 diff --git a/data/hostname/dali.internal.admin.swh.network.yaml b/data/hostname/dali.internal.admin.swh.network.yaml --- a/data/hostname/dali.internal.admin.swh.network.yaml +++ b/data/hostname/dali.internal.admin.swh.network.yaml @@ -24,3 +24,26 @@ prometheus::sql::config_snippets: - activity - queries + +sanoid::configuration: + + storage_config: + data/postgresql: + use_template: backup + data/postgresql/wal: + use_template: backup + + local_config: + data/postgresql: + use_template: pg_backup + hourly: 0 + monthly: 1 + daily: 7 + data/postgresql/wal: + use_template: pg_wal_backup + hourly: 0 + monthly: 1 + daily: 7 + + + diff --git a/site-modules/profile/manifests/sanoid/backup.pp b/site-modules/profile/manifests/sanoid/backup.pp new file mode 100644 --- /dev/null +++ b/site-modules/profile/manifests/sanoid/backup.pp @@ -0,0 +1,53 @@ +class profile::sanoid::backup { + ensure_packages('sanoid') + + $config_dir = '/etc/sanoid' + $config_file = "${config_dir}/sanoid.conf" + $host_configuration = lookup('sanoid::configuration') + $sanoid_templates = lookup('sanoid::templates') + + file {$config_dir: + ensure => directory, + owner => 'root', + group => 'root', + mode => '0755', + } + + concat {$config_file: + ensure => present, + owner => 'root', + group => 'root', + mode => '0644', + ensure_newline => true, + require => File[$config_dir] + } + + concat::fragment {"${config_file}:header": + target => $config_file, + content => "# File managed with puppet (module profile::varnish)\n# All modifications will be lost\n\n", + order => '00', + } + + $host_configuration["local_config"].each | $dataset, $config | { + $toml_config = "${ to_toml({$dataset => $config }) }\n" + # unescape toml keys escaped by to_toml when a '/' is present + # ["data/postgresql"] => [data/postgreql] + $unescaped_toml = regsubst($toml_config, '^\["(.*)"\]', '[\\1]') + concat::fragment {"${config_file}:${dataset}": + target => $config_file, + content => $unescaped_toml, + order => '01', + } + } + + $sanoid_templates.each | $template, $config | { + $key = "template_${template}" + concat::fragment {"template_${config_file}:${template}": + target => $config_file, + content => "${ to_toml({$key => $config })} \n", + order => '99', + } + } + +} + diff --git a/site-modules/role/manifests/swh_admin_database.pp b/site-modules/role/manifests/swh_admin_database.pp --- a/site-modules/role/manifests/swh_admin_database.pp +++ b/site-modules/role/manifests/swh_admin_database.pp @@ -2,4 +2,5 @@ include profile::postgresql include profile::postgresql::server include profile::prometheus::sql + include profile::sanoid::backup }