Giter Club home page Giter Club logo

mongoose-backup's Introduction

Do you need my help? Visit our Discord server.

NPM Downloads License

Node Version >= 16.16.0

Installation

npm i mongoose-backup --save
# or
yarn add mongoose-backup

Importing

// CJS
const { MongooseBackup } = require("mongoose-backup");
const Backup = new MongooseBackup({
    url: "{mongodb_url}",
    location: "Europe/Istanbul" // optional, default: Europe/Istanbul
});

// ESM
import { MongooseBackup } from "mongoose-backup";
const Backup = new MongooseBackup({
    url: "{mongodb_url}",
    location: "Europe/Istanbul" // optional, default: Europe/Istanbul
});

Events

Name Returns
connected Object: url, location
ping Object: message, url, location, time
backupError String
githubBackup Object: time, total, items
localizeBackup Object: time, total, items

Types

url: String,
location: String,
time: Date,
total: Number, // Total Size of Documents.
items: Number // Total Size of Document items.

Usage

Backup with Localize

// ESM
import { MongooseBackup } from "mongoose-backup";
const Backup = new MongooseBackup({
    url: "mongodb://localhost:27017"
});

Backup.on('connected', () => {
    Backup.Localize({
        per: 'minutes' // minutes, hours, daily, monthly, yearly
    });
});

Backup.on("localizeBackup", (data: IEvents) => {
    console.log(`Total ${data.total} documents with ${data.items} items backed up.`);
});

Backup with Github

// ESM
import { MongooseBackup } from "mongoose-backup";
const Backup = new MongooseBackup({
    url: "mongodb://localhost:27017"
});

Backup.on('connected', () => {
    Backup.Github({
        key: "ghp_XXXX",
        per: "daily",
        options: {
            owner: "clqu",
            repo: "empty-repo",
        }
    });
});

Backup.on("githubBackup", (data: IEvents) => {
    console.log(`Total ${data.total} documents with ${data.items} items backed up.`);
});

Example File

// ESM
import { MongooseBackup, IEvents } from "mongoose-backup";

const Backup = new MongooseBackup({
    url: "mongodb://localhost:27017/workspace",
    location: "Europe/Istanbul"
});

Backup.on("connected", (data: IEvents) => {
    console.log(`Connected to ${data.url}!`);
    // Backup.Github({
    //     key: "ghp_XXX",
    //     per: "minutes",
    //     options: {
    //         owner: "clqu",
    //         repo: "empty-repo",
    //     }
    // });

    Backup.Localize({
        per: "minutes"
    });
});

Backup.on("backupError", (message: string) => {
    console.log(message);
});

Backup.on("ping", (data: IEvents) => {
    console.log(`Mongoose Backup is alive. Location: ${data.location}, Logger: ${data.logger}, URL: ${data.url}, Time: ${data.time}`);
});

Backup.on("githubBackup", (data: IEvents) => {
    console.log(`[GitHub]: Total ${data.total} documents with ${data.items} items backed up.`);
});

Backup.on("localizeBackup", (data: IEvents) => {
    console.log(`[Localize]: Total ${data.total} documents with ${data.items} items backed up.`);
});






Developed with ❤️ by Void Development

mongoose-backup's People

Contributors

clqu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.