npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongo-dumper

v0.1.4

Published

Dump and restore single MongoDB instance and Replica set

Downloads

13

Readme

mongo-dumper

Dump and restore single MongoDB instance and Replica set in Node.js

Mongo-dumper provides ground for writing Node.js code focused on dumping and restoring Mongo Databases. It is based on the concept of a Dumper, a vehicle designed for carrying bulk material. Considering that idea, we provide some kinds of Dumpers:

  • DatabaseToFileDumper
  • FileToDatabaseDumper(TODO)
  • DatabaseToDatabaseDumper(TODO)

In other words, load a Dumper with settings and call transport() to make it happen!

Awesome features

  • single instance and replica set support - make a hot backup on them
  • timestamp labeled backup files - output files are saved with a moment.js timestamp reference
  • log files - generate log files for each backup
  • compression - tar.gz (Linux only)
  • authentication - dump secure MongoDbs

Usage

It's a piece of cake:

npm install mongo-dumper --save
var Dumper = require('mongo-dumper').SomeDumper;

var settings = {
	hosts: 'localhost:27017,localhost:27018,localhost:27019',
	authentication : {
		database : 'admin',
		user : 'dbAdmin',
		password : 'dbAdmin'
	}
};

var mongoDumper = new Dumper(settings);

mongoDumper.transport();

Dumpers

Dumper objects contain one main function: transport. They receive a settings object when instanciated, each one validated accordingly to Dumper type object:

function SomeDumper(dumperSettings) {
	// validate dumper settings
};

SomeDumper.prototype.transport = function(){
	// dump, restore or both
}

DatabaseToFileDumper

Makes a backup of datatbase into the filesystem. It is built as a wrapper of mongodump tool.

Dumper settings
 var dumperSettings = {
 	"hosts" : "",
	"authentication" : {
		"user" : "",			// if authentication exists, default admin
		"password" : "",
		"database" : ""
	},
	"db" : {
		"name" : "",
		"collection" : {
			"name" : "",
			"query" : ""
		}
	},
	"output" : {
		"prefix" : "",			// default dump
		"filepath" : "",
		"timestampLabel" : "", 	// moment.js format e.g. 'YYYY-MM-DD_HH-mm-ss'
		"compression": "" 		// tar.gz available
	}
 }
  • hosts - in case of replica set it is a comma separated list of hosts. Otherwise, a single host (default:localhost: 27017)
  • authentication - Secure database authentication
    • user - username
    • password - password
    • database - authentication database (default: admin)
  • db - specific database
    • name - db name
    • collection - specific collection
      • name - collection name
      • query - backup a slice of data
  • output - output backup files
    • prefix - file/folder prefix (default: dump)
    • filepath - where to drop backup files (default: source path)
    • timestampLabel - moment.js timestamp label (e.g. 'YYYY-MM-DD_HH-mm-ss' = 'prefix_2016-01-18_01-39-03')
    • compression - tar.gz available and linux only supported
Sample usage
var Dumper = require('mongo-dumper').DatabaseToFileDumper;

var settings = {
	hosts: 'localhost:27023,localhost:27024,localhost:27025',
	authentication : {
		database : 'admin',
		user : 'dbAdmin',
		password : 'dbAdmin'
	},
	output: {
		timestampLabel : 'YYYY-MM-DD_HH-mm-ss',
		prefix : 'lambda'
	}
};

var mongoDumper = new Dumper(settings);

mongoDumper.transport();
Setting Environment Variables

Environment Variables have higher priority. There is some options available so far:

  • DUMPER_HOSTS - Same as config file
  • DUMPER_AUTH - if true search for environment authentication variable
  • DUMPER_AUTH_DB - Same as config file
  • DUMPER_AUTH_USER - Same as config file
  • DUMPER_AUTH_PASSWORD - Same as config file
DUMPER_HOSTS=localhost:27017,localhost:27018,localhost:27019 / 
DUMPER_AUTH=true / 
DUMPER_AUTH_USER=dbAdmin / 
DUMPER_AUTH_PASSWORD=dbAdmin / 
node index.js

FileToDatabaseDumper

TODO

DatabaseToDatabaseDumper

TODO

CLI tool and Docker

TODO

Dependencies

  • mongodb or docker
  • Compression works only in Linux (calling tar command)

Futures releases

  • support to delayed documemts
  • support to Sharded cluster
  • Db-to-stream dump
  • checksum
  • Docker Dumper (do not need mongo installed)

License

mongo-dumper is freely distributable under the terms of the MIT license.