2021-04-12 14:40:45 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-04-12 17:56:12 -05:00
|
|
|
# 2014 Dave Bechtel
|
2021-04-12 14:40:45 -05:00
|
|
|
|
2021-04-12 17:56:12 -05:00
|
|
|
# cre8 a new ZFS dataset with options and loggit
|
|
|
|
echo "$0 opt1=(1)compression opt2=(1)sharesmb, 0 == OFF zpool dirname"
|
|
|
|
echo "Example: $0 11 zpoolname datasetname"
|
|
|
|
echo "== create zpoolname/datasetname as Shared Samba dataset with recordsize 1M and set owner"
|
2021-04-12 14:40:45 -05:00
|
|
|
|
|
|
|
# TODO -e /tmp/infile read it and process it
|
|
|
|
|
2021-04-12 17:56:12 -05:00
|
|
|
logfile=~/boojum-zfs-newds.log
|
2021-04-12 14:40:45 -05:00
|
|
|
|
2021-04-12 17:56:12 -05:00
|
|
|
#source ~/bin/failexit.mrg
|
|
|
|
# failexit.mrg
|
|
|
|
function failexit () {
|
|
|
|
echo '! Something failed! Code: '"$1 $2" |tee -a $logfile # code # (and optional description)
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
# xxx TODO editme
|
2021-04-12 14:40:45 -05:00
|
|
|
#zp=zredpool2; myds=home/vmtmpdir/vmware-virtmachines
|
|
|
|
zp="$2"; myds="$3"
|
|
|
|
user=dave
|
2021-04-12 17:56:12 -05:00
|
|
|
# this is for chown later
|
2021-04-12 14:40:45 -05:00
|
|
|
|
|
|
|
# defaults
|
2021-04-12 17:56:12 -05:00
|
|
|
dcompr=lz4
|
|
|
|
#dcompr=zstd-2 ## for zfs 2.0.x
|
|
|
|
dshrwin=off
|
2021-04-12 14:40:45 -05:00
|
|
|
|
|
|
|
# opt1=compression, opt2=sharesmb
|
|
|
|
case "$1" in
|
|
|
|
"10" )
|
|
|
|
# use defaults
|
2021-04-12 17:56:12 -05:00
|
|
|
compr=$dcompr; shrwin=$dshrwin
|
2021-04-12 14:40:45 -05:00
|
|
|
;;
|
|
|
|
"11" )
|
2021-04-12 17:56:12 -05:00
|
|
|
compr=$dcompr; shrwin="on -o xattr=sa"
|
|
|
|
# NOTE xattr=sa may not work in older versions of freebsd
|
2021-04-12 14:40:45 -05:00
|
|
|
;;
|
|
|
|
"01" )
|
2021-04-12 17:56:12 -05:00
|
|
|
compr=off; shrwin="on -o xattr=sa"
|
2021-04-12 14:40:45 -05:00
|
|
|
;;
|
|
|
|
"00" )
|
|
|
|
compr=off; shrwin=off
|
|
|
|
;;
|
|
|
|
"" )
|
|
|
|
# no arg passed; bash NOP ref: https://stackoverflow.com/questions/17583578/what-command-means-do-nothing-in-a-conditional-in-bash
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "WNG: Invalid arg passed, +$1+ not recognized"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# trace on
|
|
|
|
(set -x
|
|
|
|
zfs create -o \
|
2021-04-12 17:56:12 -05:00
|
|
|
atime=off -o compression=$compr -o sharesmb=${shrwin} -o recordsize=1024k \
|
2021-04-12 14:40:45 -05:00
|
|
|
$zp/$myds || failexit 99 "! Failed to create ZFS $zp/$myds"
|
|
|
|
)
|
|
|
|
|
2021-04-12 17:56:12 -05:00
|
|
|
echo "$(date) + $zp/$myds + compr=$compr:shr=${shrwin} + Owner:$user" >> $logfile
|
2021-04-12 14:40:45 -05:00
|
|
|
|
|
|
|
# NOTE does not take into account alt.mountpoints like /home!
|
|
|
|
chown -v $user /$zp/$myds; ls -al /$zp/$myds
|
|
|
|
#df -h /$zp/$myds
|
2021-04-12 17:56:12 -05:00
|
|
|
df -hT |head -n 1
|
|
|
|
df -hT |grep $myds
|
2021-04-12 14:40:45 -05:00
|
|
|
|
|
|
|
exit;
|
|
|
|
|
2021-04-12 17:56:12 -05:00
|
|
|
This is not intended to be comprehensive, but should provide a good example
|