Skip to content

Instantly share code, notes, and snippets.

@soldair soldair/db.js
Last active Jun 21, 2018

What would you like to do?
backup a running node levelup process
var levelup = require('level')
var zlib = require('zlib')
var fs = require('fs')
var through = require('through')
//hot backup
db = levelup(...)
var backingup = false
var backupfile = "./backupjson.log.gz"
process.on('SIGHUP', function() {
if(backingup) return console.log('im already backing up')
console.log('backup started!')
var t =
// an example of backing up to a file.
.pipe(through(function(obj) {
// depending on if you store binary data your serialization method could be msgpack.
.on("close",function() {
backingup = false;
console.log('backup complete. took ',, 'ms');
var split = require("split")
var through = require("through")
var fs = require("fs")
var zlib = require("zlib")
var levelup = require("level")
var db = levelup("./db2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.