action=purge delete latest backup, not the oldest one ?

Bug #1460524 reported by gdegoulet
6
This bug affects 1 person
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-20150529_021701_mysql
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-20150530_021701_mysql
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-20150531_021702_mysql
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-20150601_080758_mysql

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::Recursive qw/ rcopy /;
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/backup-mysql" ;
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("$backupdir/$_"))[9] } grep(! /^\./, readdir($DH));
  closedir($DH);

  # Sort by mtime
  @existingbackups = sort { $files{$b} <=> $files{$a} } (keys %files);

print "@existingbackups\n";

while ($#existingbackups+1 > $backupretention) {
 my $item = pop @existingbackups;
 print "$item\n";
}

[root@xxxxxx ~]# ./toto
backup-20150531_021702_mysql backup-20150529_021701_mysql backup-20150530_021701_mysql backup-20150601_080758_mysql
backup-20150601_080758_mysql

we can see that the latest backup will be deleted ...

if we replace "pop" by "shift"
[root@xxxxxxxxx ~]# ./toto
backup-20150531_021702_mysql backup-20150529_021701_mysql backup-20150530_021701_mysql backup-20150601_080758_mysql
backup-20150531_021702_mysql

the oldest backup will be deleted ...

Revision history for this message
Lenz Grimmer (lenzgr) wrote :

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.

Changed in mylvmbackup:
assignee: nobody → Lenz Grimmer (lenzgr)
Revision history for this message
gdegoulet (z-launchpad-degoulet-net) wrote :

all subdirectories from /data/backup-mysql/ have the same timestamp because we use rsync method : Apr 10 14:05 is the creation date from the directory where the lvm is mounted.

[root@xxxxxxx ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 1965904 566520 1294528 31% /
tmpfs 8149472 4 8149468 1% /dev/shm
/dev/sda3 1965904 3208 1857840 1% /tmp
/dev/sda5 1455088 2256 1376032 1% /home
/dev/sda6 5963328 1788740 3860016 32% /usr
/dev/sda7 4947584 220084 4465356 5% /var
/dev/mapper/ssd-mysql
                     2219346368 23874960 2195471408 2% /mysql
/dev/sdb1 5661199984 95052592 5566147392 2% /data

[root@timeserix ~]# ls -al /mysql/
total 262308
drwxr-xr-x 6 mysql mysql 4096 Apr 10 14:05 .
drwxr-xr-x 26 root root 4096 Jun 2 01:18 ..
drwxr-xr-x 6 mysql mysql 126976 Jun 2 08:28 database
-rw-rw---- 1 mysql mysql 134217728 Jun 2 01:32 ib_logfile0
-rw-rw---- 1 mysql mysql 134217728 Jun 2 01:32 ib_logfile1
drwx------ 2 root root 16384 Apr 9 13:35 lost+found
drwx--x--x 2 mysql mysql 4096 Sep 5 2007 mysql
-rw-rw---- 1 mysql mysql 5 Apr 10 14:05 mysqld.pid
srwxrwxrwx 1 mysql mysql 0 Apr 10 14:05 mysql.sock
drwxr-xr-x 2 mysql mysql 4096 May 28 13:49 tmp

you can see that /mysql creation/modification timestamp is Apr 10 14:05

[root@xxxxxxx backup-mysql]# ls -alrt
total 24
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-20150602_021701_mysql
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-20150601_080758_mysql
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-20150530_021701_mysql
drwxr-xr-x 8 mysql mysql 4096 Apr 10 14:05 backup-20150529_021701_mysql
drwxr-xr-x 8 root root 4096 May 28 14:14 ..
drwxr-xr-x 6 root root 4096 Jun 2 02:19 .

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.