Skip to content

Commit

Permalink
Partial update for backup cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
databyjp committed Oct 9, 2024
1 parent 91c67ef commit 6daf0aa
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 65 deletions.
138 changes: 73 additions & 65 deletions _includes/code/howto/configure.backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,101 @@
# ===== INSTANTIATION-COMMON =====
# ================================

# START CreateBackup # START RestoreBackup # START StatusCreateBackup # START StatusRestoreBackup
# START CreateBackup # START RestoreBackup # START StatusCreateBackup # START StatusRestoreBackup # START CancelBackup
import weaviate

client = weaviate.connect_to_local()

try:
# END CreateBackup # END RestoreBackup # END StatusCreateBackup # END StatusRestoreBackup
# END CreateBackup # END RestoreBackup # END StatusCreateBackup # END StatusRestoreBackup # END CancelBackup

# Create the collections, whether they exist or not
client.collections.delete(["Article", "Publication"])
articles = client.collections.create(name="Article")
publications = client.collections.create(name="Publication")
# Create the collections, whether they exist or not
client.collections.delete(["Article", "Publication"])
articles = client.collections.create(name="Article")
publications = client.collections.create(name="Publication")

articles.data.insert(properties={"title": "Dummy"})
publications.data.insert(properties={"title": "Dummy"})
articles.data.insert(properties={"title": "Dummy"})
publications.data.insert(properties={"title": "Dummy"})

# START CreateBackup
result = client.backup.create(
backup_id="my-very-first-backup",
backend="filesystem",
include_collections=["Article", "Publication"],
wait_for_completion=True,
)
# START CreateBackup
result = client.backup.create(
backup_id="my-very-first-backup",
backend="filesystem",
include_collections=["Article", "Publication"],
wait_for_completion=True,
)

print(result)
# END CreateBackup
print(result)
# END CreateBackup

# Test
assert result.status == "SUCCESS"
# Test
assert result.status == "SUCCESS"

# ==============================================
# ===== Check status while creating backup =====
# ==============================================
# ==============================================
# ===== Check status while creating backup =====
# ==============================================

# START StatusCreateBackup
result = client.backup.get_create_status(
backup_id="my-very-first-backup",
backend="filesystem",
)
# START StatusCreateBackup
result = client.backup.get_create_status(
backup_id="my-very-first-backup",
backend="filesystem",
)

print(result)
# END StatusCreateBackup
print(result)
# END StatusCreateBackup

# Test
assert result.status == "SUCCESS"
# Test
assert result.status == "SUCCESS"

# ==========================
# ===== Restore backup =====
# ==========================
# ==========================
# ===== Restore backup =====
# ==========================

client.collections.delete("Publication")
client.collections.delete("Publication")

# START RestoreBackup
result = client.backup.restore(
backup_id="my-very-first-backup",
backend="filesystem",
exclude_collections="Article",
wait_for_completion=True,
)
# START RestoreBackup
result = client.backup.restore(
backup_id="my-very-first-backup",
backend="filesystem",
exclude_collections="Article",
wait_for_completion=True,
)

print(result)
# END RestoreBackup
print(result)
# END RestoreBackup

# Test
assert result.status == "SUCCESS"
# Test
assert result.status == "SUCCESS"

# ==============================================
# ===== Check status while restoring backup =====
# ==============================================
# ==============================================
# ===== Check status while restoring backup =====
# ==============================================

# START StatusRestoreBackup
result = client.backup.get_restore_status(
backup_id="my-very-first-backup",
backend="filesystem",
)
# START StatusRestoreBackup
result = client.backup.get_restore_status(
backup_id="my-very-first-backup",
backend="filesystem",
)

print(result)
# END StatusRestoreBackup
print(result)
# END StatusRestoreBackup

# Test
assert result.status == "SUCCESS"
# Test
assert result.status == "SUCCESS"

# Clean up
client.collections.delete(["Article", "Publication"])
# Clean up
client.collections.delete(["Article", "Publication"])

# START-ANY
# ==============================================
# ===== Cancel ongoing backup =====
# ==============================================

finally:
client.close()
# END-ANY
# START CancelBackup
result = client.backup.cancel_backup(
backup_id="my-very-first-backup",
backend="filesystem",
)

print(result)
# END CancelBackup

client.close()
23 changes: 23 additions & 0 deletions developers/weaviate/configuration/backups.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,29 @@ The response contains a `"status"` field. If the status is `SUCCESS`, the backup
</TabItem>
</Tabs>

### Cancel Backup

An ongoing backup can be cancelled at any time. The backup process will be stopped, and the backup will be marked as `CANCELLED`.

<Tabs groupId="languages">
<TabItem value="py" label="Python Client v4">
<FilteredTextBlock
text={PyCode}
startMarker="# START CancelBackup"
endMarker="# END CancelBackup"
language="py"
/>
</TabItem>
<TabItem value="js" label="JS/TS Client v3">

```ts
// Coming soon
```

</TabItem>
</Tabs>

This operation is particularly useful if you have started a backup by accident, or if you would like to stop a backup that is taking too long.

### Restore Backup
You can restore any backup to any machine as long as the name and number of nodes between source and target are identical. The backup does not need to be created on the same instance. Once a backup backend is configured, you can restore a backup with a single HTTP request.
Expand Down

0 comments on commit 6daf0aa

Please sign in to comment.