action=purge delete latest backup, not the oldest one ?
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
mylvmbackup |
New
|
Undecided
|
Lenz Grimmer |
Bug Description
line 363 : my $item = pop @existingbackups;
pop should be replace by "shift"
in my case :
[root@xxxxxxxx ~]# ls -al /data/backup-mysql/
total 24
drwxr-xr-x 6 root root 4096 Jun 1 08:10 .
drwxr-xr-x 8 root root 4096 May 28 14:14 ..
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-
code extracted from mylvmbackup 0.16
#!/usr/bin/perl -w
use Config::IniFiles;
use Date::Format;
use DBD::mysql;
use DBI;
use File::Basename;
use File::Copy;
use File::Copy:
use File::Path;
use File::Temp qw/ mkstemps mktemp /;
use Getopt::Long;
use Sys::Hostname;
use Fcntl;
use diagnostics;
use strict;
my $backupretention = 3;
my $backupdir = "/data/
my @existingbackups;
my %files;
# Gather list of files and time stamps (mtime), exclude dot files
opendir(my $DH, $backupdir) or die "Error opening $backupdir: $!";
%files = map { $_ => (stat("
closedir($DH);
# Sort by mtime
@existingbackups = sort { $files{$b} <=> $files{$a} } (keys %files);
print "@existingbacku
while ($#existingback
my $item = pop @existingbackups;
print "$item\n";
}
[root@xxxxxx ~]# ./toto
backup-
backup-
we can see that the latest backup will be deleted ...
if we replace "pop" by "shift"
[root@xxxxxxxxx ~]# ./toto
backup-
backup-
the oldest backup will be deleted ...
Thanks for the report. Hmm, the output of "ls -al /data/backup- mysql/" above indicates that all backup files have the same time stamp ("Apr 10 14:05").
Could you please check the output of "ls -altr /data/backup- mysql") , to display the files ordered by modification time?
Note that the Perl script sorts by modification time, not the time stamp in the file name.