node package manager

zfs

A Node.js wrapper around zfs/zpool

                  __                             ___ 
                 /\ \                          /'___\
  ___     ___    \_\ \     __           ____  /\ \__/  ____
/' _ `\  / __`\  /'_` \  /'__`\ _______/\_ ,`\\ \ ,__\/',__\
/\ \/\ \/\ \L\ \/\ \L\ \/\  __//\______\/_/  /_\ \ \_/\__, `\
\ \_\ \_\ \____/\ \___,_\ \____\/______/ /\____\\ \_\\/\____/
 \/_/\/_/\/___/  \/__,_ /\/____/         \/____/ \/_/ \/___/

node-zfs

node-zfs is a simple wrapper around the zfs and zpool commands. It enables ZFS management scripting using Node.js under SmartOS, Solaris, OpenIndiana and FreeBSD. Node-zfs is also tested successfully on Ubuntu.

Installation

Using npm:

$ npm install --save zfs

Usage

var zfs-filesystem = require('zfs');
zfs-filesystem.zfs.
zfs-filesystem.zpool.

The list command lists a specific zfs dataset or all datasets. All possible options can be found inside the lib/zfs.js file.

zfs-filesystem.zfs.list(function (err, list) {
    console.log(list)
});

Get the parameters of a specific dataset or all datasets. All possible options can be found inside the lib/zfs.js file.

var opts = {
    name: 'my-dataset-name',
    property: 'quota'
};
 
zfs-filesystem.zfs.get(opts, function (err, options) {
    console.log(options);
});

Set a specific option for a given dataset. All possible options can be found inside the lib/zfs.js file.

var opts = {
    name: 'my-dataset-name',
    property: 'quota',
    value: '1024G'
};
 
zfs-filesystem.zfs.set(opts, function (err, output) {
    console.log(output);
});

Remove a dataset from the ZFS filesystem

var opts = {
    name: 'my-dataset-name'
};
 
zfs-filesystem.zfs.destroy(opts, function (err, output) {
    console.log(output);
});

Create a new dataset inside the ZFS filesystem. All possible options can be found inside the lib/zfs.js file.

var opts = {
    name: 'my-new-dataset-name'
};
 
zfs-filesystem.zfs.create(opts, function (err, output) {
    console.log(output);
});

Creates a snapshot with the given name. All possible options can be found inside the lib/zfs.js file.

var opts = {
    name: 'my-new-snapshot-name',
    dataset: 'my-dataset-name'
};
 
zfs-filesystem.zfs.snapshot(opts, function (err, output) {
    console.log(output);
});

Creates a clone of the given snapshot. All possible options can be found inside the lib/zfs.js file.

var opts = {
    snapshot: 'my-snapshot-name',
    dataset: 'my-mountpoint-name'
};
 
zfs-filesystem.zfs.clone(opts, function (err, output) {
    console.log(output);
});

Mount the filesystem with the specified name or all filesystems. All possible options can be found inside the lib/zfs.js file.

var opts = {
    dataset: 'my-filesystem-name'
};
 
zfs-filesystem.zfs.mount(opts, function (err, output) {
    console.log(output);
});

Unmount the filesystem or the mountpoint or all filesystems. All possible options can be found inside the lib/zfs.js file.

var opts = {
    name: 'my-filesystem-name',
    force: true
};
 
zfs-filesystem.zfs.unmount(opts, function (err, output) {
    console.log(output);
});

Initiates a send of a given snapshot and returns a readable stream. All possible options can be found inside the lib/zfs.js file.

var opts = {
    snapshot : '/pool/dataset@snapshot',
    verbose : true
};
 
zfs-filesystem.zfs.send(opts, function (err, sendStream) {
    sendStream.on('error', function (err) {
        console.error(err);
    });
 
    sendStream.on('verbose', function (data) {
        console.log(data);
    });
 
    sendStream.pipe(process.stdout).on('end', function () {
        console.log('done');
    });
});

Initiates a receive and returns a writable stream to which a send stream may be written. All possible options can be found inside the lib/zfs.js file.

var opts = {
    dataset : '/pool2/dataset',
    verbose : true
};
 
zfs-filesystem.zfs.receive(opts, function (err, receiveStream) {
    receiveStream.on('error', function (err) {
        console.error(err);
    });
 
    receiveStream.on('verbose', function (data) {
        console.log(data);
    });
 
    process.stdin.pipe(receiveStream).on('end', function () {
        console.log('done');
    });
});

Creates a new storage pool containing the virtual devices specified. All possible options can be found inside the lib/zpool.js file.

var opts = {
    name: 'my-datastore',
    devices: ['/dev/vdb', '/dev/vdc']
};
 
zfs-filesystem.zpool.create(opts, function (err, output) {
    console.log(output);
});

Adds the specified virtual devices to the given pool. All possible options can be found inside the lib/zpool.js file.

var opts = {
    name: 'my-datastore',
    devices: '/dev/vdd'
};
 
zfs-filesystem.zpool.add(opts, function (err, output) {
    console.log(output);
});

Sets the given property on the specified pool. See the zpool manpage for possible options and values.

var opts = {
    name: 'my-datastore',
    property: 'comment',
    value: 'Added some comment to a datastore'
};
 
zfs-filesystem.zpool.set(opts, function (err, output) {
    console.log(output);
});

Destroys the given pool, freeing up any devices for other use.

var opts = {
    name: 'my-datastore',
};
 
zfs-filesystem.zpool.destroy(opts, function (err, output) {
    console.log(output);
});

Lists the given pools along with a health status and space usage. If no pools are specified, all pools in the system are listed.

zfs-filesystem.zpool.list(function (err, output) {
    console.log(output);
});

Retrieves the given list of properties. When no name and property specified, it shows all properties for all datastores. See the zpool manpage for possible options and values.

zfs-filesystem.zpool.get(function (err, output) {
    console.log(output);
});

MIT