Skip to content

Commit

Permalink
feat: support local snapshot file in CLI tool
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Liu <[email protected]>
  • Loading branch information
apepkuss committed Jul 16, 2024
1 parent b87afda commit b63a11f
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions gaianet
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,31 @@ create_collection() {

# 10.1 recover from the given qdrant collection snapshot
if [ -n "$url_snapshot" ]; then
printf " * Download Qdrant collection snapshot ...\n"
if [[ $url_snapshot == *.tar.gz ]]; then
filename=$(basename $url_snapshot)
check_curl $url_snapshot $gaianet_base_dir/$filename

This comment was marked as off-topic.

tar -xzOf $gaianet_base_dir/$filename > $gaianet_base_dir/default.snapshot
rm $gaianet_base_dir/$filename
# Regular expression for URL validation
regex="^(https?|ftp)://[^\s/$.?#].[^\s]*$"

# Check if $url_snapshot is a valid URL
if [[ $url_snapshot =~ $regex ]]; then
printf " * Download Qdrant collection snapshot ...\n"
if [[ $url_snapshot == *.tar.gz ]]; then
filename=$(basename $url_snapshot)
check_curl $url_snapshot $gaianet_base_dir/$filename
tar -xzOf $gaianet_base_dir/$filename > $gaianet_base_dir/default.snapshot
rm $gaianet_base_dir/$filename
else
check_curl $url_snapshot $gaianet_base_dir/default.snapshot
fi
info " The snapshot is downloaded in $gaianet_base_dir"

# Check if $url_snapshot is a local file
elif [ -f "$gaianet_base_dir/$url_snapshot" ]; then
# rename the file to default.snapshot
info " * Rename $url_snapshot to default.snapshot ..."
cp $gaianet_base_dir/$url_snapshot $gaianet_base_dir/default.snapshot

else
check_curl $url_snapshot $gaianet_base_dir/default.snapshot
echo "$url_snapshot is neither a valid URL nor a local file."
fi
info " The snapshot is downloaded in $gaianet_base_dir"

printf " * Import the Qdrant collection snapshot ...\n"
printf " The process may take a few minutes. Please wait ...\n"
Expand All @@ -271,7 +286,8 @@ create_collection() {
error " * [Error] Failed to recover from the collection snapshot. $response"

if [ "$qdrant_already_running" = false ]; then
kill $qdrant_pid
info " * Stop the Qdrant instance ..."
kill -9 $qdrant_pid
fi

exit 1
Expand Down

0 comments on commit b63a11f

Please sign in to comment.