-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathex_local.py
More file actions
51 lines (34 loc) · 1.16 KB
/
Copy pathex_local.py
File metadata and controls
51 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Basic example for accessing ZFS on local machine
# Test requirements:
# python-magic
import sys
import zfslib as zfs
from zfslib_ex_common import *
def main(argv):
# Read ZFS information from local computer
conn = zfs.Connection(host='localhost')
# Load poolset
poolset = conn.load_poolset()
# Get first dataset of the first pool
p = poolset.items[0]
all_datasets = p.get_all_datasets()
ds = all_datasets[0]
print('ds: {}'.format(ds))
# Get first snapshot in specific pool/dataset
p = poolset.get_pool('dpool')
ds = p.get_dataset('vcmain')
all_snaps = ds.get_all_snapshots()
if len(all_snaps) == 0:
print('No snapshots found for dataset: {}'.format(ds))
else:
print('First Snapshot for dataset {}: {}'.format(ds, all_snaps[0]))
# Find Snapshots of name autosnap* in the last 4 hours
snapshots = ds.find_snapshots({'name': 'autosnap*', 'tdelta': '4h'})
# Iterate through all pools and print all datasets
if False:
print("Pools and Datasets:")
for p in poolset:
print_all_datasets(p)
if __name__ == '__main__':
main(sys.argv[1:])
sys.exit(0)