Skip to content

@J-O-N /copy_doc.sh
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.