bundles/zfs: introduce zfs-snapshot-backups, enable backups for nodes which need zfs-snapshot-backups
All checks were successful
bundlewrap/pipeline/head This commit looks good
All checks were successful
bundlewrap/pipeline/head This commit looks good
This commit is contained in:
parent
93e36156a0
commit
479b730be4
11 changed files with 96 additions and 18 deletions
21
bundles/zfs/files/backup-pre-hook
Normal file
21
bundles/zfs/files/backup-pre-hook
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
run-parts --exit-on-error -- /etc/zfs-snapshot-backup-pre.d
|
||||
|
||||
|
||||
% for dataset in sorted(node.metadata.get('zfs/filesystems_with_backup_snapshots')):
|
||||
if zfs get type ${dataset}@snapshot-backup >/dev/null 2>&1
|
||||
then
|
||||
zfs destroy -f ${dataset}@snapshot-backup
|
||||
fi
|
||||
|
||||
zfs snapshot ${dataset}@snapshot-backup
|
||||
|
||||
mkdir -p /mnt/backup-snapshot${node.metadata['zfs']['datasets'][dataset]['mountpoint']}
|
||||
mount -t zfs ${dataset}@snapshot-backup /mnt/backup-snapshot${node.metadata['zfs']['datasets'][dataset]['mountpoint']}
|
||||
|
||||
|
||||
% endfor
|
||||
run-parts --exit-on-error -- /etc/zfs-snapshot-backup-post.d
|
|
@ -95,7 +95,11 @@ directories = {
|
|||
"/etc/zfs-snapshot-backup-post.d": {
|
||||
'purge': True,
|
||||
},
|
||||
"/etc/zfs-snapshot-backup-final.d": {
|
||||
'purge': True,
|
||||
},
|
||||
}
|
||||
|
||||
if node.metadata.get('zfs/filesystems_with_backup_snapshots', {}) and node.has_bundle('backup-client'):
|
||||
files['/etc/backup-pre-hooks.d/99-zfs-snapshots'] = {
|
||||
'content_type': 'mako',
|
||||
'source': 'backup-pre-hook',
|
||||
'mode': '0755',
|
||||
}
|
||||
|
|
|
@ -104,7 +104,9 @@ def zfs_scrub_cronjob(metadata):
|
|||
}
|
||||
|
||||
|
||||
@metadata_reactor
|
||||
@metadata_reactor.provides(
|
||||
'icinga2_api/zfs/services',
|
||||
)
|
||||
def monitoring(metadata):
|
||||
if not node.has_bundle('sshmon'):
|
||||
raise DoNotRunAgain
|
||||
|
@ -129,3 +131,25 @@ def monitoring(metadata):
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@metadata_reactor.provides(
|
||||
'zfs/filesystems_with_backup_snapshots',
|
||||
)
|
||||
def backups_with_snapshot(metadata):
|
||||
backups = metadata.get('backups/paths', set())
|
||||
datasets = metadata.get('zfs/datasets', {})
|
||||
|
||||
backups_in_zfs_datasets = {}
|
||||
|
||||
for path in backups:
|
||||
for dname, dconfig in datasets.items():
|
||||
if 'mountpoint' in dconfig:
|
||||
if path[:len(dconfig['mountpoint'])] == dconfig['mountpoint']:
|
||||
backups_in_zfs_datasets.setdefault(dname, set()).add(path)
|
||||
|
||||
return {
|
||||
'zfs': {
|
||||
'filesystems_with_backup_snapshots': backups_in_zfs_datasets,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue