Skip to content

Commit a88b516

Browse files
Update README.md
1 parent 4c1794a commit a88b516

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
11
# zfslib
22
ZFS Libraries for Python
3+
4+
This code is based on code from [fs-tools by Rudd-O](https://github.com/Rudd-O/zfs-tools) and is used as a sample of how to use his ZFS libraries to write your own utilities that work with ZFS DataSets / Snapshots.
5+
6+
See `test.py` for sample code
7+
8+
```python
9+
from connection import ZFSConnection
10+
11+
pool_name = 'rpool'
12+
ds_name = 'devel'
13+
14+
# Read ZFS information from local computer
15+
# Change properties as needed
16+
src_conn = ZFSConnection(host='localhost',properties=["name", "avail", "usedsnap", "usedds", "usedrefreserv", "usedchild", "creation"])
17+
18+
# Load pool
19+
pool = src_conn.pools.lookup(pool_name)
20+
21+
# Load dataset
22+
ds = pool.get_child(ds_name)
23+
24+
ds_name_full = f"{pool_name}/{ds_name}"
25+
26+
# Print datasets creation date
27+
print(f"{ds_name_full} creation date: {ds.get_creation()}")
28+
29+
# Grab Snapshots
30+
snapshots = ds.get_snapshots()
31+
32+
# Load snapshot by index or iterate and filter as required
33+
snap = snapshots[1]
34+
35+
# Get Snapshot Creation date
36+
print(f"{ds_name_full}@{snap.name} creation date: {ds.get_creation()}")
37+
38+
# Read property from DataSet / Snapshot
39+
print(f"{ds_name_full}@{snap.name} usedsnap: {snap.get_property('usedsnap')}")
40+
41+
42+
```

0 commit comments

Comments
 (0)