Managing quotas on mercury

Every user on mercury.it.swin.edu.au has one or more filesystem quotas.  This is to prevent any one user from consuming all the resources and preventing other users from accessing the system.

User Private Group Quota

Every user is allocated a unix group which is named the same as their username.  The only member of the group is that user.  This is called User Private Group or UPG.

This UPG is the default group for the user and except for the cases described below, will be the owner of any files created by the user.  This means that by default, a users files will contribute to the users private group quota.

Checking your group quota

The command "quota -g" will display a summary of the quotas and their current usage.  This command should be issued at the shell prompt (The $ or % sign)

[s123456@mercury s123456]$ quota -g
Disk quotas for group s123456 (gid 1234):
Filesystem blocks quota limit grace files quota limit grace
/dev/cciss/c0d1p3
           60012* 56320 61952 none  725   0     0

Reading your quota

The information from the quota -g command is show here in a table explaining how to read the output

Column Value Description
Filesystem /dev/cciss/c0d1p3 This is the name of the disk on which the quota is enabled.  For all users on mercury, this represents the /home directory and everything below that point.
blocks  60012* This is the number of blocks of storage currenty in use.  Blocks are 1 kilobyte in size (1024 bytes).  An easy way to read the blocks is to ignore the last 3 digits and treat the number as Megabytes. ie 60 Megabytes.

The * indicates that the user has exceeded their quota

quota  56320  This is the amount of storage allocated. This is the 'soft' limit which may be exceeded for no more than the grace period (7 days)
limit  61952  This is the hard limit amount of storage allocated. You can not exceed this limit. We normally set this at 10% above the soft limit.

Supplementary groups

Supplementary group quotas

1. Logging in

First of all you will need access to the team account. If you do not have access then the member of your team who has access should follow these instructions.

Log in to mercury as the team account.

2. Identify which files you need to take ownership of.

You can use some tools to help you do this.

$ find . -type f -not -user hit3058_nn

(Do not type the $, that is your prompt.  Put in your team user as the username).

If you have one or two files then you can take ownership manually, otherwise you can automate the process.

3. Take ownership

Assuming there was one file called "testfile" then you could take ownership like this:

$ cp testfile /tmp
$ cto testfile

The first command will copy the file to /tmp. This way if something goes wrong you have a backup. If all goes well with the second command you can delete the backup like this

$ rm /tmp/testfile

but remember to test the real file before you delete the backup.

The next command "cto" will take ownership of the file. This is done by making a new copy of the file and moving it to the original file so it is possible that some things could go wrong. Assuming all goes well you have an identical file owned by your team account. The only difference is that the time stamp will be different.

4. Processing many files

Start by making a backup of the directory you will be working on. In this example it will be the "cvs" directory

$ tar -cf /tmp/mycvsbackup.tar cvs

If you don't know how to use tar you should read the man page (man tar) or find a tutorial on the web.

Then you can process your file. cto can only process one file at a time so you need to use a loop. (This will work for up to about 1000 files) 

$ for i in $(find cvs -type f -not -user hit3058_nn) ; do cto "$i" ; done

Note how the find command from above has been reused. Instead of . (the current directory) the directory "cvs" has been specified as the starting directory. 

If you have lots and lots of files (> 1000) you can make find execute cto directly.

$ find cvs -type f -not -user hit3058_nn -exec "cto" "{}" ";"

In this example, the same find command is used but some extra parameters are added. -exec will run the following command for each file found. In this case the command is "cto". Then the magic parameter "{}" which find will substitute with the actual file name. Then to indicate the end of the parameters, the ";".

After you have taken ownership of the files, you can re-run the command from step 2 so make sure that there are no more files owned by the team members.

Appenxix I.  cto script

#!/bin/bash
# convoluted take ownership
#
# This script was written by John Newbigin
# Please make sure you backup your files before using it!
# You can only process one file at a time
# This script makes a copy of the file so some original properties will be lost (times etc)
# If you run out of quota then things will not be pretty

if [ -z "$1" ] ; then
   echo "Usage: $0 filename"
   echo "For more details please run"
   echo "head $0"
else

f=$1
if [ -f "$f" ] ; then
   if /sbin/fuser "$f" ; then
      echo "File $f is is use"
   else
      if [ -O "$f" ] ; then
         echo "You already own $f"
      else
         f2=$f.cto
         if [ -e "$f2" ] ; then
            echo "Looks like cto failed previously"
         else
            if touch "$f2" ; then
               if cat "$f" > "$f2" ; then
                  if cmp "$f" "$f2" ; then
                     chmod --reference="$f" "$f2"
                     rm -f "$f"
                     mv "$f2" "$f"
                  else
                     echo "Files are different!  cto will not continue.  Perhaps you are over quota!"
                     rm -f "$f2"
                  fi
               else
                  echo "You can't read the file"
               fi
            else
               echo "You can't create a file here"
            fi
         fi
      fi
   fi
else
   echo "$f is not a file"
fi

fi