Last active
April 16, 2022 14:59
-
-
Save jo/e95110dddc01e169dfca56bc4c6a2f83 to your computer and use it in GitHub Desktop.
A minimalistic CouchDB replicator in Bash with curl and jq
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://docs.couchdb.org/en/3.2.0/replication/protocol.html