Skip to content

Commit

Permalink
Fix backup consolidate and upload duplicate (#5472)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 authored Dec 9, 2024
1 parent 9008009 commit 1f89311
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions supervisor/backups/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ async def import_backup(
return None

# Load new backup
backup = Backup(self.coresys, tar_origin, backup.slug, None, backup.data)
backup = Backup(self.coresys, tar_origin, backup.slug, location, backup.data)
if not await backup.load():
# Remove invalid backup from location it was moved to
backup.tarfile.unlink()
Expand All @@ -369,7 +369,7 @@ async def import_backup(
# Already exists?
if (
backup.slug in self._backups
and backup.all_locations != self._backups[backup].all_locations
and backup.all_locations != self._backups[backup.slug].all_locations
):
_LOGGER.warning("Backup %s already exists! consolidating", backup.slug)
try:
Expand Down
31 changes: 31 additions & 0 deletions tests/api/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,34 @@ async def test_upload_to_multiple_locations(
".cloud_backup": copy_backup,
}
assert coresys.backups.get("7fed74c8").location is None


async def test_upload_duplicate_backup_new_location(
api_client: TestClient,
coresys: CoreSys,
tmp_supervisor_data: Path,
):
"""Test uploading a backup that already exists to a new location."""
backup_file = get_fixture_path("backup_example.tar")
orig_backup = Path(copy(backup_file, coresys.config.path_backup))
await coresys.backups.reload(None, "backup_example.tar")
assert coresys.backups.get("7fed74c8").all_locations == {None: orig_backup}

with backup_file.open("rb") as file, MultipartWriter("form-data") as mp:
mp.append(file)
resp = await api_client.post(
"/backups/new/upload?location=.cloud_backup", data=mp
)

assert resp.status == 200
body = await resp.json()
assert body["data"]["slug"] == "7fed74c8"

copy_backup = coresys.config.path_core_backup / "7fed74c8.tar"
assert orig_backup.exists()
assert copy_backup.exists()
assert coresys.backups.get("7fed74c8").all_locations == {
None: orig_backup,
".cloud_backup": copy_backup,
}
assert coresys.backups.get("7fed74c8").location is None

0 comments on commit 1f89311

Please sign in to comment.