Skip to content

Commit 8b897ba

Browse files
authored
Fix bug when uploading backup to a mount (#5585)
1 parent c8f1b22 commit 8b897ba

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

supervisor/backups/manager.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ async def reload(
233233
) -> bool:
234234
"""Load exists backups."""
235235

236-
async def _load_backup(location: str | None, tar_file: Path) -> bool:
236+
async def _load_backup(location_name: str | None, tar_file: Path) -> bool:
237237
"""Load the backup."""
238-
backup = Backup(self.coresys, tar_file, "temp", location)
238+
backup = Backup(self.coresys, tar_file, "temp", location_name)
239239
if await backup.load():
240240
if backup.slug in self._backups:
241241
try:
@@ -251,7 +251,7 @@ async def _load_backup(location: str | None, tar_file: Path) -> bool:
251251

252252
else:
253253
self._backups[backup.slug] = Backup(
254-
self.coresys, tar_file, backup.slug, location, backup.data
254+
self.coresys, tar_file, backup.slug, location_name, backup.data
255255
)
256256
return True
257257

@@ -392,7 +392,13 @@ async def import_backup(
392392
return None
393393

394394
# Load new backup
395-
backup = Backup(self.coresys, tar_file, backup.slug, location, backup.data)
395+
backup = Backup(
396+
self.coresys,
397+
tar_file,
398+
backup.slug,
399+
self._get_location_name(location),
400+
backup.data,
401+
)
396402
if not await backup.load():
397403
# Remove invalid backup from location it was moved to
398404
backup.tarfile.unlink()

tests/api/test_backups.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,3 +1054,40 @@ async def test_protected_backup(
10541054
"size_bytes": 10240,
10551055
}
10561056
}
1057+
1058+
1059+
@pytest.mark.usefixtures(
1060+
"path_extern", "mount_propagation", "mock_is_mount", "tmp_supervisor_data"
1061+
)
1062+
async def test_upload_to_mount(api_client: TestClient, coresys: CoreSys):
1063+
"""Test uploading a backup to a specific mount."""
1064+
await coresys.mounts.load()
1065+
(coresys.config.path_mounts / "backup_test").mkdir()
1066+
mount = Mount.from_dict(
1067+
coresys,
1068+
{
1069+
"name": "backup_test",
1070+
"type": "cifs",
1071+
"usage": "backup",
1072+
"server": "backup.local",
1073+
"share": "backups",
1074+
},
1075+
)
1076+
await coresys.mounts.create_mount(mount)
1077+
1078+
# Capture our backup initially
1079+
backup_file = get_fixture_path("backup_example.tar")
1080+
backup = Backup(coresys, backup_file, "in", None)
1081+
await backup.load()
1082+
1083+
# Upload it and confirm it matches what we had
1084+
with backup_file.open("rb") as file, MultipartWriter("form-data") as mp:
1085+
mp.append(file)
1086+
resp = await api_client.post(
1087+
"/backups/new/upload?location=backup_test", data=mp
1088+
)
1089+
1090+
assert resp.status == 200
1091+
body = await resp.json()
1092+
assert body["data"]["slug"] == "7fed74c8"
1093+
assert backup == coresys.backups.get("7fed74c8")

0 commit comments

Comments
 (0)