diff --git a/plinth/modules/backups/repository.py b/plinth/modules/backups/repository.py index 4ba462adc..25aca4aef 100644 --- a/plinth/modules/backups/repository.py +++ b/plinth/modules/backups/repository.py @@ -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() diff --git a/plinth/modules/backups/schedule.py b/plinth/modules/backups/schedule.py index ee3729719..3a347ef6c 100644 --- a/plinth/modules/backups/schedule.py +++ b/plinth/modules/backups/schedule.py @@ -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()