File: //usr/local/directadmin/sync_mail_quotas.sh
#!/bin/bash
#############################################
# Sync Quota Limits to /home/mail Partition
# Run on DirectAdmin server
#
# Copies quota limits from /home to /home/mail
# so both partitions enforce the same limits
#############################################
echo "==========================================="
echo "Sync Quota Limits: /home -> /home/mail"
echo "==========================================="
SYNCED=0
SKIPPED=0
# Get all users with quotas on /home
repquota -u /home | tail -n +6 | while read user status blocks soft hard grace files fsoft fhard fgrace; do
# Skip header/empty lines
[ -z "$user" ] && continue
[[ "$user" == "#"* ]] && continue
[[ "$user" == "root" ]] && continue
[[ "$user" == "nobody" ]] && continue
# Remove -- or +- status indicator from user if attached
user=$(echo "$user" | sed 's/[-+]$//')
# Skip if no limit set on /home
if [ "$soft" -eq 0 ] && [ "$hard" -eq 0 ]; then
continue
fi
# Check if user has directory on /home/mail
if [ ! -d "/home/mail/$user" ]; then
continue
fi
# Set same limits on /home/mail
setquota -u "$user" "$soft" "$hard" "$fsoft" "$fhard" /home/mail 2>/dev/null
if [ $? -eq 0 ]; then
echo "[OK] $user - soft:${soft}KB hard:${hard}KB"
((SYNCED++))
else
echo "[FAIL] $user"
fi
done
echo ""
echo "==========================================="
echo "Sync Complete"
echo "==========================================="
echo ""
echo "Verify with:"
echo " repquota -u /home/mail | head -30"