Created
June 27, 2012 21:32
-
-
Save J-O-N/3007002 to your computer and use it in GitHub Desktop.
A tool for copying couch documents between databases/clusters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A tool to copy couch documents between databases/clusters | |
# 2600hz - The Future of Cloud Telecom | |
DB1=$1 | |
DB2=$2 | |
shift 2 | |
DOC_IDS=$@ | |
TEMP_FILE=/tmp/copy_doc.tmp | |
for DOC_ID in $DOC_IDS | |
do | |
# Grab the document | |
curl -s -X "GET" "$DB1/$DOC_ID?attachments=true" > $TEMP_FILE | |
if [ "$DB1" == "$DB2" ]; then | |
# Remove doc ID | |
sed -i -e 's/"_id":"[0-9a-zA-Z\-]*",//' $TEMP_FILE | |
# Remove revision | |
sed -i -e 's/"_rev":"[0-9a-zA-Z\-]*",//' $TEMP_FILE | |
# Post doc to generate new ID | |
curl -s -X "POST" -H "Content-Type: application/json" -d @$TEMP_FILE "$DB2" | |
else | |
# Remove revision | |
sed -i -e 's/"_rev":"[0-9a-zA-Z\-]*",//' $TEMP_FILE | |
# Put doc | |
curl -s -X "PUT" -H "Content-Type: application/json" -d @$TEMP_FILE "$DB2/$DOC_ID" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment