bundles/backup-{client,server}: introduce

This commit is contained in:
Franzi 2020-11-13 12:36:52 +01:00
parent 59c1cb8551
commit f71653e3ce
Signed by: kunsi
GPG key ID: 12E3D2136B818350
23 changed files with 171 additions and 0 deletions

View file

@ -0,0 +1,28 @@
assert node.has_bundle('zfs')
from os.path import join
for nodename, config in node.metadata.get('backup-server', {}).get('clients', {}).items():
with open(join(repo.path, 'data', 'backup', 'keys', f'{nodename}.pub'), 'r') as f:
pubkey = f.read().strip()
users[config['user']] = {
'home': f'/srv/backups/{nodename}',
}
files[f'/srv/backups/{nodename}/.ssh/authorized_keys'] = {
'content': pubkey,
'owner': config['user'],
'mode': '0400',
'needs': {
'bundle:zfs',
},
}
directories[f'/srv/backups/{nodename}/backups'] = {
'owner': config['user'],
'mode': '0700',
'needs': {
'bundle:zfs',
},
}

View file

@ -0,0 +1,45 @@
@metadata_reactor
def get_my_clients(metadata):
my_clients = {}
for rnode in repo.nodes:
if rnode.metadata.get('backups/exclude_from_backups', False):
continue
my_clients[rnode.name] = {
'user': rnode.metadata.get('backup-client/user-name'),
}
return {
'backup-server': {
'clients': my_clients,
},
}
@metadata_reactor
def zfs(metadata):
zfs_datasets = {}
zfs_retains = {}
retain_defaults = {
'weekly': 4,
'monthly': 6,
}
for client in metadata.get('backup-server/clients', {}).keys():
dataset = '{}/{}'.format(metadata.get('backup-server/zfs-base'), client)
zfs_datasets[dataset] = {
'mountpoint': '/srv/backups/{}'.format(client),
}
zfs_retains[dataset] = retain_defaults.copy()
return {
'zfs': {
'datasets': zfs_datasets,
'snapshots': {
'retain_per_dataset': zfs_retains,
},
},
}