Backup: change config format to toml
With support of multiple config values
This commit is contained in:
@@ -14,7 +14,7 @@ from dataclasses import dataclass
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
import requests
|
import requests
|
||||||
import configparser
|
import tomllib
|
||||||
|
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
@@ -28,17 +28,38 @@ logging.basicConfig(
|
|||||||
)
|
)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
try:
|
||||||
config.read("/etc/backup/config.ini")
|
with open("/etc/backup/config.toml", "rb") as config_file:
|
||||||
|
config = tomllib.load(config_file)
|
||||||
|
except OSError as e:
|
||||||
|
logger.error(f"Failed to read config file: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
RESTIC_REPOSITORY = config.get("restic", "RESTIC_REPOSITORY")
|
storage_cfg = config.get("storage", {}).get("yandex", {})
|
||||||
RESTIC_PASSWORD = config.get("restic", "RESTIC_PASSWORD")
|
RESTIC_REPOSITORY = storage_cfg.get("restic_repository")
|
||||||
AWS_ACCESS_KEY_ID = config.get("restic", "AWS_ACCESS_KEY_ID")
|
RESTIC_PASSWORD = storage_cfg.get("restic_password")
|
||||||
AWS_SECRET_ACCESS_KEY = config.get("restic", "AWS_SECRET_ACCESS_KEY")
|
AWS_ACCESS_KEY_ID = storage_cfg.get("aws_access_key_id")
|
||||||
AWS_DEFAULT_REGION = config.get("restic", "AWS_DEFAULT_REGION")
|
AWS_SECRET_ACCESS_KEY = storage_cfg.get("aws_secret_access_key")
|
||||||
TELEGRAM_BOT_TOKEN = config.get("telegram", "TELEGRAM_BOT_TOKEN")
|
AWS_DEFAULT_REGION = storage_cfg.get("aws_default_region")
|
||||||
TELEGRAM_CHAT_ID = config.get("telegram", "TELEGRAM_CHAT_ID")
|
|
||||||
NOTIFICATIONS_NAME = config.get("telegram", "NOTIFICATIONS_NAME")
|
notifications_cfg = config.get("notifications", {}).get("telegram", {})
|
||||||
|
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 all(
|
||||||
|
[
|
||||||
|
RESTIC_REPOSITORY,
|
||||||
|
RESTIC_PASSWORD,
|
||||||
|
AWS_ACCESS_KEY_ID,
|
||||||
|
AWS_SECRET_ACCESS_KEY,
|
||||||
|
AWS_DEFAULT_REGION,
|
||||||
|
TELEGRAM_BOT_TOKEN,
|
||||||
|
TELEGRAM_CHAT_ID,
|
||||||
|
NOTIFICATIONS_NAME,
|
||||||
|
]
|
||||||
|
):
|
||||||
|
raise ValueError("Missing required configuration values in config.toml")
|
||||||
|
|
||||||
# File name to store directories and files to back up
|
# File name to store directories and files to back up
|
||||||
BACKUP_TARGETS_FILE = "backup-targets"
|
BACKUP_TARGETS_FILE = "backup-targets"
|
||||||
|
|||||||
17
files/backups/config.template.toml
Normal file
17
files/backups/config.template.toml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
roots = [
|
||||||
|
"{{ application_dir }}"
|
||||||
|
]
|
||||||
|
|
||||||
|
[storage.yandex]
|
||||||
|
type = "restic"
|
||||||
|
restic_repository = "{{ restic_repository }}"
|
||||||
|
restic_password = "{{ restic_password }}"
|
||||||
|
aws_access_key_id = "{{ restic_s3_access_key }}"
|
||||||
|
aws_secret_access_key = "{{ restic_s3_access_secret }}"
|
||||||
|
aws_default_region = "{{ restic_s3_region }}"
|
||||||
|
|
||||||
|
[notifications.telegram]
|
||||||
|
type = "telegram"
|
||||||
|
telegram_bot_token = "{{ notifications_tg_bot_token }}"
|
||||||
|
telegram_chat_id = "{{ notifications_tg_chat_id }}"
|
||||||
|
notifications_name = "{{ notifications_name }}"
|
||||||
Reference in New Issue
Block a user