[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: space-limiting /var/cache/apt/archives



On Fri, Oct 15, 2004 at 12:33:07PM -0400, Derrick Hudson wrote:
> One solution would be to make that directory a separate file system.
> Then when the filesystem's space is consumed apt won't be able to
> exceed that limit.

I wonder how hard apt would crash when it hits the limit. I have hopes
that it will handle this gracefully, but it won't be installing any
more packages at that moment.

> | Actually, having the previous version of any installed package around 
> |  is *quite* useful. Especially since I'm using unstable. So this isn't 
> |  what I'm looking for.
> | 
> | Hmm, maybe I'll have to hack up a little shell-script to regularly 
> |  clean out...
> 
> Run 'aptitude autoclean' or 'aptitude clean' when desired.  Instead of
> a shell script, just put that one line in a crontab to run it
> automatically.

But the original poster is right that this may not be desired. Having
an older package around as replacement for a bug-ridden new one can be
a life saver.

Here's a little script that can be a beginning.

#! /bin/sh
MAXSIZE=700 # CD-Rom size. You may want something else here
APTCACHE="/var/cache/apt/archives/"
SIZE=`du -s -m $APTCACHE | cut -f1`
if test $SIZE -gt $MAXSIZE; then
    echo "WARNING: too large: $SIZE"
else
    echo "OK: $SIZE"
fi


Instead of printing a warning you can remove stuff with `apt-get
autoclean' - sometimes you just have to clean up - or your own
homegrown package weeder. For example:

cd $APTCACHE
COUNT=3
# The number of packages to remove shall be three. One, two,
# three. Not to four shalt thou count...

# Remove the oldest packages:
for i in `ls -tr | head -$COUNT`; do rm "$i"; done
# Or remove the youngest packages, whatever you want:
for i in `ls -t | head -$COUNT`; do rm "$i"; done


Wait, I have another idea. First some test data. I have just one
version of every package. So for testing purposes I copied my abcde
and adduser packages to files with a name that indicates an older
version.

mauritsvanrees:/var/cache/apt/archives# ls | head -8
aalib1_1.4p5-22_i386.deb
abcde_1.1.21-1_all.deb   # bogus test file
abcde_2.1.21-1_all.deb
adduser_3.54_all.deb     # bogus test file
adduser_3.59_all.deb
anacron_2.3-10_i386.deb
apache-common_1.3.31-6_i386.deb
apache-utils_1.3.31-6_i386.deb

I'm not sure if it is absolutely required, but it seems that every
package name has the form

<packagename><underscore><version><blabla>

Are there package names that themselves have underscores, like
package_name_version_blabla? That would make it more troublesome.

I scan for files with the same package name. `uniq' is handy
here. Read the man page for details, but the following should give you
all the packages with duplicates. The oldest ones are listed:

mauritsvanrees:/var/cache/apt/archives# ls | uniq -t "_" -d -W 1
abcde_1.1.21-1_all.deb
adduser_3.54_all.deb

Hm, if you remove these, then this will have roughly the same effect
as the autoclean function (not totally). I copied abcde again for
testing. Now we count the duplicates. Working dir is still
/var/cache/apt/archives.

# ls | sort -g | uniq -c -t "_" -d -W 1
      3 abcde_1.0.21-1_all.deb
      2 adduser_3.54_all.deb

The `sort -g' shouldn't be necessary, but let's stay on the safe side.
Now grep any package that has more than 2 versions available:

# ls | sort -g | uniq -c -t "_" -d -W 1 | grep -v -E "^[[:blank:]]*2 "
      3 abcde_1.0.21-1_all.deb

Now you can select that package, without the count:

# ls | sort -g | uniq -c -t "_" -d -W 1 | grep -v -E "^[[:blank:]]*2 " | \
sed "s/ *[[:digit:]*] \(.*\)$/\1/g"
abcde_1.0.21-1_all.deb

Now you have a list of packages that you can remove. In the beginning
you should do this by hand. Once you trust it, you can put it in a
script.

Ah, combining ls, sort, uniq, grep and sed in one line: you gotta love
the GNU toolchain. :-D

(Disclaimer: use at your own risk.)

-- 
Maurits van Rees | http://maurits.vanrees.org/ [Dutch/Nederlands]
"Let your advance worrying become advance thinking and planning."
 - Winston Churchill



Reply to: