← Back to team overview

enterprise-support team mailing list archive

[Bug 1460524] [NEW] action=purge delete latest backup, not the oldest one ?

 

Public bug reported:

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 ...

** Affects: mylvmbackup
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Server/Client Support Team, which is subscribed to MySQL.
Matching subscriptions: Ubuntu Server/Client Support Team
https://bugs.launchpad.net/bugs/1460524

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

To manage notifications about this bug go to:
https://bugs.launchpad.net/mylvmbackup/+bug/1460524/+subscriptions


Follow ups

References