Skip to content

Commit 1f89311

Browse files
authored
Fix backup consolidate and upload duplicate (#5472)
1 parent 9008009 commit 1f89311

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

supervisor/backups/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ async def import_backup(
359359
return None
360360

361361
# Load new backup
362-
backup = Backup(self.coresys, tar_origin, backup.slug, None, backup.data)
362+
backup = Backup(self.coresys, tar_origin, backup.slug, location, backup.data)
363363
if not await backup.load():
364364
# Remove invalid backup from location it was moved to
365365
backup.tarfile.unlink()
@@ -369,7 +369,7 @@ async def import_backup(
369369
# Already exists?
370370
if (
371371
backup.slug in self._backups
372-
and backup.all_locations != self._backups[backup].all_locations
372+
and backup.all_locations != self._backups[backup.slug].all_locations
373373
):
374374
_LOGGER.warning("Backup %s already exists! consolidating", backup.slug)
375375
try:

tests/api/test_backups.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,34 @@ async def test_upload_to_multiple_locations(
698698
".cloud_backup": copy_backup,
699699
}
700700
assert coresys.backups.get("7fed74c8").location is None
701+
702+
703+
async def test_upload_duplicate_backup_new_location(
704+
api_client: TestClient,
705+
coresys: CoreSys,
706+
tmp_supervisor_data: Path,
707+
):
708+
"""Test uploading a backup that already exists to a new location."""
709+
backup_file = get_fixture_path("backup_example.tar")
710+
orig_backup = Path(copy(backup_file, coresys.config.path_backup))
711+
await coresys.backups.reload(None, "backup_example.tar")
712+
assert coresys.backups.get("7fed74c8").all_locations == {None: orig_backup}
713+
714+
with backup_file.open("rb") as file, MultipartWriter("form-data") as mp:
715+
mp.append(file)
716+
resp = await api_client.post(
717+
"/backups/new/upload?location=.cloud_backup", data=mp
718+
)
719+
720+
assert resp.status == 200
721+
body = await resp.json()
722+
assert body["data"]["slug"] == "7fed74c8"
723+
724+
copy_backup = coresys.config.path_core_backup / "7fed74c8.tar"
725+
assert orig_backup.exists()
726+
assert copy_backup.exists()
727+
assert coresys.backups.get("7fed74c8").all_locations == {
728+
None: orig_backup,
729+
".cloud_backup": copy_backup,
730+
}
731+
assert coresys.backups.get("7fed74c8").location is None

0 commit comments

Comments
 (0)