]> git.proxmox.com Git - pve-manager.git/commitdiff
make use of archive_info and archive_remove
authorFabian Ebner <f.ebner@proxmox.com>
Thu, 9 Jul 2020 12:45:45 +0000 (14:45 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 20 Aug 2020 15:41:04 +0000 (17:41 +0200)
to avoid some code duplication.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/VZDump.pm

index 66a20c8c6ab59d5457344dd825d0317c5ae98aa6..6e0d3dbf73c05dae90a27bcc42c90145372cafe4 100644 (file)
@@ -633,10 +633,15 @@ sub get_backup_file_list {
     my $bklist = [];
     foreach my $fn (<$dir/${bkname}-*>) {
        next if $exclude_fn && $fn eq $exclude_fn;
-       if ($fn =~ m!/(${bkname}-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))$!) {
-           $fn = "$dir/$1"; # untaint
-           my $t = timelocal ($7, $6, $5, $4, $3 - 1, $2);
-           push @$bklist, [$fn, $t];
+
+       my $archive_info = eval { PVE::Storage::archive_info($fn) } // {};
+       if ($archive_info->{is_std_name}) {
+           my $filename = $archive_info->{filename};
+           my $backup = {
+               'path' => "$dir/$filename",
+               'ctime' => $archive_info->{ctime},
+           };
+           push @{$bklist}, $backup;
        }
     }
 
@@ -930,15 +935,13 @@ sub exec_backup_task {
                    $opts->{scfg}, $opts->{storage}, 'prune', $args, logfunc => $logfunc);
            } else {
                my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname, $task->{target});
-               $bklist = [ sort { $b->[1] <=> $a->[1] } @$bklist ];
+               $bklist = [ sort { $b->{ctime} <=> $a->{ctime} } @$bklist ];
 
                while (scalar (@$bklist) >= $maxfiles) {
                    my $d = pop @$bklist;
-                   debugmsg ('info', "delete old backup '$d->[0]'", $logfd);
-                   unlink $d->[0];
-                   my $logfn = $d->[0];
-                   $logfn =~ s/\.(tgz|((tar|vma)(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?))$/\.log/;
-                   unlink $logfn;
+                   my $archive_path = $d->{path};
+                   debugmsg ('info', "delete old backup '$archive_path'", $logfd);
+                   PVE::Storage::archive_remove($archive_path);
                }
            }
        }