Answer the question
In order to leave comments, you need to log in
How to remove many FreeBSD files?
I inherited a remote server on freebsd (8.2-RELEASE FreeBSD 8.2-RELEASE). Pretty old.
Initially, it was configured incorrectly, and the /var/spool/clientmqueue directory became so full that the system could not even get a listing. The disk space is 99% occupied. It is necessary to clear the directory, however, all methods known to me do not work - because they try to get a list of files as an argument and hang on it, eat up all the memory and the system crashes.
From what I've tried:
rm -r /var/spool/clientmqueue/
find . -type f -print -delete
However, in some strange way, mc was able to get the names of the first few files in the directory. I checked that the files on the direct path are opened, and after deletion they are not available.
Smart disk is fine. (if it matters).
Is there a way to get filenames and pass them as an argument to the rm command sequentially instead of all at once?
ZY sendmail disabled in rc.conf.
In general, another problem appeared - I started using the script
time perl -e 'opendir(D1, "/var/spool/clientmqueue/clientmqueue.old/") || die "Error: $!"; readdir(D1); while ($a=readdir(D1)) { print("$a"); ;unlink("$a");}'
It works well, doesn't eat up memory, deletes files (if run from the target directory). However, it causes a strong i / o on zfs from which the latter falls. Therefore, I added sleep and left it to work. while everything works, the truth will take forever, but at least it moves. It ended up like this:
time perl -e 'opendir(D1, "/var/spool/clientmqueue/clientmqueue.old/") || die "Error: $!"; readdir(D1); while ($a=readdir(D1)) { print("$a\n"); sleep(1);unlink("$a");}'
upd; sleep (1) - accepts only integer values as an argument, or rounds them up to an integer. Therefore, the minimum delay in the case of using sleep is 1 second.
This is too long - so I changed the delay method - using the select command with undefined first three arguments - it allows you to set the delay in microseconds. Playing with microseconds, you can find a value at which the server will not fall due to a large load on i / o - in the end it turned out like this:
time perl -e 'opendir(D1, "/var/spool/clientmqueue/clientmqueue.old/") || die "Error: $!"; readdir(D1); while ($a=readdir(D1)) { print("$a\n"); select(undef, undef, undef, 0.1); ;unlink("$a");}'
In this case, the delay is one tenth of a second, which speeds things up a bit.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question