Fix bug when uploading backup to a mount (#5585)

This commit is contained in:
Mike Degatano 2025-01-28 12:30:37 -05:00 committed by GitHub
parent c8f1b222c0
commit 8b897ba537
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 4 deletions

View File

@ -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()

View File

@ -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")