/usr/bin/expirebackups is in simplebackup 0.1.6-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #!/usr/bin/perl -w
#
# expirebackups - find old backups to be deleted
#
# Copyright (C) 2004,2006,2007,2008,2011 Christian Garbs <mitch@cgarbs.de>
# licensed under GNU GPL v2 or later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
use strict;
# parameter handling
die "usage:\n\t$0 [keep_this_many] <backup_path>\n" unless (@ARGV == 1 or @ARGV == 2);
my $keep_count = 4;
if (@ARGV == 2) {
$keep_count = shift @ARGV;
die "[keep_this_many] may only contain digits!\n" if ($keep_count =~ y/0-9//c);
}
my ($backup_path) = @ARGV;
$backup_path =~ s:/+$::;
# read file list
my (%backup, @keep, @delete);
opendir DIR, $backup_path or die "can't opendir() `$backup_path': $!\n";
foreach ( grep { -f "$backup_path/$_" } readdir(DIR) ) {
if ( /^((.+)-(\d{4})(\d{2})(\d{2})\.tar\.bz2)$/ ) {
push @{$backup{$2}}, {
'FILE' => $1,
'NAME' => $2,
'YEAR' => $3,
'MONTH' => $4,
'DAY' => $5,
'AGE' => (($3*13)+$4)*32+$5
}
}
}
closedir DIR or die "can't closedir() `$backup_path': $!\n";
foreach my $file (keys %backup) {
my @backup = @{$backup{$file}};
# sort newest first
@backup = sort {$b->{AGE} <=> $a->{AGE}} @backup;
# keep latest 4 entries
@keep = splice @backup, 0, $keep_count;
# sort oldest first
@backup = reverse @backup;
# print file list
print "$backup_path/$_->{FILE}\n" foreach (@backup);
}
|