|
83 | 83 | fi |
84 | 84 | _printf "fetching collections!\n" |
85 | 85 |
|
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 |
87 | 91 |
|
88 | 92 | collections_count=0 |
89 | 93 |
|
@@ -141,7 +145,11 @@ data: |
141 | 145 |
|
142 | 146 | # creates and appends created collection snapshot from a qdrant node to $QDRANT_SNAPSHOTS_FILE |
143 | 147 | 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 |
145 | 153 | local collection_name="$1" |
146 | 154 | local result="" |
147 | 155 | local status="" |
@@ -342,11 +350,61 @@ data: |
342 | 350 | fi |
343 | 351 | } |
344 | 352 |
|
| 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 | +
|
345 | 397 | # generates a list of collection snapshots from a s3 and appends it to $QDRANT_SNAPSHOTS_FILE |
346 | 398 | generate_snapshot_file_from_s3() { |
347 | 399 | local datetime="${1:-}" |
| 400 | +
|
348 | 401 | 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 |
350 | 408 | fi |
351 | 409 |
|
352 | 410 | snapshot_count=0 |
@@ -496,7 +554,11 @@ data: |
496 | 554 |
|
497 | 555 | # gets the collection aliases from a qdrant node and appends it to $QDRANT_COLLECTION_ALIASES file |
498 | 556 | 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 |
500 | 562 | local result="" |
501 | 563 | local status="" |
502 | 564 |
|
@@ -597,7 +659,11 @@ data: |
597 | 659 | # restores collection aliases to a qdrant node and appends progress to $QDRANT_ALIAS_RECOVERY_HISTORY_FILE |
598 | 660 | recover_collection_aliases() { |
599 | 661 |
|
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 |
601 | 667 |
|
602 | 668 |
|
603 | 669 | if [ "$BACKUP_COLLECTION_ALIASES_ON_S3" = "true" ]; then |
@@ -667,7 +733,12 @@ data: |
667 | 733 |
|
668 | 734 | # gets qdrant peer host url using cluster info endpoint. Sets the port to $QDRANT_HTTP_PORT the http port. |
669 | 735 | 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 | +
|
671 | 742 | result=$(_curl GET "$host/cluster" --header "api-key: $QDRANT_API_KEY") |
672 | 743 | entries=$(jq -r '.result.peers // {}' <<< "$result") |
673 | 744 | peer_uri_entries=$(jq -r 'to_entries[] | "\(.key) \(.value.uri)"' <<< "$entries") |
|
0 commit comments