Skip to content

Instantly share code, notes, and snippets.

@jo
Last active April 16, 2022 14:59
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 jo/e95110dddc01e169dfca56bc4c6a2f83 to your computer and use it in GitHub Desktop.
Save jo/e95110dddc01e169dfca56bc4c6a2f83 to your computer and use it in GitHub Desktop.
A minimalistic CouchDB replicator in Bash with curl and jq
curl --silent "$source_url/_changes?feed=normal&style=all_docs" \
| jq '.results | reduce .[] as $change ({}; . + { ($change.id): $change.changes | map(.rev) } )' \
| curl --silent -XPOST "$target_url/_revs_diff" -d@- -H 'Content-Type:application/json' \
| jq 'to_entries | reduce .[] as $entry ([]; . + ($entry.value.missing | map({ id: $entry.key, rev: . }))) | { docs: . }' \
| curl --silent -XPOST "$source_url/_bulk_get?revs=true&attachments=true" -d@- -H 'Content-Type:application/json' \
| jq '.results | map(.docs) | reduce .[] as $docs ([]; . + ($docs | map(.ok))) | { docs: ., new_edits: false }' \
| curl --silent -XPOST "$target_url/_bulk_docs" -d@- -H 'Content-Type:application/json' \
| jq
@jo
Copy link
Author

jo commented Apr 16, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment