2015-04-19 23:25:52 +02:00
# Introduction
2018-11-09 19:24:36 +01:00
**go-libzfs** currently implements basic manipulation of ZFS pools and data sets. Plan is to add more in further development, improve documentation with more examples, and add more tests. _go-libzfs_ use libzfs C library and does not wrap OpenZFS CLI tools. Goal is to let easy using and manipulating OpenZFS form with in go, and tries to map libzfs C library in to go style package respecting golang common practice.
## Note
This golang package is only used and tested on Linux.
- Version tagged as v0.1 is latest used and compatible with ZFS On Linux version 0.6.5.x
- Version tagged as v0.2 is latest used and compatible with ZFS On Linux version 0.7.x
2015-04-19 23:25:52 +02:00
2015-04-20 10:49:01 +02:00
[![GoDoc ](https://godoc.org/github.com/bicomsystems/go-libzfs?status.svg )](https://godoc.org/github.com/bicomsystems/go-libzfs)
2015-04-19 23:25:52 +02:00
2015-04-19 23:33:10 +02:00
## Main features
- Creating, destroying, importing and exporting pools.
- Reading and modifying pool properties.
- Creating, destroying and renaming of filesystem datasets and volumes.
- Creating, destroying and rollback of snapshots.
- Cloning datasets and volumes.
- Reading and modifying dataset and volume properties.
2018-11-09 19:24:36 +01:00
- Send and receive snapshot streams
2015-04-19 23:33:10 +02:00
## Requirements:
2015-04-19 23:25:52 +02:00
2018-11-09 19:24:36 +01:00
- OpenZFS on Linux and libzfs with development headers installed.
- Developed using go1.9
2015-04-19 23:25:52 +02:00
2015-04-19 23:33:10 +02:00
## Installing
2015-04-19 23:25:52 +02:00
```sh
2015-04-20 10:55:04 +02:00
go get github.com/bicomsystems/go-libzfs
2015-04-19 23:25:52 +02:00
```
2015-04-19 23:33:10 +02:00
## Testing
2015-04-19 23:25:52 +02:00
```sh
# On command line shell run
2015-04-20 10:55:04 +02:00
cd $GOPATH/src/github.com/bicomsystems/go-libzfs
2015-04-19 23:25:52 +02:00
go test
```
2015-04-19 23:33:10 +02:00
## Usage example
2015-04-19 23:25:52 +02:00
```go
// Create map to represent ZFS dataset properties. This is equivalent to
// list of properties you can get from ZFS CLI tool, and some more
// internally used by libzfs.
props := make(map[ZFSProp]Property)
// I choose to create (block) volume 1GiB in size. Size is just ZFS dataset
// property and this is done as map of strings. So, You have to either
// specify size as base 10 number in string, or use strconv package or
// similar to convert in to string (base 10) from numeric type.
strSize := "1073741824"
2015-12-04 23:05:19 +01:00
props[DatasetPropVolsize] = Property{Value: strSize}
2015-04-19 23:25:52 +02:00
// In addition I explicitly choose some more properties to be set.
2015-12-04 23:05:19 +01:00
props[DatasetPropVolblocksize] = Property{Value: "4096"}
props[DatasetPropReservation] = Property{Value: strSize}
2015-04-19 23:25:52 +02:00
// Lets create desired volume
d, err := DatasetCreate("TESTPOOL/VOLUME1", DatasetTypeVolume, props)
if err != nil {
println(err.Error())
return
}
// Dataset have to be closed for memory cleanup
defer d.Close()
println("Created zfs volume TESTPOOL/VOLUME1")
```
## Special thanks to
- [Bicom Systems ](http://www.bicomsystems.com ) for supporting this little project and that way making it possible.
- [OpenZFS ](http://open-zfs.org ) as the main ZFS software collective.