Skip to content

Instantly share code, notes, and snippets.

@smartm13
Last active December 31, 2024 12:17
Show Gist options
  • Save smartm13/3324a9368f57180f9af984090d194933 to your computer and use it in GitHub Desktop.
Save smartm13/3324a9368f57180f9af984090d194933 to your computer and use it in GitHub Desktop.
Corporate script for Fix Vector to VectorE Docker Mounts
#!/bin/bash
# Check if WEAVIATE_KEY is set
if [ -z "$WEAVIATE_KEY" ]; then
echo "Error: WEAVIATE_KEY environment variable is not set. Exiting."
exit 1
fi
# Extract env_name and account_name using the command provided
path=$(df -h | grep "file.core.windows.net" | grep "shareddata" | awk '{print $6}')
IFS='/' read -ra ADDR <<< "$path"
env_name=${ADDR[1]}
account_name=${ADDR[3]}
echo "Env: ${env_name} Account: ${account_name}"
# Validate if the path exists
if [ ! -d "/${env_name}/fileshare/${account_name}/vectordata/weaviate" ]; then
echo "No vectordata to migrate, maybe already migrated."
exit 1
fi
# Step 1: Capture output of Weaviate object count (without jq)
OLD_RESULT=$(curl --silent -k -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer $WEAVIATE_KEY" -d '{"query": "{ Aggregate { Fixed_db { meta { count } } } }" }' http://localhost:8081/v1/graphql)
echo "Step 1: Recorded existing Weaviate status: $OLD_RESULT"
# Step 2: Stop the Weaviate docker container
echo "Step 2: Stopping Weaviate"
docker stop weaviate
# Step 3: Move files from vectordata to vectoredata
echo "Step 3: Moving Files"
sudo rsync -rav /${env_name}/fileshare/${account_name}/vectordata/weaviate/ /${env_name}/fileshare/${account_name}/vectoredata/weaviate
# Step 4: Fix DockerCompose vectordata to vectoredata
echo "Step 4: Fixing Docker Compose"
sudo sed -i 's/vectordata/vectoredata/g' /home/azureuser/docker-compose.yaml
# Step 5: Start the Weaviate docker container
echo "Step 5: Starting Weaviate"
docker compose -f /home/azureuser/docker-compose.yaml up -d
# Step 6: Capture output of Weaviate object count (without jq)
NEW_RESULT=$(curl --silent -k -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer $WEAVIATE_KEY" -d '{"query": "{ Aggregate { Fixed_db { meta { count } } } }" }' http://localhost:8081/v1/graphql)
echo "Step 6: Recording new Weaviate status: $NEW_RESULT"
# Step 7: Check if OLD_RESULT is not equal to NEW_RESULT
echo "Step 7: Validating result"
if [ "$OLD_RESULT" != "$NEW_RESULT" ]; then
echo "Error: Object count mismatch. Exiting."
exit 1
fi
# Step 8: Remove local vectordata
echo "Step 8: Removing Old Weaviate directory"
sudo rm -rf /${env_name}/fileshare/${account_name}/vectordata
echo "Process completed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment