Skip to content

Instantly share code, notes, and snippets.

@J-O-N
Created June 27, 2012 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save J-O-N/3007002 to your computer and use it in GitHub Desktop.
Save J-O-N/3007002 to your computer and use it in GitHub Desktop.
A tool for copying couch documents between databases/clusters
#!/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