1834772 Members
3302 Online
110070 Solutions
New Discussion

Re: Limiting file sizes

 
SOLVED
Go to solution
Mark Jones_1
Advisor

Limiting file sizes

Does anyone have any ideas regarding limiting the size of files within a VXFS file system? I want to be able to prevent files greater than a certain size being created, if possible.
10 REPLIES 10
Santosh Nair_1
Honored Contributor

Re: Limiting file sizes

This isn't quite what you wanted but how about putting a quota on the file system. It doesn't limit the size of any one file, but it does limit the amount of space a user has on the filesystem.

-Santosh
Life is what's happening while you're busy making other plans
Vincent Farrugia
Honored Contributor

Re: Limiting file sizes

Hello,

You can use ulimit -f . Type ulimit -a to see your new settings.

HTH,
Vince
Tape Drives RULE!!!
Steven Gillard_2
Honored Contributor

Re: Limiting file sizes

You can use "ulimit -Sf ". Eg to limit the size of files to 500k, run:

$ ulimit -Sf 1024
$ cp /stand/vmunix .
cp: bad copy to ./vmunix: write: File too large

Regards,
Steve
Vincent Farrugia
Honored Contributor

Re: Limiting file sizes

More info:

This will still create the file, however. But it will reach that limit only. So if you set it to 100 blocks, the file cannot grow more than that.

HTH,
Vince
Tape Drives RULE!!!
Mark Jones_1
Advisor

Re: Limiting file sizes

ulimit is fine, however I want to be able to make the change system-wide so that no files above a certain size can be created in a particular directory or filesystem. This also means that using disk quotas is out of the question.
Thanks,
Mark.
harry d brown jr
Honored Contributor

Re: Limiting file sizes

Although ulimit will work, it can cause you other headaches, like when a user process has to create a large file. Your best bet is to not allow users at the unix prompt, and restricting their access to file creating activities.

live free or die
harry
Live Free or Die
Mark Jones_1
Advisor

Re: Limiting file sizes

Users do not have access to the unix prompt; but this problem is associated with application processes that they run which sometimes loop and create very large log files. I simply need to prevent the files growing beyond a particular size. Once the filesystem fills, it prevents other user processes from running - hence the need to put a stop to these large files.
Thanks,
Mark.
Roger Baptiste
Honored Contributor
Solution

Re: Limiting file sizes

Mark,

<< I simply need to prevent the files growing beyond a particular size. Once the filesystem fills, it prevents other user processes from running - hence the need to put a stop to these large files>>

We run into this problem and the way i contain it is by creating separate filesystem(s) for the directories where the applications write their log files (or related output files) with the largefiles option turned off. That way, no file can be larger than 2Gb within the filesystem and if the filesystem gets full due to too many files, it does not affect other user processes, since it is a local filesystem.

eg: if appliction is writting to /prod/app/test1/log -> make this a filesystem.

HTH
raj
Take it easy.
Steven Gillard_2
Honored Contributor

Re: Limiting file sizes

Here's an idea that you may or may not be able to use, depending on the application and how it creates its log files:

- Create a named pipe in place of the applications log file. Hopefully the application will open this pipe as its log file and start writing messages to it.

- Have a process (perl/shell/C) that continually reads from this named pipe and writes the log messages to another file. You can then put logic into this script/program to control how large the log files can be, how they are rotated etc.

I've seen this method used to great effect on a system I used to look after. Be careful that the process reading from the pipe is stable, because if it dies it can cause your application to hang when the pipe fills up.

Regards,
Steve
Mark Jones_1
Advisor

Re: Limiting file sizes

I think that setting the log file directory as a separate file system and switching off the largefiles option is probably the way I will go.

Many thanks
Mark ;-)