50 lines
1.3 KiB
Python
Executable file
50 lines
1.3 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import json
|
|
import subprocess
|
|
import os
|
|
from pathlib import Path
|
|
import backup_manager
|
|
|
|
|
|
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 PaperlessManager(backup_manager.BackupManager):
|
|
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"
|
|
try:
|
|
result = subprocess.run(
|
|
cmd, shell=True, text=True, check=True, capture_output=True
|
|
)
|
|
except subprocess.CalledProcessError as e:
|
|
self._gotify.send_subprocess_error("Exporting data failed", e)
|
|
return False
|
|
self._gotify.send_success("Data exported.", result)
|
|
return True
|
|
|
|
|
|
def main():
|
|
config = read_config()
|
|
try:
|
|
os.chdir(config["common"]["BACKUP_DOCKER_DIR"])
|
|
except KeyError:
|
|
pass
|
|
backup_manager = PaperlessManager(config)
|
|
if not backup_manager.export_data():
|
|
exit(1)
|
|
if not backup_manager.borg_backup():
|
|
exit(1)
|
|
exit(0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|