-
Notifications
You must be signed in to change notification settings - Fork 4
/
remove_old_builds.pl
51 lines (42 loc) · 1.05 KB
/
remove_old_builds.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl -w
use strict;
if(@ARGV == 0){
die "Usage\t[keep:1..2]|[remove:2..3]\n";
}
my $buildDir='/opt/server/gwb.nixbioinf.org/build';
my %requests;
foreach my $arg(@ARGV){
if($arg=~/\[((?:keep)|(?:remove)):([0-9]+)\.\.([0-9]+)\]/){
my $key=$1;
my $from=$2;
my $to=$3;
for(my $i=$from;$i<=$to;$i++){
$requests{$key}->{$i}=1;
}
}elsif($arg=~/\[((?:keep)|(?:remove)):([0-9]+)/){
$requests{$1}->{$2}=1;
}
}
foreach my $removeItem(keys %{$requests{'remove'}}){
if(exists $requests{'keep'}->{$removeItem}){
delete $requests{'remove'}->{$removeItem};
}
}
print "Builds that are not removed or kept explicitly are not deleted\n";
foreach my $key(keys %requests){
my @items=keys %{$requests{$key}};
print "$key\[ @items";
if(@items>1){
print join(",",@items);
}else{
print $items[0];
}
print "]\n";
}
print "Press Ctrl+C if you wish to abort in the next ten seconds\n";
sleep(10);
foreach my $remove(keys %{$requests{'remove'}}){
my $pathToRemove="$buildDir/$remove";
print "Removing $pathToRemove\n";
`rm -r $pathToRemove`;
}