Home -- Contact -- Site Map

Saturday, October 17, 2009

Huge Log Files

Problem:
-- The VM has limited space
-- You're getting a filesystem full error message
-- A log file has gotten ridiculously large (1.5GB in my case)


Details:
-- FreeBSD system 6.2-STABLE



Oct 9 06:00:00 system kernel: pid 13311 (dd), uid 2 inumber 47118 on /var: filesystem full


%df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/ad0s1a 496M 64M 392M 14% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/ad0s1e 496M 26K 456M 0% /tmp
/dev/ad0s1f 9.7G 2.2G 6.7G 25% /usr
/dev/ad0s1d 1.9G 1.8G -2.8M 100% /var


%ls -alh
total 1720980
drwxr-xr-x 3 root wheel 1.5K Oct 9 03:01 .
drwxr-xr-x 24 root wheel 512B Oct 8 16:50 ..
....
-rw-r--r-- 1 root wheel 1.4G Oct 9 07:02 httpd-access.log
-rw-r--r-- 1 root wheel 247M Oct 8 22:53 httpd-error.log


Solutions:
-- Backup, remove, and recreate the files
-- Backup and use the built in tool: truncate
-- Delete everything.

Let's do it:
the filesystem full error message will tell you which filesystem is full, to view details about your other filesystems use the df command

%df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/ad0s1a 496M 64M 392M 14% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/ad0s1e 496M 26K 456M 0% /tmp
/dev/ad0s1f 9.7G 2.2G 6.7G 25% /usr
/dev/ad0s1d 1.9G 1.8G -2.8M 100% /var


Looks like our /var directory is full. There are few things, that I know of, that would grow and cause this directory to fill; the log files.

use the cd command to cd to the directory the logs are located at

%cd /var/log/


use the list command with the proper flags to view files and their human-readable sizes

%ls -alh
total 1720980
drwxr-xr-x 3 root wheel 1.5K Oct 9 03:01 .
drwxr-xr-x 24 root wheel 512B Oct 8 16:50 ..
....
-rw-r--r-- 1 root wheel 1.4G Oct 9 07:02 httpd-access.log
-rw-r--r-- 1 root wheel 247M Oct 8 22:53 httpd-error.log


Looks like we have some pretty large files there, the G means gigabytes and the M means megabytes. While it is generally believed that bigger is better this is a bit much.
We can either delete these two files and recreate them or shave off some of the extra fluff.

Take a quick look at the manual page for truncate. Then put on your robe and wizard's hat. Once you're set You can speak the magic words:

truncate -c -s -900m httpd-access.log


And this should chop your file down a fair bit. You can keep using this command and modify the number until you get the file down to what you feel is a reasonable size.

%ls -alh
total 1720980
drwxr-xr-x 3 root wheel 1.5K Oct 11 00:00 .
drwxr-xr-x 24 root wheel 512B Oct 10 18:14 ..
....
-rw-r--r-- 1 root wheel 7.5M Oct 11 00:25 httpd-access.log
-rw-r--r-- 1 root wheel 7.3M Oct 11 00:17 httpd-error.log


All that's left now is to take off the robe and wizard's hat....and put it all away...
 
::Site Map::.....
    ♥Multi-Media
  • Photography
    • Sceanery
    • Commisioned
    • Wildlife
    • Miscellaneous
  • Graphics
    • 3D still renders
    • 'Shopped
    • WallPapers
    • Miscellaneous
  • Videos
    • 3D animetions
    • In r/l
    • pro-ductions
    • Miscellaneous
  • Audio
    • Sound Bites
    • Dope beats
    • Miscellaneous
    ♥Projects
  • Web
    • Jinkaku.net
    • This site
    Desktop
    • None now
    ♥About
  • Me
    • Education
    • Work EXP.
  • The Site
    • Design
    • Statistics
    ♥Language
  • Japanese
    • Phrases
    • Tips 'n tricks
    • vocabulary
  • Spanish
    • Phrases
    • Tips 'n tricks
    • vocabulary
  • Korean
    • Phrases
    • Tips 'n tricks
    • vocabulary
    ♥Miscellaneous
  • Links
    • Educational
    • Humor
    • cohorts
  • Badges