Skip to content

nfriedly/couchdb-backup-restore

Repository files navigation

couchdb-backup-restore NPM version Build Status - with CouchDB 1.6.1 Node.js CI - with CouchDB 2.3, 3.0, and latest

Creates backups of couchdb databases (.tar.gz files containing one .json file per database) and restores from those backups.

Also plays nice with Cloudant (hosted CouchDB service).

Note: the official backup methods are recomended for most users. However, this tool will remain avaliable for those who need it.

Limitations

Install

$ npm install --save couchdb-backup-restore

Usage

var fs = require('fs');
var cbr = require('couchdb-backup-restore');

var config = {credentials: 'http://localhost:5984'};

function done(err) {
  if (err) {
    return console.error(err);
  }
  console.log('all done!');
}

// backup
cbr.backup(config, done).pipe(fs.createWriteStream('./db-backup.tar.gz'))
  
// restore
fs.createReadStream('./db-backup.tar.gz').pipe(cbr.restore(config, done));

Bluemix / Cloudant example:

var cbr = require('couchdb-backup-restore');
var bluemix = require('bluemix'); 

var config = {
 credentials: bluemix.getService('cloudantNoSQLDB').credentials
}

// or just var config = bluemix.getService('cloudantNoSQLDB');

Configuring

Default options are:

{
  credentials: 'http://localhost:5984',
  excludeDbs: ['_replicator', '_users'], // automatic built-in dbs that you probably don't want to backup
  databases: null
}
  • credentials is passed directly to nano and can be either a straight url or a configuration object.
  • excludeDbs should be an array, although it may be an empty array ([]) if you want to include the built-in _replicator and _users databases.
  • databases may be an array. If set, CBR will only back up the specified DBs, overriding the excludeDbs option.

Compatibility

Travis CI automatically tests changes against Node.js LTS and Stable (14.16.0 and 15.10.0 at the time of writing) and CouchDB 1.6.1.

Github Actions automatically tests changes against Node.js 14 and 15 and Couch DB 2.3, 3.0, and latest (3.1.1 at the time of writing).

License

MIT © Nathan Friedly

About

Node.js library for simple backup and restore of CouchDB databases

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •