[fix] Add remote repo

This commit is contained in:
ljf 2022-10-16 19:20:50 +02:00
parent c73a677d20
commit ac0b4c4302
No known key found for this signature in database
2 changed files with 25 additions and 3 deletions

View file

@ -45,11 +45,15 @@ class BorgBackupRepository(LocalBackupRepository):
if self.domain: if self.domain:
# TODO Use the best/good key # 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 # Don't check ssh fingerprint strictly the first time
# TODO improve this by publishing and checking this with DNS # 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'] = "ssh -i %s -oStrictHostKeyChecking=%s"
env['BORG_RSH'] = env['BORG_RSH'] % (private_key, strict) 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"]: if "quota" in self.future_values and self.future_values["quota"]:
cmd += ['--storage-quota', self.quota] cmd += ['--storage-quota', self.quota]
logger.debug(cmd)
try: try:
self._call('init', cmd) self._call('init', cmd)
except YunohostError as e: except YunohostError as e:
@ -260,6 +266,7 @@ class BorgBackupArchive(BackupArchive):
return HTTPResponse(reader, 200) return HTTPResponse(reader, 200)
def extract(self, paths=[], destination=None, exclude_paths=[]): 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) paths, destination, exclude_paths = super().extract(paths, destination, exclude_paths)
cmd = ['borg', 'extract', self.archive_path] + paths cmd = ['borg', 'extract', self.archive_path] + paths
for path in exclude_paths: for path in exclude_paths:

View file

@ -119,7 +119,10 @@ class BackupRepository(ConfigPanel):
self._load_current_values() self._load_current_values()
if self.__class__ == BackupRepository: self._cast_by_backup_method()
def _cast_by_backup_method(self):
try:
if self.method == 'tar': if self.method == 'tar':
from yunohost.repositories.tar import TarBackupRepository from yunohost.repositories.tar import TarBackupRepository
self.__class__ = TarBackupRepository self.__class__ = TarBackupRepository
@ -129,6 +132,8 @@ class BackupRepository(ConfigPanel):
else: else:
from yunohost.repositories.hook import HookBackupRepository from yunohost.repositories.hook import HookBackupRepository
self.__class__ = HookBackupRepository self.__class__ = HookBackupRepository
except KeyError:
pass
# ================================================= # =================================================
# Config Panel Hooks # Config Panel Hooks
@ -150,6 +155,16 @@ class BackupRepository(ConfigPanel):
logger.debug("SHF running") logger.debug("SHF running")
return {'is_shf': True} 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 # Config Panel Override
# ================================================= # =================================================