2021-04-02 16:57:13 +00:00
|
|
|
repo.libs.tools.require_bundle(node, 'zfs')
|
2020-11-13 11:36:52 +00:00
|
|
|
|
|
|
|
from os.path import join
|
2023-02-05 16:30:58 +00:00
|
|
|
|
2022-01-05 08:53:18 +00:00
|
|
|
from bundlewrap.metadata import metadata_to_json
|
2020-11-13 11:36:52 +00:00
|
|
|
|
2021-08-01 05:57:48 +00:00
|
|
|
dataset = node.metadata.get('backup-server/zfs-base')
|
|
|
|
|
2022-01-05 08:53:18 +00:00
|
|
|
files = {
|
|
|
|
'/etc/backup-server/config.json': {
|
|
|
|
'content': metadata_to_json({
|
|
|
|
'zfs-base': dataset,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
'/usr/local/bin/rotate-single-backup-client': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2022-01-05 21:44:55 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_backup_for_node': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2022-01-05 08:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
directories['/etc/backup-server/clients'] = {
|
|
|
|
'purge': True,
|
|
|
|
}
|
|
|
|
|
|
|
|
sudoers = {}
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for nodename, config in node.metadata.get('backup-server/clients', {}).items():
|
2020-11-13 11:36:52 +00:00
|
|
|
with open(join(repo.path, 'data', 'backup', 'keys', f'{nodename}.pub'), 'r') as f:
|
|
|
|
pubkey = f.read().strip()
|
|
|
|
|
2022-01-05 08:53:18 +00:00
|
|
|
sudoers[config['user']] = nodename
|
|
|
|
|
2020-11-13 11:36:52 +00:00
|
|
|
users[config['user']] = {
|
|
|
|
'home': f'/srv/backups/{nodename}',
|
|
|
|
}
|
|
|
|
|
2022-01-05 08:53:18 +00:00
|
|
|
files[f'/etc/backup-server/clients/{nodename}'] = {
|
|
|
|
'content': metadata_to_json(config['retain']),
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:36:52 +00:00
|
|
|
files[f'/srv/backups/{nodename}/.ssh/authorized_keys'] = {
|
|
|
|
'content': pubkey,
|
|
|
|
'owner': config['user'],
|
|
|
|
'mode': '0400',
|
2021-08-01 05:57:48 +00:00
|
|
|
'needs': {
|
|
|
|
f'zfs_dataset:{dataset}/{nodename}',
|
|
|
|
},
|
2020-11-13 11:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
directories[f'/srv/backups/{nodename}/backups'] = {
|
|
|
|
'owner': config['user'],
|
|
|
|
'mode': '0700',
|
2021-08-01 05:57:48 +00:00
|
|
|
'needs': {
|
|
|
|
f'zfs_dataset:{dataset}/{nodename}',
|
|
|
|
},
|
2020-11-13 11:36:52 +00:00
|
|
|
}
|
2022-01-05 08:53:18 +00:00
|
|
|
|
|
|
|
files['/etc/sudoers.d/backup-server'] = {
|
|
|
|
'source': 'sudoers',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'clients': sudoers,
|
|
|
|
},
|
|
|
|
}
|