Skip to content

Commit 4f6a4be

Browse files
Update ConfigMap with latest script changes
1 parent f0553f4 commit 4f6a4be

1 file changed

Lines changed: 77 additions & 6 deletions

File tree

qdrant-backup-restore/k8s/configmap-script.yaml

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ data:
8383
fi
8484
_printf "fetching collections!\n"
8585
86-
local host="${source_hosts[0]}"
86+
local host="${source_hosts[0]:-}"
87+
if [[ -z "$host" ]]; then
88+
_printf "source host is not available for fetching collections. Please ensure QDRANT_SOURCE_HOSTS is set correctly in your environment variables.\n"
89+
exit 1
90+
fi
8791
8892
collections_count=0
8993
@@ -141,7 +145,11 @@ data:
141145
142146
# creates and appends created collection snapshot from a qdrant node to $QDRANT_SNAPSHOTS_FILE
143147
track_created_collection_snapshot() {
144-
local host="${source_hosts[0]}"
148+
local host="${source_hosts[0]:-}"
149+
if [[ -z "$host" ]]; then
150+
_printf "source host is not available for fetching collection snapshots. Please ensure QDRANT_SOURCE_HOSTS is set correctly in your environment variables.\n"
151+
exit 1
152+
fi
145153
local collection_name="$1"
146154
local result=""
147155
local status=""
@@ -342,11 +350,61 @@ data:
342350
fi
343351
}
344352
353+
# discovers collection names from the S3 snapshots prefix and stores them in $QDRANT_COLLECTIONS_FILE
354+
fetch_collections_from_s3() {
355+
local prefix="snapshots"
356+
local result=""
357+
358+
_printf "fetching collections from s3 bucket %s under %s/\n" "$QDRANT_S3_BUCKET_NAME" "$prefix"
359+
360+
result=$(mc ls --json "$QDRANT_S3_ALIAS/$QDRANT_S3_BUCKET_NAME/$prefix/")
361+
362+
if [ "$result" = "" ]; then
363+
_printf "no collections found in s3 path: %s/%s/ ...skipping!\n" "$QDRANT_S3_BUCKET_NAME" "$prefix"
364+
return
365+
fi
366+
367+
collections_count=0
368+
_result=$(jq -c '.' <<< "$result")
369+
370+
while read -r item; do
371+
local status=""
372+
local object_key=""
373+
local collection_name=""
374+
375+
status=$(jq -r '.status?' <<< "$item")
376+
if [ "$status" != "success" ]; then
377+
_printf "failed to list collections from s3, got this instead %s\n" "${item//[[:space:]]/}"
378+
continue
379+
fi
380+
381+
object_key=$(jq -r '.key' <<< "$item") # e.g. "my_collection/" from mc ls on snapshots/
382+
object_key="${object_key%/}" # strip trailing slash (folder marker)
383+
collection_name="${object_key##*/}" # use last path segment as collection name
384+
385+
if [[ -z "$collection_name" || "$collection_name" == "$prefix" ]]; then
386+
continue
387+
fi
388+
389+
((collections_count=collections_count+1))
390+
printf ',%s\n' "$collection_name" >> $QDRANT_COLLECTIONS_FILE
391+
done <<< "$_result"
392+
393+
_printf "%s file updated, found %d collection(s) from s3!\n" "$QDRANT_COLLECTIONS_FILE" "$collections_count"
394+
collections_count=0
395+
}
396+
345397
# generates a list of collection snapshots from a s3 and appends it to $QDRANT_SNAPSHOTS_FILE
346398
generate_snapshot_file_from_s3() {
347399
local datetime="${1:-}"
400+
348401
if [[ ! -s "$QDRANT_COLLECTIONS_FILE" ]]; then
349-
get_collections
402+
fetch_collections_from_s3
403+
fi
404+
405+
if [ ! -f "$QDRANT_COLLECTIONS_FILE" ]; then
406+
_printf "non error exit since file does not %s exist.\n" "$QDRANT_COLLECTIONS_FILE"
407+
exit 0
350408
fi
351409
352410
snapshot_count=0
@@ -496,7 +554,11 @@ data:
496554
497555
# gets the collection aliases from a qdrant node and appends it to $QDRANT_COLLECTION_ALIASES file
498556
get_collection_aliases() {
499-
local host="${source_hosts[0]}"
557+
local host="${source_hosts[0]:-}"
558+
if [[ -z "$host" ]]; then
559+
_printf "source host is not available for fetching collection aliases. Please ensure QDRANT_SOURCE_HOSTS is set correctly in your environment variables.\n"
560+
exit 1
561+
fi
500562
local result=""
501563
local status=""
502564
@@ -597,7 +659,11 @@ data:
597659
# restores collection aliases to a qdrant node and appends progress to $QDRANT_ALIAS_RECOVERY_HISTORY_FILE
598660
recover_collection_aliases() {
599661
600-
local host="${restore_hosts[0]}"
662+
local host="${restore_hosts[0]:-}"
663+
if [[ -z "$host" ]]; then
664+
_printf "restore host is not available for recovering collection aliases. Please ensure QDRANT_RESTORE_HOSTS is set correctly in your environment variables.\n"
665+
exit 1
666+
fi
601667
602668
603669
if [ "$BACKUP_COLLECTION_ALIASES_ON_S3" = "true" ]; then
@@ -667,7 +733,12 @@ data:
667733
668734
# gets qdrant peer host url using cluster info endpoint. Sets the port to $QDRANT_HTTP_PORT the http port.
669735
get_peers_from_cluster_info() {
670-
local host="${source_hosts[0]}"
736+
local host="${source_hosts[0]:-}"
737+
if [[ -z "$host" ]]; then
738+
_printf "source host is not available. Please ensure QDRANT_SOURCE_HOSTS is set correctly in your environment variables. If restoring snapshots set QDRANT_SOURCE_HOSTS and GET_PEERS_FROM_CLUSTER_INFO to empty string.\n"
739+
exit 1
740+
fi
741+
671742
result=$(_curl GET "$host/cluster" --header "api-key: $QDRANT_API_KEY")
672743
entries=$(jq -r '.result.peers // {}' <<< "$result")
673744
peer_uri_entries=$(jq -r 'to_entries[] | "\(.key) \(.value.uri)"' <<< "$entries")

0 commit comments

Comments
 (0)