4

I am using apt-mirror to create a local Ubuntu mirror. It does succeed in downloading files from another mirror (there's about a couple gigabytes each week), but never removing anything or indicates files that can be deleted. I might run out of free space, eventually.

The output of apt-mirror always include

0.0 bytes in 0 files and 0 directories can be freed.

Run /var/spool/apt-mirror/var/clean.sh for this purpose.

The clean.sh is ran every time apt-mirror executes, because the content of /var/spool/apt-mirror/var/postmirror.sh is just

/var/spool/apt-mirror/var/clean.sh

Running clean.sh produces this output:

Removing 0 unnecessary files [0 bytes]... done.

Removing 0 unnecessary directories... done.

Here's my mirror.list file:

############# config ##################
#
# set base_path    /var/spool/apt-mirror
#
# set mirror_path  $base_path/mirror
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch  <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

deb-i386 http://ubuntu.c3sl.ufpr.br/ubuntu/ trusty main restricted universe multiverse 
deb-i386 http://ubuntu.c3sl.ufpr.br/ubuntu/ trusty-updates main restricted universe multiverse 
deb-i386 http://ubuntu.c3sl.ufpr.br/ubuntu/ trusty-backports main restricted universe multiverse 
deb-i386 http://ubuntu.c3sl.ufpr.br/ubuntu/ trusty-security main restricted universe multiverse 

deb-amd64 http://ubuntu.c3sl.ufpr.br/ubuntu/ trusty main restricted universe multiverse 
deb-amd64 http://ubuntu.c3sl.ufpr.br/ubuntu/ trusty-updates main restricted universe multiverse 
deb-amd64 http://ubuntu.c3sl.ufpr.br/ubuntu/ trusty-backports main restricted universe multiverse 
deb-amd64 http://ubuntu.c3sl.ufpr.br/ubuntu/ trusty-security main restricted universe multiverse 

clean http://archive.ubuntu.com/ubuntu

1 Answer 1

8

Solution:

Change the last line to:

clean http://ubuntu.c3sl.ufpr.br/ubuntu/

Explanation:

The problem is in your last line where it defines what repository to clean. clean takes the name of the repository in which it should remove:

## Parse config

open CONFIG, "<$config_file" or die("apt-mirror: can't open config file ($config_file)");
while (<CONFIG>)
{
    ## Here we detect the line starting with "clean" and process the URL
    if ( $config_line eq "clean" )
    {
        $config_line[0] =~ s[^(\w+)://][];
        $config_line[0] =~ s[/$][];
        $config_line[0] =~ s[~][%7E]g if get_variable("_tilde");
        $clean_directory{ $config_line[0] } = 1;
        next;
    }
    die("apt-mirror: invalid line in config file ($.: $config_line ...)");
}
## we store the results in the "clean_directory" variable, now we will
## loop through all of them:
foreach ( keys %clean_directory )
{
    process_directory($_) if -d $_ && !-l $_;
}
## and proceed to take the actions:
sub process_directory
{
    my $dir       = shift;
    my $is_needed = 0;
    return 1 if $skipclean{$dir};
    opendir( my $dir_h, $dir ) or die "apt-mirror: can't opendir $dir: $!";
    foreach ( grep { !/^\.$/ && !/^\.\.$/ } readdir($dir_h) )
    {
        my $item = $dir . "/" . $_;
        $is_needed |= process_directory($item) if -d $item && !-l $item;
        $is_needed |= process_file($item)      if -f $item;
        $is_needed |= process_symlink($item)   if -l $item;
    }
    closedir $dir_h;
    push @rm_dirs, $dir unless $is_needed;
    return $is_needed;
}

The directories where the files are stored are in the form of /var/spool/apt-mirror/mirror/mirror.domain, so to decide what directories to clean, it should match any of these directories, if it doesn't then do nothing.

That's why changing the url to match the others is the solution.

3
  • if i have wheezy and jessie under the same url how do i delete only one of them without affecting the other ? : ftp.de.debian.org/debian wheezy main | ftp.de.debian.org/debian jessie main
    – Asaf Magen
    Feb 9, 2017 at 17:12
  • @AsafMagen what are you doing exactly? If you don't want wheezy on your mirror, simply don't list it.
    – Braiam
    Feb 9, 2017 at 17:28
  • im hosting debian 7 and debain 8 repo and now i dont need 7 anymore and want to free up the space its packages are taking. so simly remove it from apt-mirror.list will free the space ?
    – Asaf Magen
    Feb 9, 2017 at 18:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .