diff --git a/backup_manager.py b/backup_manager.py index 22ab0fc..24c2a3b 100644 --- a/backup_manager.py +++ b/backup_manager.py @@ -1,21 +1,11 @@ import gotify -import json import subprocess import os -from pathlib import Path - - -def read_config(): - source_path = Path(__file__).resolve() - secrets = source_path.parent / "secrets/paperless.json" - with open(secrets, "r") as f: - config = json.load(f) - return config class BackupManager: - def __init__(self): - self._config = read_config() + def __init__(self, config): + self._config = config self._remotes = self._config["remotes"] self._common = self._config["common"] self._gotify = gotify.Gotify(self._common["GOTIFY_TOKEN"]) @@ -41,7 +31,9 @@ class BackupManager: borg_env["BORG_RSH"] = remote["BORG_RSH"] borg_env["BORG_PASSPHRASE"] = remote["BORG_PASSPHRASE"] repo = f"ssh://{backup_user}@{remote_host}/{repo_prefix}/{local_host}/{repo_subdir}::{{{time_format}}}" - cmd = f"borg create -v --stats {repo} {backup_dirs} --exclude {exclude_dirs}" + cmd = ( + f"borg create -v --stats {repo} {backup_dirs} --exclude {exclude_dirs}" + ) try: result = subprocess.run( cmd, diff --git a/nextcloud_backup b/nextcloud_backup index 9e41e2e..be24fd8 100755 --- a/nextcloud_backup +++ b/nextcloud_backup @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import gotify import json import subprocess import os @@ -17,8 +16,8 @@ def read_config(): class NextcloudManager(backup_manager.BackupManager): - def __init__(self): - super().__init__() + def __init__(self, config): + super().__init__(config=config) def enable_maintenance(self): cmd = "docker compose exec -i --user 1000:1000 app /var/www/html/occ maintenance:mode --on" @@ -82,7 +81,7 @@ class NextcloudManager(backup_manager.BackupManager): def main(): config = read_config() os.chdir(config["common"]["BACKUP_DOCKER_DIR"]) - backup_manager = NextcloudManager() + backup_manager = NextcloudManager(config) if not backup_manager.enable_maintenance(): backup_manager.disable_maintenance() exit(1) diff --git a/paperless-ngx_backup b/paperless-ngx_backup index a227b01..c681558 100755 --- a/paperless-ngx_backup +++ b/paperless-ngx_backup @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import gotify import json import subprocess import os @@ -17,8 +16,8 @@ def read_config(): class PaperlessManager(backup_manager.BackupManager): - def __init__(self): - super().__init__() + def __init__(self, config): + super().__init__(config=config) def export_data(self): cmd = "docker compose exec -it webserver document_exporter ../export -d -f --no-progress-bar" @@ -39,7 +38,7 @@ def main(): os.chdir(config["common"]["BACKUP_DOCKER_DIR"]) except KeyError: pass - backup_manager = PaperlessManager() + backup_manager = PaperlessManager(config) if not backup_manager.export_data(): exit(1) if not backup_manager.borg_backup():