backups: Run compact in cleanup

Tests:

- Enable scheduled backups for root and remote repo. Modify
  schedule.py so that backups and cleanup will run every 2
  minutes. Log shows compact command is run for both
  /var/lib/freedombox/borgbackup and mount location for remote
  repo. No errors shown in log.

Closes: #2380

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2026-10-07 07:24:09 -04:00 committed by Sunil Mohan Adapa
parent b739a1e831
commit 27ff747cf0
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 9 additions and 2 deletions

View File

@ -316,6 +316,12 @@ def delete_archive(path: str, encryption_passphrase: secret_str | None = None):
_run(['borg', 'delete', path], encryption_passphrase)
@privileged
def compact(path: str):
"""Compact segments and free repo disk space."""
_run(['borg', 'compact', path])
def _extract(archive_path, destination, encryption_passphrase, locations=None):
"""Extract archive contents."""
prev_dir = os.getcwd()

View File

@ -81,9 +81,9 @@ class BaseBorgRepository(abc.ABC):
def prepare():
"""Prepare the repository for operations."""
@staticmethod
def cleanup():
def cleanup(self):
"""Cleanup the repository after operations."""
privileged.compact(self.borg_path)
def get_info(self):
"""Return Borg information about a repository."""
@ -317,6 +317,7 @@ class SshBorgRepository(BaseBorgRepository):
def cleanup(self):
"""Cleanup the repository after operations by unmounting."""
super().cleanup()
self._umount_ignore_errors()
@property