Task: Apply ZFS user quota to Smaba
Source:
zpool with samba user home folders: poolz2/samba/usersAllow request about quota for everyone:
zfs allow everyone userquota,userused poolz2/samba/users
Set usrer quota 120G for domain user : DOMAIN\username
zfs set userquota@"DOMAIN\username"=120G poolz2/samba/users
Tune SAMBA, /usr/local/etc/smb4.conf:
get quota command = /mnt/poolz2/home/scripts/quota_get.sh %U %D
Reload SAMBA:
killall -HUP smbd
Or change via GUI of FreeNAS
Example of GUI of SMB Services (FreeNAS11.2), add quota. |
Soulution:
Script for get quota data: /mnt/poolz2/home/scripts/quota_get.sh#!/bin/sh rtype=$4 if [ "${rtype}" == -1 ]; then exit fi username=$1 if [ ! -z "$username" ]; then domainname=$2 requestpath=${PWD} DATASETNAME=`/bin/df -l ${requestpath} | /usr/bin/tail -n 1 | /usr/bin/awk '{ print $1 };'` info=`/sbin/zfs userspace -Hp ${DATASETNAME} | /usr/bin/grep -i ${domainname}'\\\\'${username}` usedbytes=`echo ${info}| /usr/bin/awk '{ printf "%.f", $4/1024 };'`; quotabytes=`echo ${info}| /usr/bin/awk '{ if ( $5 == "none" ) { print "0"} else { printf "%.f", $5/1024 } };'`; if [ "$quotabytes" != 0 ]; then echo 2 $usedbytes $quotabytes $quotabytes $usedbytes $quotabytes $quotabytes fi fi exit
Example of GUI of Sharing SMB (FreeNAS11.2). |
#!/bin/sh USERS_DATASET=poolz2/samba/users DOMAINNAME=SOMEDOMAIN DEFAULT_QUOTA=80G /sbin/zfs allow everyone userquota,userused ${USERS_DATASET} mountpoint=`/bin/df -l ${USERS_DATASET} | /usr/bin/tail -n 1 | /usr/bin/awk '{ print $6 };'` for file in ${mountpoint}/*; do USERNAME=$(/usr/bin/basename "$file") LOGON=${DOMAINNAME}\\${USERNAME} QUOTA=`/sbin/zfs get -H "userquota@${LOGON}" ${USERS_DATASET} | /usr/bin/awk '{ print $3 };'` #echo ${LOGON} : ${QUOTA} if [ "$QUOTA" == "none" ];then /sbin/zfs set "userquota@${LOGON}=${DEFAULT_QUOTA}" ${USERS_DATASET} #echo Was set default quota ${DEFAULT_QUOTA} for ${LOGON} fi done #/sbin/zfs userspace ${USERS_DATASET}
More:
Немає коментарів:
Дописати коментар