CouchDB (using _replicator db) replication helpers
Replimate provides some helpers for working with the CouchDB 1.1
_replicator database. Using the
provides some benefits over the traditional replication methods
including replication persistence across CouchDB server restarts.
Working with replimate is designed to be really easy, and here are a few examples:
var replimate = require'replimate';var targetUrl = processenvCOUCHDB_URL || '';var out = require'out';replimatedbUrlif errreturn out.errorerr;console.logdocs;;
Creating a new replcication job is pretty easy also:
var replimate = require'replimate';var targetUrl = processenvCOUCHDB_URL || '';var opts =action: 'replicate'source: ''target: 'seattle_neighbourhood';// create a replication rule to run from the test seattle_neighbourhood db// to a local copy on the replimate instancereplimatetargetUrl optsconsole.log'replication started';// using the returned monitor,// report when the replication has finishedmonitoron'completed'console.log'replication finished';;;
You will note here, however, that we need to supply admin credentials to create a new replication job as the seattle_neighbourhood db will be need to be created on the replimate.iriscouch.com server.
One thing that is interesting about the
_replicator database is that it
does start to fill up with replication jobs that have been completed in
the past. In an effort to help keep my replicator database instances
clear-completed job was created.
Like creating new replication jobs, a user with admin privileges is required:
var replimate = require'replimate';var targetUrl = processenvCOUCHDB_URL || '';var out = require'out';replimatetargetUrl action: 'clear-completed'if errreturn out.errorerr;out'_replicator database now a little cleaner...';;
Start the replimate process. The
targetUrl specifies the target couch
server endpoint (including basic auth admin credentials if required).
opts are specified, then replimate will simply return information on
the entries within the
_replicator database on that server.
The replication Monitor class is returned from creating a replication task using replimate. A Monitor provides a useful way to pass around an object that can be used in other parts of your application to check on the status of a particular replication job
Cancel a replication task
Request the status of the replication task.
This is a simple helper function that will check the current state of the specified state name, and if already flagged trigger an event immediately when a new event listener is coupled to the replication monitor
Monitor the state of the replication job, and update data against the monitor as it changes.
Replimate implements a few core actions that can be invoked through the options passed to replimate
info action is used to retrieve a list of all the current replication jobs for
the target servers
_replicator database. If no action is specified, then info is
used by default
replicate action is used to create a new replication task in the target
_replicator database. For information on how the CouchDB _replicator
database operates, see the CouchDB wiki
Copyright (c) 2016 Damon Oehlman firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.