Created
July 24, 2014 18:50
-
-
Save nshalman/e1a78a4fdbc60e8d405d to your computer and use it in GitHub Desktop.
ZFS snapshot API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var parent_fs = "zones/snapapi/data" | |
var restify = require('restify'); | |
var cp = require('child_process'); | |
function snapshots(req, res, next) { | |
cp.exec("zfs list -Ho name -t snapshot -s creation -r " + parent_fs, function(err, stdout, stderr){ | |
res.send(stdout.trim().split('\n').map(function(x){return x.split('@')[1]})); | |
return next(); | |
}) | |
} | |
function full_snap(req, res, next) { | |
sender = cp.spawn("zfs", ["send", parent_fs + '@' + req.params.start], {stdio: [null, 'pipe', process.stderr]}); | |
sender.stdout.pipe(res); | |
return next(); | |
} | |
function incr_snap(req, res, next) { | |
sender = cp.spawn("zfs", ["send", "-I", parent_fs + '@' + req.params.start, parent_fs + '@' + req.params.end], {stdio: [null, 'pipe', process.stderr]}); | |
sender.stdout.pipe(res); | |
return next(); | |
} | |
var server = restify.createServer({ | |
name: 'snapapi', | |
version: '0.0.1' | |
}); | |
var server = restify.createServer(); | |
server.use(restify.gzipResponse()); | |
server.get('/snapshots', snapshots); | |
server.get('/snapshots/:start', full_snap); | |
server.get('/snapshots/:start/:end', incr_snap); | |
server.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment