From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v4 manager 5/7] make use of archive_info and archive_remove
Date: Thu, 9 Jul 2020 14:45:45 +0200 [thread overview]
Message-ID: <20200709124547.2913-6-f.ebner@proxmox.com> (raw)
In-Reply-To: <20200709124547.2913-1-f.ebner@proxmox.com>
to avoid some code duplication.
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
PVE/VZDump.pm | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index 601cd56e..2f509555 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -631,10 +631,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;
}
}
@@ -927,15 +932,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);
}
}
}
--
2.20.1
next prev parent reply other threads:[~2020-07-09 12:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-09 12:45 [pve-devel] [PATCH-SERIES v4] fix #2649: introduce prune-backups property for storages supporting backups Fabian Ebner
2020-07-09 12:45 ` [pve-devel] [PATCH v4 storage 1/7] Introduce prune-backups property for directory-based storages Fabian Ebner
2020-07-24 17:07 ` [pve-devel] applied: " Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 storage 2/7] Add prune_backups to storage API Fabian Ebner
2020-07-24 17:07 ` [pve-devel] applied: " Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 storage 3/7] Add API and pvesm call for prune_backups Fabian Ebner
2020-07-13 7:04 ` Fabian Ebner
2020-07-24 17:08 ` Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 guest-common 4/7] Add prune-backups option to vzdump parameters Fabian Ebner
2020-08-20 15:39 ` [pve-devel] applied: " Thomas Lamprecht
2020-07-09 12:45 ` Fabian Ebner [this message]
2020-08-21 11:31 ` [pve-devel] applied: [PATCH v4 manager 5/7] make use of archive_info and archive_remove Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 manager 6/7] Allow prune-backups as an alternative to maxfiles Fabian Ebner
2020-07-09 12:45 ` [pve-devel] [PATCH v4 manager 7/7] Always use prune-backups instead of maxfiles internally Fabian Ebner
2020-08-21 11:33 ` Thomas Lamprecht
2020-08-24 7:25 ` Fabian Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200709124547.2913-6-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox