From ac0b4c43024613ec8e263d54a92e05f47b9e9218 Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 16 Oct 2022 19:20:50 +0200 Subject: [PATCH] [fix] Add remote repo --- src/repositories/borg.py | 11 +++++++++-- src/repository.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/repositories/borg.py b/src/repositories/borg.py index 934010d44..295eeeb16 100644 --- a/src/repositories/borg.py +++ b/src/repositories/borg.py @@ -45,11 +45,15 @@ class BorgBackupRepository(LocalBackupRepository): if self.domain: # TODO Use the best/good key - private_key = "/root/.ssh/ssh_host_ed25519_key" + private_key = "/etc/ssh/ssh_host_ed25519_key" # Don't check ssh fingerprint strictly the first time # TODO improve this by publishing and checking this with DNS - strict = 'yes' if self.domain in open('/root/.ssh/known_hosts').read() else 'no' + # FIXME known_host are hashed now + try: + strict = 'yes' if self.domain in open('/root/.ssh/known_hosts').read() else 'no' + except FileNotFoundError: + strict = 'no' env['BORG_RSH'] = "ssh -i %s -oStrictHostKeyChecking=%s" env['BORG_RSH'] = env['BORG_RSH'] % (private_key, strict) @@ -121,6 +125,8 @@ class BorgBackupRepository(LocalBackupRepository): if "quota" in self.future_values and self.future_values["quota"]: cmd += ['--storage-quota', self.quota] + + logger.debug(cmd) try: self._call('init', cmd) except YunohostError as e: @@ -260,6 +266,7 @@ class BorgBackupArchive(BackupArchive): return HTTPResponse(reader, 200) def extract(self, paths=[], destination=None, exclude_paths=[]): + # TODO exclude_paths not available in actions map paths, destination, exclude_paths = super().extract(paths, destination, exclude_paths) cmd = ['borg', 'extract', self.archive_path] + paths for path in exclude_paths: diff --git a/src/repository.py b/src/repository.py index f7ee845e3..a28ddf5e0 100644 --- a/src/repository.py +++ b/src/repository.py @@ -119,7 +119,10 @@ class BackupRepository(ConfigPanel): self._load_current_values() - if self.__class__ == BackupRepository: + self._cast_by_backup_method() + + def _cast_by_backup_method(self): + try: if self.method == 'tar': from yunohost.repositories.tar import TarBackupRepository self.__class__ = TarBackupRepository @@ -129,6 +132,8 @@ class BackupRepository(ConfigPanel): else: from yunohost.repositories.hook import HookBackupRepository self.__class__ = HookBackupRepository + except KeyError: + pass # ================================================= # Config Panel Hooks @@ -150,6 +155,16 @@ class BackupRepository(ConfigPanel): logger.debug("SHF running") return {'is_shf': True} + def post_ask__is_remote(self, question): + if question.value: + self.method = 'borg' + self._cast_by_backup_method() + return {} + + def post_ask__method(self, question): + self._cast_by_backup_method() + return {} + # ================================================= # Config Panel Override # =================================================