Disk Quotas is the most natural starting point in building a solid storage strategy. Setting quotas will easily let you:
– Show users what reasonable storage use is – define an upper limit.
– Allow storage to grow in a controlled and sustainable manner.
– Promote efficient usage and streamline backup/restore times.
This script will set a quota directory on the Novell Storage Services for Novell Open Enterprise Server 11.
Usage:
./sdq.sh /media/nss/VOLUMENAME size
Please, mind that the size must be in KB! The quota will be set to all directories on the HOME volume. If you do not want to set a quota for a particular directories, please add them to:
/etc/sysconfig/excludefromsdq.conf
in the form:
/media/nss/VOLUMENAME/directoryname/
/media/nss/VOLUMENAME/directory name 1/
Please, mind that the forward slash at the end of each line is required.
Okay, so now on you know how to use this script. Let say that you need to set a directory quota on OES11 server on NSS volume for about thousand directories in the form:
current size of a directory + 500MB and 500MB for directories which current size is lower than 500MB, so to do that please type the following:
sdq.sh /media/nss/HOME 500000
nbfs4:~ # sdq.sh /media/nss/HOME 500000
Running with the following options: ./sdq.sh /media/nss/HOME 500000
File /etc/sysconfig/excludefromsdq.conf exists.
500000 is greater than data 189952
Directory Quota on “/media/nss/HOME/desktop”:
quota : Unlimited
spaceUsed : 0.00 KB
Set quota for /media/nss/HOME/desktop/
Directory Quota on “/media/nss/HOME/desktop”:
quota : 488.28 MB
spaceUsed : 185.50 MB
Quota set to 500000 KB
Directory Quota on “/media/nss/HOME/desktop”:
quota : 488.28 MB
spaceUsed : 185.50 MB
Done for /media/nss/HOME/desktop/
Directory /media/nss/HOME/dontchange/ is excluded from quota
Directory Quota on “/media/nss/HOME/dontchange”:
quota : Unlimited
spaceUsed : 0.00 KB
Size of data 3741492 is greater than 500000
Directory Quota on “/media/nss/HOME/GW”:
quota : Unlimited
spaceUsed : 0.00 KB
Set quota for /media/nss/HOME/GW/
Directory Quota on “/media/nss/HOME/GW”:
quota : 4.05 GB
spaceUsed : 3.57 GB
Quota set to 4241492 KB
Directory Quota on “/media/nss/HOME/GW”:
quota : 4.05 GB
spaceUsed : 3.57 GB
Done for /media/nss/HOME/GW/
#!/bin/bash
########### Set a Directory Quota on OES11 ###############
# Version : 3.0
# Date : 07 October 2014
# Author : Gregor Spyra - gregor.spyra at securelinx.com
# Licence : GPL http://www.fsf.org/licenses/gpl.txt
##########################################################
# Many thanks to Eoghan Cotter for suggested corrections ;-)
#
# This script will set a quota directory on the Novell Storage Services for Novell Open Enterprise Server 11.
# In the form: current size of a directory + 500MB and 500MB for directories which current size is lower than 500MB.
#
# Usage:
#
# ./sdq.sh /media/nss/VOLUMENAME size
#
# Please, mind that the size must be in KB! The quota will be set to all directories on the HOME volume.
# If you do not want to set a quota for a particular directories, please add them to:
#
# /etc/sysconfig/excludefromsdq.conf
#
# in the form:
#
# /media/nss/VOLUMENAME/directoryname/
# /media/nss/VOLUMENAME/directory name 1/
#
# Please, mind that the forward slash at the end of each line is required.
########################################################
# This sets the IFS variable so that the .space. character
# is no longer an input field separator
IFS=$'nt'
# Check if the arguments are pass/set from a command line.
if [[ -n "$1" && -n "$2" ]]; then
echo "Running with the following options: ./sdq.sh $1 $2"
else
echo "Usage: ./sdq.sh /media/nss/VOLUMENAME SIZE"
echo "The size must be in KB!"
exit
fi
# volume path
vpath=$1
#quota size
quota=$2
# Check if the excludefromsdg.conf file exists,
# if not it will be created.
excludefromsdq="/etc/sysconfig/excludefromsdq.conf"
if [ -f "$excludefromsdq" ]; then
echo "File $excludefromsdq exists."
echo ""
else
echo "File $excludefromsdq does not exist."
touch "$excludefromsdq"
echo "So, it has been created."
echo ""
fi
# This is the function we use to set the Quota
# Wrapping all the directories in quotes in case anything has spaces in it, need to test that works
# Now handled by IFS=$'nt' but we still can use the quotas.
set_quota() {
nssquota -D -d "$2"
echo Set quota for "$2"
nssquota -D -d "$2" -s $1 KB
echo Quota set to $1 KB
nssquota -D -d "$2"
echo Done for "$2"
echo
}
# Get the directory list from Volume and set a quota,
# also exclude directories from a quota listed in excludefromsdq.conf
for dir in $(ls -d "$vpath"/*/) ; do
hit=0
while read line; do
# If directory is equal to an exclude directory then mark it as "hit"
if [ "$dir" == "$line" ]; then
hit=1
fi
done < $excludefromsdq
# The listed directory marked as "hit" is excluded from the quota
if [ "$hit" == "1" ]; then
echo "Directory $dir is excluded from quota"
nssquota -D -d "$dir"
echo ""
else
size=$(du -s "$dir" | awk '{print $1}')
if [ $size -gt $quota ]; then
echo "Size of data $size is greater than $quota"
size=$(($size+$quota))
set_quota $size "$dir"
else
echo "$quota is greater than data $size"
set_quota $quota "$dir"
fi
fi
done