Skip to content

Commit 450b6c9

Browse files
committed
feat: backup-qdrant-collection-aliases
1 parent eb56195 commit 450b6c9

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

qdrant-backup-restore/.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ export QDRANT_S3_ENDPOINT_URL="http://minio.default.svc.cluster.local:9000" # up
88
export QDRANT_RESTORE_HOSTS="http://localhost:6334" # update to target restore host(s) (for restore only otherwise leave as empty string).
99
export GET_PEERS_FROM_CLUSTER_INFO="false" # only enable for kubernetes cluster deployment with qdrant cluster.enabled option set as true.
1010
export MC_CONFIG_DIR="mc" # controls where mc S3 client store its configurations (for restore or get_snap_s3 only).
11+
export BACKUP_COLLECTION_ALIASES_ON_S3="true" # enable to backup collection aliases to s3 bucket.
12+
export QDRANT_COLLECTION_ALIASES_STABLE_FILE="collection_aliases" # override the stable version of collection_aliases file to restore.

qdrant-backup-restore/k8s/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Update the following environment varibles in your copy of `backup-cronjob.yaml`
120120
5. `CURL_TIMEOUT` is set at `3000` seconds. This is the max time curl will wait for request to complete. Its increased in scenarios where backup takes a while.
121121
6. `QDRANT_S3_LINK_EXPIRY_DURATION` is set at `3600`. This is the duration that an s3 presigned url will be active. The url is used during the recovery process.
122122
7. `QDRANT_WAIT_ON_TASK` is set as `true`. This configuation make backup process synchronous meaning 'wait for snapshot process to finish successfully before moving on'. Its used during backup and recovery.
123+
8. `BACKUP_COLLECTION_ALIASES_ON_S3` is set as `false`. This configuration is used to toggle backup of collection aliases to S3. The collection_aliases are versioned by the timestamp.
123124

124125
Deploy the job!
125126

@@ -148,6 +149,8 @@ Update the following environment varibles accordingly;
148149
7. `QDRANT_WAIT_ON_TASK` is set as `true`. This configuation make restoration process synchronous meaning 'wait for snapshot process to finish successfully before moving on'. Its used during backup and recovery.
149150
8. `QDRANT_SNAPSHOT_DATETIME_FILTER` is empty. Setting this filters out snapshot/backups belonging to a certain date and time using glob pattern matching. e.g `"2026-01-29"` = all snapshots in 29th January 2026, `2026-01` = all backups in January 2026.
150151
9. `MC_CONFIG_DIR` is `mc`. This overrides the default storage location ($HOME) for mc s3 client configurations. Essential in set ups that use stricter securityContext configuration like `readOnlyRootFilesystem: true`.
152+
10. `BACKUP_COLLECTION_ALIASES_ON_S3` is `false`. When this is set to `true` during restoration it will fetch the lastest `collection_alias` from S3.
153+
11. `QDRANT_COLLECTION_ALIASES_STABLE_FILE` is `collection_aliases`. This configuration is used to override the stable version of collection_aliases file to restore. e.g. `collection_aliases-2026-04-30_18-31-04`. The file has to exist on s3.
151154

152155
Deploy the job!
153156

qdrant-backup-restore/qdrant_backup_recovery.sh

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ QDRANT_FAILED_RECOVERY_FILE="failed_snapshot_recovery"
77
QDRANT_SNAPSHOT_RECOVERY_HISTORY_FILE="snapshot_recovery_history"
88
QDRANT_ALIAS_RECOVERY_HISTORY_FILE="alias_recovery_history"
99
QDRANT_COLLECTION_ALIASES="collection_aliases"
10+
BACKUP_COLLECTION_ALIASES_ON_S3=${BACKUP_COLLECTION_ALIASES_ON_S3:-false}
11+
QDRANT_COLLECTION_ALIASES_BACKUP_FOLDER="collection_aliases_store"
1012
QDRANT_WAIT_ON_TASK=${QDRANT_WAIT_ON_TASK:-true}
1113
CURL_TIMEOUT="${CURL_TIMEOUT:-1800}"
1214
QDRANT_S3_ALIAS="qdrant_s3_snaphost"
1315
QDRANT_S3_LINK_EXPIRY_DURATION="${QDRANT_S3_LINK_EXPIRY_DURATION:-3600s}"
1416
QDRANT_HTTP_PORT="${QDRANT_HTTP_PORT:-6333}"
17+
QDRANT_COLLECTION_ALIASES_STABLE_FILE="${QDRANT_COLLECTION_ALIASES_STABLE_FILE:-collection_aliases}"
1518

