Skip to content

Running sg replicate from Sync Gateway

Adam Fraser edited this page Jun 10, 2016 · 1 revision

Running replications via the REST API

IN THIS DOCUMENT

Sample replications. Configuration Properties A replication is run by sending a POST request to the server endpoint /_replicate, with a JSON object defining the replication parameters. Both one-shot and continuous replications can be run, each replication is one-way between two local or remote Sync Gateway databases. Multiple replications can run simultaneously, supporting bi-directional replications and different replication topologies.

Sample replications. These parameters start a one-shot replication between two database on the local Sync Gateway instance. The request will block until the replication has completed.

{ "source": "db", "target": "db-copy" }

These parameters start a one-shot replication between one database on the local Sync Gateway instance and one on a remote Sync Gateway instance. The request will return immediately and the replication will run asynchronously.

{ "source": "db", "target": "http://example.com:4985/db-copy", "async":true }

These parameters start a continuous replication between one database on the local Sync Gateway instance and one on a remote Sync Gateway instance with the user provided replication_id. The request will return immediately and the replication will run asynchronously.

{ "replication_id":"my-named-replication", "source": "db", "target": "http://example.com:4985/db-copy", "continuous":true }

These parameters start a continuous replication between one database on the local Sync Gateway instance and one on a remote Sync Gateway instance. The replicator will batch up to 1000 revisions at a time, this will improve replication performance but will use more memory resources. Source database documents will be filtered so that only those tagged with the channel names "channel1" or "channel2" are replicated.

{ "source": "db", "target": "http://example.com:4985/db-copy", "continuous":true, "changes_feed_limit":1000, "filter":"sync_gateway/bychannel", "query_params":["channel1","channel2"] }

Configuration Properties The _replicate JSON Object supports the following properties,

Name Type Description Default
source URL Required. A URL pointing to the source database for the replication, the URL may be relative i.e. just the name of a local database on the Sync Gateway instance. The URL may point to the Admin REST API which will replicate all documents in the DB, or it may point to the public REST API which will only copy documents in the users assigned channels. none
target URL Required. A URL pointing to the target database for the replication, the URL may be relative i.e. just the name of a local database on the Sync Gateway instance. The URL may point to the Admin REST API or it may point to the public REST API, this will impact the behaviour of the target database sync function. none
continuous Boolean Optional. Indicates whether the replication should be a one-shot or continuous replication. false
filter String Optional. Passes the name of filter to apply to the source documents, currently the only supported filter is "sync_gateway/bychannel", this will replicate documents only from the set of named channels. None
query_params Object Optional. Passes parameters to the filter, for the "sync_gateway/bychannel" filter the value should be an array or channel names (JSON strings). none
cancel Boolean Optional. Indicates that a running replication task should be cancelled, the running task is identified by passing its replication_id or by passing the original source and target values. false
replication_id String Optional. If the cancel parameter is true then this is the id of the active replication task to be cancelled, otherwise this is the replication_id to be used for the new replication. If no replication_id is given for a new replication it will be assigned a random UUID. false
async Boolean Optional. Indicates that a one-shot replication should be run asynchronously and the request should return immediately. Replication progress can be monitored by using the _active_tasks resource. false
changes_feed_limit Number Optional. The maximum number of change entries to pull in each loop of a continuous changes feed. 50
Clone this wiki locally