19 квітня 2018 р.

FreeNAS, ZFS, User Quota, Samba

Task: Apply ZFS user quota to Smaba

Source:

zpool with samba user home folders: poolz2/smbhome

Allow request about quota for everyone:
zfs allow everyone userquota,userused poolz2/smbhome 

Set usrer quota 120G for domain user : DOMAIN\username
zfs set userquota@"DOMAIN\username"=120G poolz2/smbhome

Tune SAMBA,  /usr/local/etc/smb4.conf:
get quota command = /root/script/quota_get.sh %U

Reload SAMBA:
killall -HUP smbd 

Soulution:

Script for get quota data: /root/scripts/quota_get.sh
#!/bin/sh
rtype=$3
if [ "${rtype}" == -1 ]; then
 exit
fi
poolname="poolz2/smbhome"
username=$1
if [ ! -z  "$username" ]; then
 info=`zfs userspace -Hp ${poolname}  | grep -i ${username} `;
 usedbytes=`echo ${info}| awk '{ printf "%.f", $4/1024 };'`;
 quotabytes=`echo ${info}| 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




Коли забув ти рідну мову, біднієш духом ти щодня...
When you forgot your native language you would become a poor at spirit every day ...

Д.Білоус / D.Bilous
Рабів до раю не пускають. Будь вільним!

ipv6 ready