2020-11-13 11:36:52 +00:00
|
|
|
from os.path import join
|
|
|
|
|
2021-05-15 18:32:23 +00:00
|
|
|
if node.has_bundle('zfs'):
|
|
|
|
wanted_paths = node.metadata.get('backups/paths', set())
|
|
|
|
snapshot_paths = node.metadata.get('zfs/filesystems_with_backup_snapshots', {})
|
|
|
|
backup_paths = set()
|
|
|
|
|
|
|
|
for path in wanted_paths:
|
|
|
|
path_found = False
|
|
|
|
for zfs_paths in snapshot_paths.values():
|
|
|
|
if path in zfs_paths:
|
|
|
|
backup_paths.add(f'/mnt/backup-snapshot{path}')
|
|
|
|
path_found = True
|
|
|
|
|
|
|
|
if not path_found:
|
|
|
|
backup_paths.add(path)
|
|
|
|
else:
|
|
|
|
backup_paths = node.metadata.get('backups/paths', set())
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
if node.metadata.get('backups/exclude_from_backups', False):
|
2021-02-07 19:47:22 +00:00
|
|
|
files['/etc/backup.priv'] = {
|
|
|
|
'delete': True,
|
2020-11-13 11:36:52 +00:00
|
|
|
}
|
|
|
|
else:
|
2020-11-14 11:49:57 +00:00
|
|
|
if ':' in node.metadata['backup-client']['server']:
|
|
|
|
server, port = node.metadata['backup-client']['server'].split(':')
|
|
|
|
else:
|
|
|
|
server = node.metadata['backup-client']['server']
|
|
|
|
port = 22
|
|
|
|
|
2021-02-07 19:47:22 +00:00
|
|
|
files['/usr/local/bin/generate-backup'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'username': node.metadata['backup-client']['user-name'],
|
|
|
|
'server': server,
|
|
|
|
'port': port,
|
2021-05-15 18:32:23 +00:00
|
|
|
'paths': backup_paths,
|
2020-11-13 11:36:52 +00:00
|
|
|
},
|
2021-02-07 19:47:22 +00:00
|
|
|
'mode': '0700',
|
|
|
|
}
|
|
|
|
files['/etc/backup.priv'] = {
|
|
|
|
'content': repo.vault.decrypt_file(join('backup', 'keys', f'{node.name}.key.vault')),
|
|
|
|
'mode': '0400',
|
2020-11-13 11:36:52 +00:00
|
|
|
}
|
|
|
|
|
2021-02-07 19:47:22 +00:00
|
|
|
files['/usr/local/share/icinga/plugins/check_backup_last_run'] = {
|
|
|
|
'mode': '0755',
|
|
|
|
}
|
|
|
|
|
2021-06-06 06:05:41 +00:00
|
|
|
files['/etc/logrotate.d/backup-client'] = {
|
|
|
|
'source': 'logrotate.conf',
|
|
|
|
}
|
|
|
|
|
2021-02-07 19:47:22 +00:00
|
|
|
directories['/etc/backup-pre-hooks.d'] = {
|
|
|
|
'purge': True,
|
|
|
|
}
|
|
|
|
|
2021-06-06 06:05:41 +00:00
|
|
|
directories['/var/log/backup-client'] = {}
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for hname, hcontent in node.metadata.get('backup-client/pre-hooks', {}).items():
|
2021-02-13 07:37:49 +00:00
|
|
|
files[f'/etc/backup-pre-hooks.d/50-{hname}'] = {
|
2021-02-13 07:26:46 +00:00
|
|
|
'content': '#!/bin/sh\n\n' + hcontent,
|
2021-02-07 19:47:22 +00:00
|
|
|
'mode': '0700',
|
|
|
|
}
|