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