2020-11-13 12:36:52 +01:00
|
|
|
from os.path import join
|
|
|
|
|
2021-05-15 20:32:23 +02: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 18:12:25 +01:00
|
|
|
if node.metadata.get('backups/exclude_from_backups', False):
|
2022-01-07 08:29:34 +01:00
|
|
|
# make sure nobody tries to do something funny
|
2023-04-01 06:58:48 +02:00
|
|
|
for file in {
|
2022-01-07 08:29:34 +01:00
|
|
|
'/etc/backup.priv',
|
|
|
|
'/usr/local/bin/generate-backup',
|
|
|
|
'/usr/local/bin/generate-backup-with-retries',
|
|
|
|
'/var/tmp/backup.monitoring', # status file
|
2023-04-01 06:58:48 +02:00
|
|
|
}:
|
2022-01-07 08:29:34 +01:00
|
|
|
files[file] = {
|
|
|
|
'delete': True,
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:36:52 +01:00
|
|
|
else:
|
2022-01-04 17:14:55 +01:00
|
|
|
backup_target = repo.get_node(node.metadata.get('backup-client/target'))
|
2020-11-14 12:49:57 +01:00
|
|
|
|
2022-01-07 08:29:34 +01:00
|
|
|
files['/etc/backup.priv'] = {
|
2023-03-31 21:41:12 +02:00
|
|
|
'content': repo.libs.ssh.generate_ed25519_private_key(
|
|
|
|
node.metadata.get('backup-client/user-name'),
|
|
|
|
backup_target,
|
|
|
|
),
|
2022-01-07 08:29:34 +01:00
|
|
|
'mode': '0400',
|
|
|
|
}
|
|
|
|
|
2021-02-07 20:47:22 +01:00
|
|
|
files['/usr/local/bin/generate-backup'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
2023-03-31 21:41:12 +02:00
|
|
|
'username': node.metadata.get('backup-client/user-name'),
|
2022-01-04 17:14:55 +01:00
|
|
|
'server': backup_target.metadata.get('backup-server/my_hostname'),
|
|
|
|
'port': backup_target.metadata.get('backup-server/my_ssh_port'),
|
2021-05-15 20:32:23 +02:00
|
|
|
'paths': backup_paths,
|
2020-11-13 12:36:52 +01:00
|
|
|
},
|
2021-02-07 20:47:22 +01:00
|
|
|
'mode': '0700',
|
|
|
|
}
|
2022-01-04 17:14:55 +01:00
|
|
|
|
2022-01-07 08:29:34 +01:00
|
|
|
files['/usr/local/bin/generate-backup-with-retries'] = {
|
|
|
|
'mode': '0700',
|
2020-11-13 12:36:52 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 20:47:22 +01:00
|
|
|
files['/usr/local/share/icinga/plugins/check_backup_last_run'] = {
|
|
|
|
'mode': '0755',
|
|
|
|
}
|
|
|
|
|
2021-06-06 08:05:41 +02:00
|
|
|
files['/etc/logrotate.d/backup-client'] = {
|
2022-01-07 08:29:34 +01:00
|
|
|
'delete': True,
|
2021-06-06 08:05:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-07 20:47:22 +01:00
|
|
|
directories['/etc/backup-pre-hooks.d'] = {
|
|
|
|
'purge': True,
|
|
|
|
}
|
|
|
|
|
2021-02-18 18:12:25 +01:00
|
|
|
for hname, hcontent in node.metadata.get('backup-client/pre-hooks', {}).items():
|
2021-02-13 08:37:49 +01:00
|
|
|
files[f'/etc/backup-pre-hooks.d/50-{hname}'] = {
|
2021-02-13 08:26:46 +01:00
|
|
|
'content': '#!/bin/sh\n\n' + hcontent,
|
2021-02-07 20:47:22 +01:00
|
|
|
'mode': '0700',
|
|
|
|
}
|