1619
declare -a peer_uri_map;
1720
# printf wrapper helper
@@ -510,6 +513,30 @@ get_collection_aliases() {
510513
done <<< "$_result"
511514
fi
512515

516+
if [ "$BACKUP_COLLECTION_ALIASES_ON_S3" = "true" ]; then
517+
local ts
518+
ts=$(date '+%Y-%m-%d_%H-%M-%S')
519+
520+
local base_path="$QDRANT_S3_ALIAS/$QDRANT_S3_BUCKET_NAME/$QDRANT_COLLECTION_ALIASES_BACKUP_FOLDER"
521+
522+
local versioned_dest="$base_path/${QDRANT_COLLECTION_ALIASES}-$ts"
523+
local stable_dest="$base_path/${QDRANT_COLLECTION_ALIASES}"
524+
525+
_printf "backing up collection aliases to s3 bucket %s\n" "$QDRANT_S3_BUCKET_NAME"
526+
527+
if ! mc cp "$QDRANT_COLLECTION_ALIASES" "$versioned_dest"; then
528+
_printf "failed to upload versioned backup to %s\n" "$QDRANT_S3_BUCKET_NAME"
529+
exit 1
530+
fi
531+
532+
if ! mc cp "$versioned_dest" "$stable_dest"; then
533+
_printf "failed to update stable backup pointer in %s\n" "$QDRANT_S3_BUCKET_NAME"
534+
exit 1
535+
fi
536+
537+
_printf "successfully backed up collection aliases to s3 bucket %s\n" "$QDRANT_S3_BUCKET_NAME"
538+
fi
539+
513540
_printf "%s file updated,found %d collection alias(es)!\n" "$QDRANT_COLLECTION_ALIASES" "$colla_length"
514541
}
515542

@@ -550,6 +577,16 @@ recover_collection_alias() {
550577

551578
# restores collection aliases to a qdrant node and appends progress to $QDRANT_ALIAS_RECOVERY_HISTORY_FILE
552579
recover_collection_aliases() {
580+
581+
if [ "$BACKUP_COLLECTION_ALIASES_ON_S3" = "true" ]; then
582+
if mc cp "$QDRANT_S3_ALIAS/$QDRANT_S3_BUCKET_NAME/$QDRANT_COLLECTION_ALIASES_BACKUP_FOLDER/$QDRANT_COLLECTION_ALIASES_STABLE_FILE" "$QDRANT_COLLECTION_ALIASES"; then
583+
_printf "collection aliases restored from s3 bucket %s\n" "$QDRANT_S3_BUCKET_NAME"
584+
else
585+
_printf "failed to restore collection aliases file (%s) from s3 bucket %s\n" "$QDRANT_COLLECTION_ALIASES_STABLE_FILE" "$QDRANT_S3_BUCKET_NAME"
586+
exit 1
587+
fi
588+
fi
589+
553590
if [[ ! -s "$QDRANT_COLLECTION_ALIASES" ]]; then
554591
get_collection_aliases
555592
fi
@@ -562,7 +599,7 @@ recover_collection_aliases() {
562599
colla_count=$(wc -l < $QDRANT_COLLECTION_ALIASES)
563600
recovered_colla_count=0
564601
failed_recovered_colla_count=0
565-
602+
colla_skipped_count=0
566603
local host="${restore_hosts[0]}"
567604

568605
touch $QDRANT_ALIAS_RECOVERY_HISTORY_FILE
@@ -577,12 +614,13 @@ recover_collection_aliases() {
577614

578615
if [ "$history_count" -gt 0 ]; then
579616
_printf "[%s] collection alias %s:%s already recovered, skipping!\n" "$host" "$collection_name" "$alias_name"
617+
((colla_skipped_count=colla_skipped_count+1))
580618
continue
581619
fi
582620
recover_collection_alias "$collection_name" "$alias_name"
583621
done < $QDRANT_COLLECTION_ALIASES
584622

585-
_printf "recovery summary: %d/%d collection aliases recovered, %d failed.\n" "$recovered_colla_count" "$colla_count" "$failed_recovered_colla_count"
623+
_printf "recovery summary: %d/%d collection aliases recovered, %d failed, %d skipped.\n" "$recovered_colla_count" "$colla_count" "$failed_recovered_colla_count" "$colla_skipped_count"
586624

587625
colla_count=0
588626
recovered_colla_count=0

0 commit comments

Comments
 (0)