diff --git a/supervisor/api/backups.py b/supervisor/api/backups.py index 7399abe13..b4334ee09 100644 --- a/supervisor/api/backups.py +++ b/supervisor/api/backups.py @@ -100,6 +100,7 @@ class APIBackups(CoreSysAttributes): ATTR_DATE: backup.date, ATTR_TYPE: backup.sys_type, ATTR_SIZE: backup.size, + ATTR_LOCATON: backup.location, ATTR_PROTECTED: backup.protected, ATTR_COMPRESSED: backup.compressed, ATTR_CONTENT: { @@ -172,6 +173,7 @@ class APIBackups(CoreSysAttributes): ATTR_PROTECTED: backup.protected, ATTR_SUPERVISOR_VERSION: backup.supervisor_version, ATTR_HOMEASSISTANT: backup.homeassistant_version, + ATTR_LOCATON: backup.location, ATTR_ADDONS: data_addons, ATTR_REPOSITORIES: backup.repositories, ATTR_FOLDERS: backup.folders, diff --git a/supervisor/backups/backup.py b/supervisor/backups/backup.py index 044cc78c2..369110c05 100644 --- a/supervisor/backups/backup.py +++ b/supervisor/backups/backup.py @@ -2,6 +2,7 @@ from base64 import b64decode, b64encode from collections.abc import Awaitable from datetime import timedelta +from functools import cached_property import json import logging from pathlib import Path @@ -150,6 +151,14 @@ class Backup(CoreSysAttributes): """Set the Docker config data.""" self._data[ATTR_DOCKER] = value + @cached_property + def location(self) -> str | None: + """Return the location of the backup.""" + for backup_mount in self.sys_mounts.backup_mounts: + if self.tarfile.is_relative_to(backup_mount.local_where): + return backup_mount.name + return None + @property def size(self): """Return backup size.""" diff --git a/tests/api/test_backups.py b/tests/api/test_backups.py index c3e3a1770..2a57f913c 100644 --- a/tests/api/test_backups.py +++ b/tests/api/test_backups.py @@ -95,6 +95,11 @@ async def test_backup_to_location( assert (tmp_supervisor_data / backup_dir / f"{slug}.tar").exists() + resp = await api_client.get(f"/backups/{slug}/info") + result = await resp.json() + assert result["result"] == "ok" + assert result["data"]["location"] == location + async def test_backup_to_default( api_client: TestClient,