Inter-Sync Gateway Replication Configuration

    Using Sync Gateway’s Admin REST API to configure and manage inter-Sync Gateway replications

    Pre-3.0 Legacy Configuration Equivalents

    This content describes configuration for Sync Gateway 3.0 and higher — for legacy configuration, see: Legacy Pre-3.0 Configuration

    Introduction

    Sync Gateway 3.0 and later uses the Admin REST API to provision persistent configuration changes. This page introduces the PUT/{url}/{db}/_replication/{replicationId} endpoint for convenience — see Replication for a full description of the endpoints available.

    Using CA Certificates

    You must add required CA certificates to the system certificate pool.

    On Linux, you can do this using 1 of the following methods:

    • Adding the location of the certificate to SSL_CERT_FILE environment variable,

    • Placing the certificate in a location pointed to by the SSL_CERT_DIR environment variable.

    • Using 1 of the system-dependent locations listed in this file.

    For Windows-based systems, add CA certificate files to the system root certificate store.

    Upsert a Replication

    For complete endpoint details, see PUT/{url}/{db}/_replication/{replicationId}.

    Example

    • Curl

    • HTTP

    curl --location --request PUT 'http://localhost:4985/db1-local/_replication/db1-rep-id1 '\
    --header 'Content-Type: application/json' \
    --data-raw '{
      "direction": "push",
      "purge_on_removal": false,
      "remote": "http://user1:password1@example.com:4984/db1-remote",
      "filter":"sync_gateway/bychannel",
      "query_params": {
        "channels":["channel.user1"]
      },
      "continuous": false
      }'
    PUT /db1-local/_replication/db1-rep-id1 HTTP/1.1
    Host: localhost:4985
    Content-Type: application/json
    Content-Length: 235
    
    {"direction": "push",
      "purge_on_removal":false,
      "remote": "http://user1:password1@example.com:4984/db1-remote",
      "filter":"sync_gateway/bychannel",
      "query_params": {
        "channels":["channel.user1"]
      },
      "continuous": false
    }

    Schema

    This section shows the replication configuration settings in schema format. Use these schemas to construct JSON models for the Admin REST API.

    The configuration settings described here are provisioned through the Replication endpoints.

    {
       adhoc: false,
       batch_size: 200,
       collections_enabled: false,
       collections_local: ["string"...],
       collections_remote: ["string"...],
       conflict_resolution_type: "default",
       continuous: false,
       custom_conflict_resolver: "",
       direction: "string",
       enable_delta_sync: false,
       filter: "string",
       initial_state: "running",
       max_backoff_time: 5,
       purge_on_removal: false,
       query_params: ["string"...],
       remote: "string",
       remote_password: "string",
       remote_username: "string",
       replication_id: "string",
       run_as: "string"
    }
    

    adhoc

    Type

    boolean

    Description

    Set to true to run the replication as an adhoc replication instead of a persistent one.

    This means that the replication will only last the period of the replication until the status is changed to stopped and then it will be removed automatically. It will also be removed if Sync Gateway restarts or if removed due to user action.

    batch_size

    Type

    integer

    Default

    200

    Description

    The amount of changes to be sent in one batch of replications. Changing this is an Enterprise Edition only feature.

    collections_enabled

    Type

    boolean

    Description

    If true, the replicator will run with collections, and will replicate all collections, unless otherwise limited by collections_local.

    If false, the replicator will only replicate the default collection.

    collections_local

    Type

    array

    Description

    Limits the set of collections replicated to those listed in this array.

    The replication will use all collections defined on the database if this list is empty.

    collections_remote

    Type

    array

    Description

    Remaps the local collection name to the one specified in this array when replicating with the remote.

    If only a subset of collections need remapping, elements in this array can be specified as null to preserve the local collection name.

    The same index is used for both collections_remote and collections_local, and both arrays must be the same length.

    conflict_resolution_type

    Type

    string

    Default

    default

    Description

    This defines what conflict resolution policy Sync Gateway should use to apply when resolving conflicting revisions.

    Changing this is an Enterprise Edition only feature.

    continuous

    Type

    boolean

    Description

    If true, changes will be immediately synced when they happen. This is known as a continuous replication.

    If false, all changes will be synced until they have been processed. The replication will then cease and not process any future changes (unless started again by the user). This is known as a one-shot replication.

    custom_conflict_resolver

    Type

    string

    Description

    This specifies the Javascript function to use to resolve conflicts between conflicting revisions.

    This must be used when conflict_resolution_type=custom. This property will be ignored when conflict_resolution_type is not custom.

    The Javascript function to provide this property should be in backticks (like the sync function). The function takes 1 parameter which is a struct that represents the conflict. This struct has 2 properties:

    • LocalDocument - The local document. This contains the document ID under the _id key.
    • RemoteDocument - The remote document The function should return the new document's body. This can be the winning revision (for example, return conflict.LocalDocument), a new body, or nil to resolve as a delete.

    Example:

    function(conflict) {
      console.log("Doc ID: "+conflict.LocalDocument._id);
      console.log("Full remote doc: "+JSON.stringify(conflict.RemoteDocument));
      return conflict.RemoteDocument;
    }
    

    Using complex custom_conflict_resolver functions can noticeably degrade performance. Use a built-in resolver whenever possible.

    If a document merge is being done, the _rev and _cv properties should not be included in the returned document body as Sync Gateway will generate new values for these.

    This is an Enterprise Edition only feature.

    direction

    Type

    string

    Description

    This specifies which direction the replication will be replicating with the remote replicator.

    enable_delta_sync

    Type

    boolean

    Description

    This will turn on delta-sync for the replication. In order to enable delta-sync for a replication, the database level setting delta_sync.enabled must also be set to true.

    Using delta-sync is an Enterprise Edition only feature.

    filter

    Type

    string

    Description

    This defines whether to filter documents.

    initial_state

    Type

    string

    Default

    running

    Description

    This is what state to start the replication in when creating a new replication.

    This allows you to control if the replication starts in a stopped start or running state.

    Replications prior to Sync Gateway 2.8 will run in the default state running.

    max_backoff_time

    Type

    integer

    Default

    5

    Description

    Specifies the maximum time-period (in minutes) that Sync Gateway will attempt to reconnect to a lost or unreachable remote.

    When a disconnection happens, Sync Gateway will do an exponential backoff up to this specified value. When this value is met, it will attempt to reconnect indefinitely every max_backoff_time minutes.

    If this is set to 0, Sync Gateway will do the normal exponential backoff after the disconnect happens but then attempting 10 minutes and stop the replication.

    Note: this defaults to 5 minutes for replications created prior to Sync Gateway 2.8.

    purge_on_removal

    Type

    boolean

    Description

    Specifies whether to purge a document if the remote user loses access to all of the channels on the document when attempting to pull it from the remote.

    If false, documents will not be replicated and not be purged when the user loses access.

    query_params

    Type

    array

    Description

    This is a set of key/value pairs used in the query string of the replication.

    If filters=sync_gateway/bychannel then this can be used to set the channels to filter by in a pull replication. To do this, set the channels key to a string array of the channels to filter by. For example:

    "filter":"sync_gateway/bychannel",
    "query_params": {
      "channels":["chanUser1"]
    },
    

    remote

    Type

    string

    Description

    This is the endpoint of the database for the remote Sync Gateway that is the subject of this replication's push, pull, or pushAndPull action. Typically this would include the URI, port, and database name. For example, https://localhost:4985/db.

    remote_password

    Type

    string

    Description

    The password to use to authenticate with the remote. This password will be redacted in the replication config.

    remote_username

    Type

    string

    Description

    The username to use to authenticate with the remote.

    replication_id

    Type

    string

    Description

    This is the ID of the replication.

    When creating a new replication using a POST request, this will be set to a random UUID if not explicitly set.

    When the replication ID is specified in the URL, this must be set to the same replication ID if specifying it at all.

    run_as

    Type

    string

    Description

    This is used if you want to specify a user to run the replication as. This means that the replication will only be able to replicate what the user access to what the user has access to.