Skip to content

WIP: Add options to backup roles and users #1607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev/1.30
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions weaviate/backup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from enum import Enum
from time import sleep
from typing import Optional, Union, List, Tuple, Dict, Any, cast
from typing import Literal, Optional, Union, List, Tuple, Dict, Any, cast

from pydantic import BaseModel, Field

Expand Down Expand Up @@ -288,6 +288,8 @@ async def restore(
backend: BackupStorage,
include_collections: Union[List[str], str, None] = None,
exclude_collections: Union[List[str], str, None] = None,
roles_restore: Optional[Literal["noRestore", "all"]] = None,
user_restore: Optional[Literal["noRestore", "all"]] = None,
wait_for_completion: bool = False,
config: Optional[BackupConfigRestore] = None,
backup_location: Optional[BackupLocationType] = None,
Expand Down Expand Up @@ -345,16 +347,14 @@ async def restore(
"exclude": exclude_collections,
}

configPayload = {}

if config is not None:
if self._connection._weaviate_version.is_lower_than(1, 25, 0):
raise WeaviateUnsupportedFeatureError(
"BackupConfigRestore", str(self._connection._weaviate_version), "1.25.0"
)
if not isinstance(config, BackupConfigRestore):
raise WeaviateInvalidInputError(
f"Expected 'config' to be of type 'BackupConfigRestore', but got {type(config)}."
)
payload["config"] = config._to_dict()
configPayload = config._to_dict()

if backup_location is not None:
if self._connection._weaviate_version.is_lower_than(1, 27, 2):
Expand All @@ -366,7 +366,16 @@ async def restore(

if "config" not in payload:
payload["config"] = {}
payload["config"].update(backup_location._to_dict())
configPayload.update(backup_location._to_dict())

if roles_restore is not None:
configPayload["rolesOptions"] = roles_restore

if user_restore is not None:
configPayload["usersOptions"] = user_restore

if len(configPayload) > 0:
payload["config"] = configPayload

path = f"/backups/{backend.value}/{backup_id}/restore"
response = await self._connection.post(
Expand Down
4 changes: 3 additions & 1 deletion weaviate/backup/sync.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Union, List
from typing import Literal, Optional, Union, List

from weaviate.backup.backup import (
BackupStorage,
Expand Down Expand Up @@ -47,6 +47,8 @@ class _Backup:
wait_for_completion: bool = False,
config: Optional[BackupConfigRestore] = None,
backup_location: Optional[BackupLocationType] = None,
roles_restore: Optional[Literal["noRestore", "all"]] = None,
user_restore: Optional[Literal["noRestore", "all"]] = None,
) -> BackupReturn: ...
def get_restore_status(
self,
Expand Down
14 changes: 12 additions & 2 deletions weaviate/collections/backups/backups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Literal, Optional

from weaviate.backup.backup import (
BackupConfigCreate,
Expand Down Expand Up @@ -71,6 +71,8 @@ async def restore(
self,
backup_id: str,
backend: BackupStorage,
roles_restore: Optional[Literal["noRestore", "all"]] = None,
user_restore: Optional[Literal["noRestore", "all"]] = None,
wait_for_completion: bool = False,
config: Optional[BackupConfigRestore] = None,
backup_location: Optional[BackupLocationType] = None,
Expand Down Expand Up @@ -103,7 +105,15 @@ async def restore(
If the backup failed.
"""
restore = await self._backup.restore(
backup_id, backend, [self._name], None, wait_for_completion, config, backup_location
backup_id,
backend,
[self._name],
None,
roles_restore,
user_restore,
wait_for_completion,
config,
backup_location,
)
return BackupStatusReturn(
error=restore.error, status=restore.status, path=restore.path, id=backup_id
Expand Down
4 changes: 3 additions & 1 deletion weaviate/collections/backups/sync.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Literal, Optional
from weaviate.backup.backup import (
BackupConfigCreate,
BackupConfigRestore,
Expand All @@ -19,6 +19,8 @@ class _CollectionBackup(_CollectionBackupBase):
self,
backup_id: str,
backend: BackupStorage,
roles_restore: Optional[Literal["noRestore", "all"]] = None,
user_restore: Optional[Literal["noRestore", "all"]] = None,
wait_for_completion: bool = False,
config: Optional[BackupConfigRestore] = None,
) -> BackupStatusReturn: ...
Expand Down