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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mongodb-backup-cloud

v1.0.8

Published

backup mongodb databases and upload to github/google drive

Readme

Mongodb-backup-cloud

Automate mongodb instance backup & upload to Github / GDrive

npm i mongodb-backup-cloud

What can this package do?

  • Backup Mongodb database instances
  • Upload backup files to Github
  • Upload backup files to Google Drive

Note

  • Backup process can be executed once or repeatedly using cron schedules
  • In order for the backup process to work the computer running the code must have Mongodb Database Tools installed and added to Path
    How to install Mongodb Database Tools

usage

Backup Process

import {Backup, DirectOptions, URIOptions } from  "mongodb-backup-cloud";

// Backup with mongodb connection string
-----------------------------------------------

const uriOptions: URIOptions = {
  uri: "mongodb://localhost:27017/",
  database: 'test_db',
  collection: 'test_collection',
  outputPath: './test_backup_path',
};

Backup.withConnectionString(uriOptions);


// Backup with host & port
-----------------------------------------------
  
const directOptions: DirectOptions = {
  host: "localhost",
  port: "27017",
  database: "test_db",
  collection: "test_collection",
  outputPath: "./test_backup_path",
};

Backup.withHostAndPort(directOptions);


// Backup + Delete old backup files
----------------------------------------------

const uriOptions: URIOptions = {
  uri: "mongodb://localhost:27017/",
  database: "test_db",
  collection: "test_collection",
  outputPath: "./test_backup_path",
  removeOldBackups: true,
  oldBackupPath: "./old_backup",
};

Backup.withConnectionString(uriOptions);


// Run backup with cron schedule
---------------------------------------------

const scheduleOptions: DirectOptions = {
  host: "localhost",
  port: "27017",
  database: "test_db",
  collection: "test_collection",
  outputPath: "./test_backup_path",
  schedule: '00 00 00 * * *',
  scheduleCallback: (args) => { /* do something */ },
};

Backup.withHostAndPort(scheduleOptions);


// Backup + Delete old backups with cron schedule
--------------------------------------------------
  
const scheduleOptions: DirectOptions = {
  host: "localhost",
  port: "27017",
  database: "test_db",
  collection: "test_collection",
  outputPath: "./test_backup_path",
  schedule: "00 00 00 * * *",
  scheduleCallback: (args) => {/* do something */ },
  removeOldBackups: true,
  localBackupRange: 2,
};

Backup.withHostAndPort(scheduleOptions);

Upload Process

import {Upload, GDriveOptions, GithubOptions,} from  "mongodb-backup-cloud";

// Upload files to github

const githubOptions: GithubOptions = {
  token: 'private access token', // with repo and read:user access to read repo names
  repository: 'test_repo',
  branch: 'main',
  email: 'your github email',
  filePath: './backups'
}

Upload.toGitHub(githubOptions);


// Upload files to Google Drive

const driveOptions: GDriveOptions = {
  clientId: 'oAuth client id',
  clientSecret: 'oAuth client secret',
  refreshToken: 'oAuth refresh token',
  driveFolderName: 'test_upload',
  filePath: './backups'
}

Upload.toGoogleDrive(driveOptions);

How to get OAuth Credentials


Available Options

Backup

| option | type | default | description | | ------------------ | ------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | uri | string | --- | Mongodb connection string | | host | string | --- | Specifies the resolvable hostname of the MongoDB deployment. | | port | string | --- | Specifies the TCP port on which the MongoDB instance listens for client connections. | | username | string | --- | Specifies a username with which to authenticate to a MongoDB database that uses authentication. | | password | string | --- | Specifies a password with which to authenticate to a MongoDB database that uses authentication. | | verbose | number (1-5) | 1 | Increases the amount of logging output | | quiet | boolean | false | Limits the amount of output | | readPreference | object | primary | Specifies the read preference for mongodump | | gzip | boolean | false | Compresses the output. The files have the suffix ' .gz ' | | outputPath | string | current_directory/backup | Specifies the directory where mongodump will write BSON files for the dumped databases. (can't be used together with archive option ) | | archive | string | --- | Writes the output to a specified archive file. (can't be used together with outputPath option ) | | archiveExtension | string | --- | File extension of the archive file. | | schedule | string | --- | cron schedule string. ex:- '0 0 * * * ' | | scheduleCallback | function | --- | Callback function to run after every scheduled backup process completion | | removeOldBackups | boolean | false | Remove previous backups | | removeOldDir | boolean | false | Remove entire directory containing previous backups | | oldBackupPath | string | --- | Relative path to the previous backup that should be removed * useful only when NOT using the schedule option** | | localBackupRange | number | 7 | Number of days to keep previous backups. Backups made before the specified number of days will be removed ** available only when using the schedule option** | | database | string | --- | Specifies a database to backup. If you do not specify a database, mongodump copies all databases of the instance into the dump files. | | collection | string | --- | Specifies a collection to backup. If you do not specify a collection, this option copies all collections in the specified database or instance to the dump files. | | query | string | --- | Provides a JSON document as a query that optionally limits the documents included in the output of mongodump. ** available only when using the collection option** | | queryFilePath | string | --- | Specifies the path to a file containing a JSON document as a query filter that limits the documents included in the output of mongodump. | | dumpUsersAndRoles | boolean | false | Includes user and role definitions in the database's dump directory ** available only when using the database option** | | excludeCollection | Array[string] | --- | Excludes the specified collections from the mongodump output example :- ['coll_1', 'coll_2'] | | excludeWithPrefix | Array[string] | --- | Excludes all collections with a specified prefix from the mongodump outputs. example :- ['coll', 'test'] | | parallel | number | --- | Number of collections mongodump should export in parallel. | | viewsAsCollections | boolean | --- | When specified, mongodump exports read-only views as collections. |

Upload

  • Github

| option | type | description | | ---------- | ------ | ---------------------------------------------------------- | | token | string | Github private access token | | repository | string | Github repository name | | branch | string | Github repository branch name | | email | string | Github account email | | filePath | string | Path to file or directory that needs to be added to github |


  • Google Drive

| option | type | description | | --------------- | ------ | -------------------------------------------------------------------------------- | | clientId | string | OAuth client id | | clientSecret | string | OAuth client secret | | refreshToken | string | OAuth refresh token | | filePath | string | Path to the file or directory that needs to be uploaded. | | driveFolderName | string | Google drive root level folder name. folder will be created if it doesn't exist. |

How to get OAuth Credentials