7

I'm installing a program on my Linux server and it stores data locally for a week. However, there is an error that can occur sometimes that will keep it from deleting the data.

To safeguard against this when I installed it on a Unix server I just create a new filesystem of the specified size. However, the filesystem on my linux server was created to have the full partition. Is there some way to set the maximum size for a directory?

Additionally if these was free space in the partition, would it be better to create a new filesystem, or use the above restrictions.

Thanks, Alex

Buzkie
  • 195
  • 4
  • 11

2 Answers2

4

I'm not sure of a way to limit the size of a single directory. You could create a new user, assign a quota to them, and then run the process under that user, but I'm guessing that's not what you're after.

As you hint at, you can create a filesystem as a "file" and mount it as the output directory for this app. This would ensure it never spills over to your regular filesystem:

dd if=/dev/zero of=~/disk_image_file count=$size_in_blocks
mkfs -t ext3 -q ~/disk_image_file
mkdir -p ~/mnt/app1/log
mount -o loop=/dev/loop0 ~/disk_image_file ~/mnt/app1/log
Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
  • Yeah. I was figuring that if no one at work was suggesting it, it probably didn't exist, but it was worth a shot. Thanks for the code. -Alex – Buzkie Jan 21 '10 at 16:17
  • Thx. See also http://stackoverflow.com/questions/8148715/how-to-set-limit-on-directory-size-in-linux#8148831 and http://souptonuts.sourceforge.net/quota_tutorial.html. – Jérôme Aug 28 '16 at 20:11
2

You're looking for quotas. Yes, it is entirely possible to implement quotas on most if not all unix filesystems.

Here's what you should read: http://www.faqs.org/docs/Linux-mini/Quota.html You shouldn't need to do any kernel config. Any vaguely modern system will likely have this enabled already by the distribution.

Come back if you have problems.

dotplus
  • 1,230
  • 7
  • 12
  • 1
    Thanks for the suggestion, I was looking into that while waiting for answers. The main problem with quotas is I can't be sure what user the program is running as. In addition, it defaults to run as root, and if I'm deploying to a machine with shared root, I don't want to put a quota on root. – Buzkie Jan 21 '10 at 16:08