backups: repository: Introduce a prepare method

Useful for abstracting the mount() operation that is not available on non-remote
repositories.

- On non-remote repositories do nothing.

- On remote repositories, mount the location in preparation for operations on
the repository.

Tests performed:

- When an SSH repository is unmounted before a schedule backup, it is
automatically mounted for listing, backup and cleanup at scheduled time.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-01-15 15:42:02 -08:00 committed by James Valleroy
parent 3789048854
commit 1170e438a3
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -126,6 +126,10 @@ class BaseBorgRepository(abc.ABC):
"""Return the repository that the backups action script should use."""
return self._path
@staticmethod
def prepare():
"""Prepare the repository for operations."""
def get_info(self):
"""Return Borg information about a repository."""
output = self.run(['info', '--path', self.borg_path])
@ -373,6 +377,13 @@ class SshBorgRepository(BaseBorgRepository):
"""
return self._mountpoint
def prepare(self):
"""Prepare the repository for operations by mounting."""
if not self.is_usable():
raise errors.SshfsError('Remote host not verified')
self.mount()
@property
def hostname(self):
"""Return hostname from the remote path."""