public
Created

A tool for copying couch documents between databases/clusters

  • Download Gist
copy_doc.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.