Replimate¶
Replimate is a Node.js library that is designed to provide a simple API to for working with CouchDB replication (via the Replicator database).
Contents:
Checking Replication Status¶
Getting the current _replicator database rules is simple using replimate:
Running this example should run output similar to the following:
[ { _id: 'test_test2',
_rev: '119-c46968d9e7a4485015279b4e3af7d465',
source: 'test',
target: 'test2',
continuous: true,
create_target: true,
user_ctx: { name: 'admin', roles: [ '_admin' ] },
owner: 'admin',
_replication_state: 'triggered',
_replication_state_time: '2012-07-20T03:32:43+00:00',
_replication_id: '922742a54303e0c8aa96b09f93bf55ca' } ]
This data is provided directly from the CouchDB _replicator db entry, and will contain both current and completed replication jobs.
Starting a Replication Job¶
Starting a replication job is simple when using replimate:
var replimate = require('replimate'),
var targetUrl = process.env.COUCHDB_URL || 'http://localhost:5984';
var opts = {
action: 'replicate',
source: 'http://sidelab.iriscouch.com/seattle_neighbourhood',
target: 'seattle_neighbourhood'
};
// create a replication rule to run from the test seattle_neighbourhood db
// to a local copy on the replimate instance
replimate(targetUrl, opts, function(err, monitor) {
console.log('replication started');
// using the returned monitor,
// report when the replication has finished
monitor.on('completed', function() {
console.log('replication finished');
});
});