refactor(hosts): organize repository by server profiles (hosts/raspberrypi5, hosts/llm-node) and add host-aware installer

This commit is contained in:
Lars committed 2026-10-29 14:27:49 +01:00
1 parent c53fc0a939
commit c2740c9542
44 files changed
+528 -40

No files matched your search

+52 -12
View File
@@ -66,8 +66,15 @@ def lock_exclusive(fp):
fcntl.flock(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
def load_host_config(path=DEFAULT_HOST_CONFIG):
def resolve_repo_host_dir(host_name=None):
host = host_name or socket.gethostname().split('.')[0]
candidate = Path(__file__).resolve().parent / 'hosts' / host
return candidate if candidate.is_dir() else None
def load_host_config(path=DEFAULT_HOST_CONFIG, host_name=None):
default = {
'hostname': host_name or socket.gethostname(),
'nas_mount': NAS_MOUNT,
'nas_source': NAS_SOURCE,
'nas_fstype': 'nfs4',
@@ -77,16 +84,37 @@ def load_host_config(path=DEFAULT_HOST_CONFIG):
'conflict_timers': ['paperless-data-backup.timer', 'borgmatic.timer'],
'cron_users': ['root', 'lars'],
}
if path and Path(path).is_file():
with Path(path).open(encoding='utf-8') as fp:
data = json.load(fp)
if isinstance(data, dict):
default.update(data)
candidates = []
if host_name:
host_dir = resolve_repo_host_dir(host_name)
if host_dir:
candidates.append(host_dir / 'host.json')
if path:
candidates.append(Path(path))
host_dir = resolve_repo_host_dir()
if host_dir:
candidates.append(host_dir / 'host.json')
for candidate in candidates:
if candidate.is_file():
with candidate.open(encoding='utf-8') as fp:
data = json.load(fp)
if isinstance(data, dict):
default.update(data)
break
return default
def load_targets_config(path=DEFAULT_TARGETS_CONFIG):
candidates = [Path(path)] if path else []
def load_targets_config(path=DEFAULT_TARGETS_CONFIG, host_name=None):
candidates = []
if host_name:
host_dir = resolve_repo_host_dir(host_name)
if host_dir:
candidates.append(host_dir / 'targets.json')
if path:
candidates.append(Path(path))
host_dir = resolve_repo_host_dir()
if host_dir:
candidates.append(host_dir / 'targets.json')
candidates.append(Path(__file__).resolve().parent / 'targets.json')
for candidate in candidates:
if candidate.is_file():
@@ -1396,6 +1424,7 @@ def main():
mode.add_argument('--restore-test', action='store_true', help='Execute isolated disposable restore test')
parser.add_argument('--json', action='store_true', help='Machine-readable JSON output')
parser.add_argument('--host', type=str, default=None, help='Select server profile from hosts/<host> (e.g. raspberrypi5, llm-node)')
parser.add_argument('--config', type=Path, default=DEFAULT_CONFIG)
parser.add_argument('--notify-config', type=Path, default=DEFAULT_NOTIFY_CONFIG)
parser.add_argument('--targets-config', type=Path, default=DEFAULT_TARGETS_CONFIG)
@@ -1419,6 +1448,17 @@ def main():
parser.add_argument('--keep', action='store_true', help='Keep isolated test environment running after --restore-test')
args = parser.parse_args()
if args.host:
host_dir = resolve_repo_host_dir(args.host)
if not host_dir:
parser.error(f'Unknown host profile: {args.host!r}')
if args.config == DEFAULT_CONFIG:
args.config = host_dir / 'jobs.csv'
if args.notify_config == DEFAULT_NOTIFY_CONFIG and (host_dir / 'notifications.json.example').is_file():
args.notify_config = host_dir / 'notifications.json.example'
if args.targets_config == DEFAULT_TARGETS_CONFIG and (host_dir / 'targets.json').is_file():
args.targets_config = host_dir / 'targets.json'
if not 1 <= args.max_parallel <= 16:
parser.error('--max-parallel must be 1..16')
json_capable = (
@@ -1434,7 +1474,7 @@ def main():
return show_status(args.log_root, as_json=args.json)
if args.list_recovery_points:
host_cfg = load_host_config()
host_cfg = load_host_config(host_name=args.host)
search_dirs = args.search_dirs or [
host_cfg['archive_sets_dir'],
host_cfg['local_dump_dir'],
@@ -1472,7 +1512,7 @@ def main():
if args.recovery_plan:
if not args.point or not args.target:
parser.error('--point and --target are required with --recovery-plan')
targets_cfg = load_targets_config(args.targets_config)
targets_cfg = load_targets_config(args.targets_config, host_name=args.host)
plan_doc = generate_recovery_plan(args.point, args.target, targets_cfg, sessions_mode=args.sessions)
if args.json:
print(json.dumps(plan_doc, ensure_ascii=False, indent=2))
@@ -1492,11 +1532,11 @@ def main():
return plan_doc['compatibility']['exit_code']
if args.restore:
targets_cfg = load_targets_config(args.targets_config)
targets_cfg = load_targets_config(args.targets_config, host_name=args.host)
return execute_recovery_command('restore', args, targets_cfg)
if args.restore_test:
targets_cfg = load_targets_config(args.targets_config)
targets_cfg = load_targets_config(args.targets_config, host_name=args.host)
return execute_recovery_command('restore-test', args, targets_cfg)
jobs = load_jobs(args.config)