Skip to content

Commit

Permalink
Merge pull request #1494 from weaviate/dynamic_backup
Browse files Browse the repository at this point in the history
Add support for dynamic backup path
  • Loading branch information
dirkkul authored Jan 10, 2025
2 parents 4ca9edd + aeb6557 commit 18838b1
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 45 deletions.
68 changes: 57 additions & 11 deletions integration/test_backup_v4.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import datetime
import pathlib
import time
from typing import Generator, List, Union
from typing import Generator, List, Union, Optional

import pytest

import weaviate
import weaviate.classes as wvc
from weaviate.backup.backup import (
BackupCompressionLevel,
BackupConfigCreate,
Expand Down Expand Up @@ -346,33 +348,59 @@ def test_fail_creating_backup_for_both_include_and_exclude_classes(
)


def test_backup_and_restore_with_collection(client: weaviate.WeaviateClient) -> None:
@pytest.mark.parametrize("dynamic_backup_location", [False, True])
def test_backup_and_restore_with_collection(
client: weaviate.WeaviateClient, dynamic_backup_location: bool, tmp_path: pathlib.Path
) -> None:
backup_id = _create_backup_id()

conf_create: Optional[wvc.backup.BackupConfigCreate] = None
conf_restore: Optional[wvc.backup.BackupConfigRestore] = None
backup_location: Optional[wvc.backup.BackupLocation] = None
if dynamic_backup_location:
if client._connection._weaviate_version.is_lower_than(1, 27, 2):
pytest.skip("Cancel backups is only supported from 1.27.2")

backup_location = wvc.backup.BackupLocation.FileSystem(path=str(tmp_path))

article = client.collections.get("Article")

# create backup
create = article.backup.create(backup_id=backup_id, backend=BACKEND, wait_for_completion=True)
create = article.backup.create(
backup_id=backup_id,
backend=BACKEND,
wait_for_completion=True,
config=conf_create,
backup_location=backup_location,
)
assert create.status == BackupStatus.SUCCESS

assert len(article) == len(ARTICLES_IDS)

# check create status
create_status = article.backup.get_create_status(backup_id, BACKEND)
create_status = article.backup.get_create_status(
backup_id=backup_id, backend=BACKEND, backup_location=backup_location
)
assert create_status.status == BackupStatus.SUCCESS

# remove existing class
client.collections.delete("Article")

# restore backup
restore = article.backup.restore(backup_id=backup_id, backend=BACKEND, wait_for_completion=True)
restore = article.backup.restore(
backup_id=backup_id,
backend=BACKEND,
wait_for_completion=True,
config=conf_restore,
backup_location=backup_location,
)
assert restore.status == BackupStatus.SUCCESS

# # check data exists again
assert len(article) == len(ARTICLES_IDS)

# check restore status
restore_status = article.backup.get_restore_status(backup_id, BACKEND)
restore_status = article.backup.get_restore_status(backup_id, BACKEND, backup_location)
assert restore_status.status == BackupStatus.SUCCESS


Expand Down Expand Up @@ -468,24 +496,42 @@ def test_backup_and_restore_with_collection_and_config_1_23_x(
# assert backup_id in [b.backup_id for b in backups]


def test_cancel_backup(client: weaviate.WeaviateClient) -> None:
@pytest.mark.parametrize("dynamic_backup_location", [False, True])
def test_cancel_backup(
client: weaviate.WeaviateClient, dynamic_backup_location, tmp_path: pathlib.Path
) -> None:
"""Create and restore backup without waiting."""
backup_id = _create_backup_id()
if client._connection._weaviate_version.is_lower_than(1, 24, 25):
pytest.skip("Cancel backups is only supported from 1.24.25")

resp = client.backup.create(backup_id=backup_id, backend=BACKEND)
backup_location: Optional[wvc.backup.BackupLocation] = None
if dynamic_backup_location:
if client._connection._weaviate_version.is_lower_than(1, 27, 2):
pytest.skip("Cancel backups is only supported from 1.27.2")

backup_location = wvc.backup.BackupLocation.FileSystem(path=str(tmp_path))

resp = client.backup.create(
backup_id=backup_id, backend=BACKEND, backup_location=backup_location
)
assert resp.status == BackupStatus.STARTED

assert client.backup.cancel(backup_id=backup_id, backend=BACKEND)
assert client.backup.cancel(
backup_id=backup_id, backend=BACKEND, backup_location=backup_location
)

# async process
start = time.time()
while time.time() - start < 5:
status_resp = client.backup.get_create_status(backup_id=backup_id, backend=BACKEND)
status_resp = client.backup.get_create_status(
backup_id=backup_id, backend=BACKEND, backup_location=backup_location
)
if status_resp.status == BackupStatus.CANCELED:
break
time.sleep(0.1)
status_resp = client.backup.get_create_status(backup_id=backup_id, backend=BACKEND)
status_resp = client.backup.get_create_status(
backup_id=backup_id, backend=BACKEND, backup_location=backup_location
)
# there can be a race between the cancel and the backup completion
assert status_resp.status == BackupStatus.CANCELED or status_resp.status == BackupStatus.SUCCESS
Loading

0 comments on commit 18838b1

Please sign in to comment.