Backup: support multiple roots

This commit is contained in:
2025-12-20 17:27:29 +03:00
parent b686e4da4d
commit 2617aa2bd2

View File

@@ -4,7 +4,7 @@ Backup script for all applications
Automatically discovers and runs backup scripts for all users,
then creates restic backups and sends notifications.
"""
import itertools
import os
import sys
import subprocess
@@ -15,6 +15,7 @@ from pathlib import Path
from typing import List, Optional
import requests
import tomllib
from collections.abc import Iterable
# Configure logging
@@ -35,6 +36,8 @@ except OSError as e:
logger.error(f"Failed to read config file: {e}")
raise
ROOTS = config.get("roots") or []
storage_cfg = config.get("storage", {}).get("yandex", {})
RESTIC_REPOSITORY = storage_cfg.get("restic_repository")
RESTIC_PASSWORD = storage_cfg.get("restic_password")
@@ -47,6 +50,9 @@ TELEGRAM_BOT_TOKEN = notifications_cfg.get("telegram_bot_token")
TELEGRAM_CHAT_ID = notifications_cfg.get("telegram_chat_id")
NOTIFICATIONS_NAME = notifications_cfg.get("notifications_name")
if not isinstance(ROOTS, Iterable) or not ROOTS:
raise ValueError("roots must be a non-empty list of paths in config.toml")
if not all(
[
RESTIC_REPOSITORY,
@@ -84,8 +90,7 @@ class BackupManager:
def find_applications(self) -> List[Application]:
"""Get all application directories and their owners."""
applications: List[Application] = []
applications_path = Path("/mnt/applications")
source_dirs = applications_path.iterdir()
source_dirs = itertools.chain(*(Path(root).iterdir() for root in ROOTS))
for app_dir in source_dirs:
if "lost+found" in str(app_dir):