1.0.6 • Published 1 year ago

mongod-backup v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

MongoDB Backup and Restore Utility

This is a Node.js module that provides backup and restore utility functions for MongoDB databases. It uses the mongodump and mongorestore commands to create and restore database backups.

Prerequisites

  • Node.js version 14 or higher
  • MongoDB installed locally or remote server
  • MongoDB installed on your machine
  • Node.js installed on your machine

Installation

To install the module, run the following command in your Node.js project:

bashCopy code

npm install mongod-backup

Usage

backup(dbUri: string): Promise

This function creates a backup of a MongoDB database using the mongodump command. It accepts a database URI as a parameter and returns a promise that resolves with the path of the archive file that was created.

const { backup } = require("mongod-backup");

const dbUri = "mongodb://localhost:27017/mydatabase";

backup(dbUri)
  .then((backupPath) => {
    console.log(`Backup successful. Archive file path: ${backupPath}`);
  })
  .catch((error) => {
    console.log("Backup failed.", error);
  });

restore(dbName: string, archivePath: string): Promise

This function restores a MongoDB database from an archive file using the mongorestore command. It accepts the name of the database to restore and the path of the archive file as parameters, and returns a promise that resolves with a success message when the restore is complete.

const { restore } = require("mongod-backup");

restore("mydatabase", "/path/to/archive/file")
  .then((message) => {
    console.log(message);
  })
  .catch((error) => {
    console.error("Restore failed:", error);
  });

backupFromLocal(dbName: string): Promise

This function creates a backup of a local MongoDB database using the mongodump command. It accepts the name of the database as a parameter and returns a promise that resolves with the path of the archive file that was created.

const { backupFromLocal } = require("mongod-backup");

backupFromLocal("mydatabase")
  .then((archivePath) => {
    console.log(`Backup successful: ${archivePath}`);
  })
  .catch((error) => {
    console.error("Backup failed:", error);
  });

Contributing

Contributions to this module are welcome. To contribute, please create a pull request with your changes.

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago