#!/bin/bash

set -e
set -x



# device name or file path
DEVICE=usb-ST325062_0AS_98765432100C-0:0-part2

# pool and dataset names
POOL=test_pool
SET=test_set

# mountpoint for the pool
MOUNT=/mnt/zfs_test




# create pool
zpool create -f -m $MOUNT -o ashift=12 $POOL $DEVICE

# create encrypted dataset
dd if=/dev/urandom of=/tmp/key bs=32 count=1
zfs create -o sync=disabled -o atime=off -o encryption=on -o keyformat=raw -o keylocation=file:///tmp/key $POOL/$SET

#mount -t zfs -o noatime $POOL/$SET $MOUNT/$POOL/$SET

# write some files to the dataset
for i in {1..10}
do
	dd if=/dev/urandom bs=1M count=100 of=$MOUNT/$SET/$i 2>/dev/null
done

# list contents of $SET
ls $MOUNT/$SET



# export pool
zpool export $POOL

# import pool back
zpool import $POOL



# list contents of $SET
ls $MOUNT/$SET
