diff --git a/supervisor/backups/manager.py b/supervisor/backups/manager.py index 76d47780e..fd95bcd05 100644 --- a/supervisor/backups/manager.py +++ b/supervisor/backups/manager.py @@ -233,9 +233,9 @@ class BackupManager(FileConfiguration, JobGroup): ) -> bool: """Load exists backups.""" - async def _load_backup(location: str | None, tar_file: Path) -> bool: + async def _load_backup(location_name: str | None, tar_file: Path) -> bool: """Load the backup.""" - backup = Backup(self.coresys, tar_file, "temp", location) + backup = Backup(self.coresys, tar_file, "temp", location_name) if await backup.load(): if backup.slug in self._backups: try: @@ -251,7 +251,7 @@ class BackupManager(FileConfiguration, JobGroup): else: self._backups[backup.slug] = Backup( - self.coresys, tar_file, backup.slug, location, backup.data + self.coresys, tar_file, backup.slug, location_name, backup.data ) return True @@ -392,7 +392,13 @@ class BackupManager(FileConfiguration, JobGroup): return None # Load new backup - backup = Backup(self.coresys, tar_file, backup.slug, location, backup.data) + backup = Backup( + self.coresys, + tar_file, + backup.slug, + self._get_location_name(location), + backup.data, + ) if not await backup.load(): # Remove invalid backup from location it was moved to backup.tarfile.unlink() diff --git a/tests/api/test_backups.py b/tests/api/test_backups.py index 647c8e435..24aaa0bd5 100644 --- a/tests/api/test_backups.py +++ b/tests/api/test_backups.py @@ -1054,3 +1054,40 @@ async def test_protected_backup( "size_bytes": 10240, } } + + +@pytest.mark.usefixtures( + "path_extern", "mount_propagation", "mock_is_mount", "tmp_supervisor_data" +) +async def test_upload_to_mount(api_client: TestClient, coresys: CoreSys): + """Test uploading a backup to a specific mount.""" + await coresys.mounts.load() + (coresys.config.path_mounts / "backup_test").mkdir() + mount = Mount.from_dict( + coresys, + { + "name": "backup_test", + "type": "cifs", + "usage": "backup", + "server": "backup.local", + "share": "backups", + }, + ) + await coresys.mounts.create_mount(mount) + + # Capture our backup initially + backup_file = get_fixture_path("backup_example.tar") + backup = Backup(coresys, backup_file, "in", None) + await backup.load() + + # Upload it and confirm it matches what we had + with backup_file.open("rb") as file, MultipartWriter("form-data") as mp: + mp.append(file) + resp = await api_client.post( + "/backups/new/upload?location=backup_test", data=mp + ) + + assert resp.status == 200 + body = await resp.json() + assert body["data"]["slug"] == "7fed74c8" + assert backup == coresys.backups.get("7fed74c8")