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-git-backup

v0.2.7

Published

A tool for making text Mongo backups on Git repos Edit

Downloads

26

Readme

mongo-git-backup Build Status npm version

The tool exports text dump (via mongoexport) of given MongoDB database to given Git repository and restores it back (via mongoimport). Please read MIT License agreement before use.

Pros

  • Github and Bitbucket are safe places to store data and history of data changes.
  • You don't need to pay for a storage if you're able to create private repos (on Bitbucket they're free).
  • You can make as many backups as you can and as often as you want since Git stores diffs instead of storing everything.
  • Git GUI clients (including web UI) allow to nicely show diffs between two versions (two commits) of data.

Cons

  • Likely, it isn't good for big databases.

Install

npm install -g mongo-git-backup

To run the tool on boot you need to install pm2.

npm install -g pm2

CLI

mongo-git-backup export options

  • --db - DB name you want to export (required)
  • --repo - a Git repository where you want to store backups (required)
  • --host - DB host (optional, localhost by default)
  • --port - DB port (optional, 27017 by default)
  • --branch - a branch of the Git repository (optional, master by default)
  • --gitUserName - Git user name (optional)
  • --gitUserEmail - Git user email (optional)
  • --daemonize - daemonize export via pm2
  • --interval - an interval of backups in seconds (works when daemonized, 300 by default)
  • --undaemonize - deletes pm2 process and removes given export settings from the list of mongo-git-backup instances

Example:

mongo-git-backup export --db=test [email protected]:finom/mongo-git-backup.git --branch=test --daemonize

To run the tool on startup:

  • Daemonize it first.
  • Check is mongo-git-backup run by typing pm2 ls in terminal.
  • Run pm2 save to save process list.
  • Run pm2 startup to resurrect the saved process list on startup.

See PM2 documentation for more info.

mongo-git-backup import options

  • --db - DB name you want to restore (required)
  • --repo - a Git repository where backup is stored (required)
  • --branch - a branch of the Git repository (optional, master by default)
  • --checkout - switches to a specified commit or git tag (optional)

Example:

mongo-git-backup import --db=test [email protected]:finom/mongo-git-backup.git --branch=test --checkout=tags/foo

Tip: add this command to NPM scripts to run it easier.

API

There are two functions exported: exportToGit and importFromGit. Both functions return promise. The list of arguments is the same as for CLI.

const { exportToGit, importFromGit } = require('mongo-git-backup');

const options = {
    db: 'test',
    repo: '[email protected]:finom/mongo-git-backup.git',
    branch: 'test'
}

exportToGit(options).then(() => importFromGit(options));