mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-15 09:51:21 +00:00
backups: Unmount repositories before and after backup
[sunil: Make the umount code specific to SSH repositories] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
d7a1ea03a3
commit
957ddf5a2d
@ -133,6 +133,10 @@ class BaseBorgRepository(abc.ABC):
|
||||
def prepare():
|
||||
"""Prepare the repository for operations."""
|
||||
|
||||
@staticmethod
|
||||
def cleanup():
|
||||
"""Cleanup the repository after operations."""
|
||||
|
||||
def get_info(self):
|
||||
"""Return Borg information about a repository."""
|
||||
output = self.run(['info', '--path', self.borg_path])
|
||||
@ -393,8 +397,13 @@ class SshBorgRepository(BaseBorgRepository):
|
||||
if not self.is_usable():
|
||||
raise errors.SshfsError('Remote host not verified')
|
||||
|
||||
self._umount_ignore_errors() # In case the connection is stale.
|
||||
self.mount()
|
||||
|
||||
def cleanup(self):
|
||||
"""Cleanup the repository after operations by unmounting."""
|
||||
self._umount_ignore_errors()
|
||||
|
||||
@property
|
||||
def hostname(self):
|
||||
"""Return hostname from the remote path."""
|
||||
@ -440,6 +449,13 @@ class SshBorgRepository(BaseBorgRepository):
|
||||
|
||||
self._run('sshfs', ['umount', '--mountpoint', self._mountpoint])
|
||||
|
||||
def _umount_ignore_errors(self):
|
||||
"""Run unmount operation and ignore any exceptions thrown."""
|
||||
try:
|
||||
self.umount()
|
||||
except Exception as exception:
|
||||
logger.warning('Unable to unmount repository', exc_info=exception)
|
||||
|
||||
def remove(self):
|
||||
"""Remove a repository from the kvstore and delete its mountpoint"""
|
||||
self.umount()
|
||||
|
||||
@ -321,3 +321,5 @@ class Schedule:
|
||||
logger.info('Cleaning up in repository %s backup archive %s',
|
||||
self.repository_uuid, archive['name'])
|
||||
repository.delete_archive(archive['name'])
|
||||
|
||||
repository.cleanup()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user