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

influx-backup

v1.0.1

Published

Influxdb backup/restore helper

Downloads

7

Readme

influx-backup

NPM version Downloads

PRs Welcome MIT Licence

NPM

Description

NodeJS module for InfluxDB backup/restore. This module allows to backup an InfluxDB database by creating a zip file with all backup files generated with the influxd shell command.

REQUIREMENTS

  • influxd bin must be installed in your system. Check it by running which influxd command
  • Works only with InfluxDB > v1.5

Uses InfluxDB portable backups introduced in InfluxDb v1.5, check docs for more info.

Install

Run the following command in the root directory of your project

npm install influx-backup --save

Usage

Check here and the example in examples folder

Here are some lines from examples/app.js

const TEST_DB = "testDB";

const manager = new BackupManager({db: TEST_DB});

// Restore DB api
app.post('/restore', (req, res) => {

  var restore_path = "";

  // create a temp directory to use for the backup
  manager.createDir()
  .then((dir) => {

    restore_path = dir;

    // Use multer to get the file from the req
    // and store it in the temp dir created
    var Storage = multer.diskStorage({
        destination: restore_path,
        filename: function(req, file, callback) {
            callback(null, file.originalname);
        }
    });

    // "restore" is the name attr of input file in html
    var upload = multer({storage: Storage}).single("restore");

    return multerPromise(upload, req, res)
  })
  .then((file) => {
      //now the file is stored correctly, I can start the restore command
    if(file){
        return manager.restore(restore_path, file.originalname)
    }else{
        throw Error("No file provided");
    }
}) //the backup has been restored in a backup database, load the backup in the main database
  .then(() => manager.loadBackup())
  .then(() => res.json({success:true, message: "Backup restored successfully"}))
  .catch(err => {
      console.log(err);
      res.json({success:false, message: err.message})
  });
});

// Backup DB api
app.get('/backup', (req, res) => {

  manager.backup()
  .then((file) => {
     //zip file is ready, send it to the client
    var stream = fs.createReadStream(file);

    res.setHeader('Content-disposition', 'attachment; filename=' + file.split('/').pop());

    stream.once("close", function () {
      stream.destroy(); // makesure stream closed, not close if download aborted.
      //IMPORTANT: remove backup files and zip
      manager.deleteDir(path.dirname(file));
    });

    stream.pipe(res);
  })
  .catch(err => {
    res.json({success: false, message: err});
  });

});

// Check testDB exists, if not create one and start app listening on port 8000
influx.getDatabaseNames()
.then(names => {
  if (!names.includes(TEST_DB)) {
    return influx.createDatabase(TEST_DB)
  }
})
.then(() => manager.init())
.then(() => {
  app.listen(8000, function () {
    console.log('Listening on port 8000')
  })
})
.catch(err => {
  console.error(`Error creating Influx database!`)
})