[pve-devel] [PATCH storage v3 4/7] Fix: backup: ctime taken from stat
Alwin Antreich
a.antreich at proxmox.com
Wed Apr 8 12:25:59 CEST 2020
not the file name. The vzdump file was passed with the full path to the
regex. That regex captures the time from the file name, to calculate the
epoch.
As the regex didn't match, the ctime from stat was taken instead. This
resulted in the ctime shown when the file was changed, not when the
backup was made.
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
PVE/Storage/Plugin.pm | 3 ++-
test/test_list_volumes.pm | 16 ++++++++--------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 8c0dae1..0ab44ce 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -952,7 +952,8 @@ my $get_subdir_files = sub {
next if $fn !~ m!/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!;
my $format = $2;
- $info = { volid => "$sid:backup/$1", format => $format };
+ $fn = $1;
+ $info = { volid => "$sid:backup/$fn", format => $format };
if ($fn =~ m!^vzdump\-(?:lxc|qemu)\-(?:[1-9][0-9]{2,8})\-(\d{4})_(\d{2})_(\d{2})\-(\d{2})_(\d{2})_(\d{2})\.${format}$!) {
my $epoch = timelocal($6, $5, $4, $3, $2-1, $1 - 1900);
diff --git a/test/test_list_volumes.pm b/test/test_list_volumes.pm
index 4b3fdb7..169c8be 100644
--- a/test/test_list_volumes.pm
+++ b/test/test_list_volumes.pm
@@ -106,9 +106,9 @@ my @tests = (
{ 'content' => 'images', 'ctime' => DEFAULT_CTIME, 'format' => 'qcow2', 'parent' => undef, 'size' => DEFAULT_SIZE, 'used' => DEFAULT_USED, 'vmid' => '16110', 'volid' => 'local:16110/vm-16110-disk-0.qcow2' },
{ 'content' => 'images', 'ctime' => DEFAULT_CTIME, 'format' => 'qcow2', 'parent' => undef, 'size' => DEFAULT_SIZE, 'used' => DEFAULT_USED, 'vmid' => '16110', 'volid' => 'local:16110/vm-16110-disk-1.qcow2' },
{ 'content' => 'images', 'ctime' => DEFAULT_CTIME, 'format' => 'qcow2', 'parent' => undef, 'size' => DEFAULT_SIZE, 'used' => DEFAULT_USED, 'vmid' => '16110', 'volid' => 'local:16110/vm-16110-disk-2.qcow2' },
- { 'content' => 'backup', 'ctime' => DEFAULT_CTIME, 'format' => 'vma.gz', 'size' => DEFAULT_SIZE, 'vmid' => '16110', 'volid' => 'local:backup/vzdump-qemu-16110-2020_03_30-21_11_40.vma.gz' },
- { 'content' => 'backup', 'ctime' => DEFAULT_CTIME, 'format' => 'vma.lzo', 'size' => DEFAULT_SIZE, 'vmid' => '16110', 'volid' => 'local:backup/vzdump-qemu-16110-2020_03_30-21_12_45.vma.lzo' },
- { 'content' => 'backup', 'ctime' => DEFAULT_CTIME, 'format' => 'vma', 'size' => DEFAULT_SIZE, 'vmid' => '16110', 'volid' => 'local:backup/vzdump-qemu-16110-2020_03_30-21_13_55.vma' },
+ { 'content' => 'backup', 'ctime' => 1585595500, 'format' => 'vma.gz', 'size' => DEFAULT_SIZE, 'vmid' => '16110', 'volid' => 'local:backup/vzdump-qemu-16110-2020_03_30-21_11_40.vma.gz' },
+ { 'content' => 'backup', 'ctime' => 1585595565, 'format' => 'vma.lzo', 'size' => DEFAULT_SIZE, 'vmid' => '16110', 'volid' => 'local:backup/vzdump-qemu-16110-2020_03_30-21_12_45.vma.lzo' },
+ { 'content' => 'backup', 'ctime' => 1585595635, 'format' => 'vma', 'size' => DEFAULT_SIZE, 'vmid' => '16110', 'volid' => 'local:backup/vzdump-qemu-16110-2020_03_30-21_13_55.vma' },
{ 'content' => 'snippets', 'ctime' => DEFAULT_CTIME, 'format' => 'snippet', 'size' => DEFAULT_SIZE, 'volid' => 'local:snippets/hookscript.pl' },
{ 'content' => 'snippets', 'ctime' => DEFAULT_CTIME, 'format' => 'snippet', 'size' => DEFAULT_SIZE, 'volid' => 'local:snippets/userconfig.yaml' },
],
@@ -124,9 +124,9 @@ my @tests = (
],
expected => [
{ 'content' => 'rootdir', 'ctime' => DEFAULT_CTIME, 'format' => 'raw', 'parent' => undef, 'size' => DEFAULT_SIZE, 'used' => DEFAULT_USED, 'vmid' => '16112', 'volid' => 'local:16112/vm-16112-disk-0.raw' },
- { 'content' => 'backup', 'ctime' => DEFAULT_CTIME, 'format' => 'tar.lzo', 'size' => DEFAULT_SIZE, 'vmid' => '16112', 'volid' => 'local:backup/vzdump-lxc-16112-2020_03_30-21_39_30.tar.lzo' },
- { 'content' => 'backup', 'ctime' => DEFAULT_CTIME, 'format' => 'tar.gz', 'size' => DEFAULT_SIZE, 'vmid' => '16112', 'volid' => 'local:backup/vzdump-lxc-16112-2020_03_30-21_49_30.tar.gz' },
- { 'content' => 'backup', 'ctime' => DEFAULT_CTIME, 'format' => 'tgz', 'size' => DEFAULT_SIZE, 'vmid' => '16112', 'volid' => 'local:backup/vzdump-lxc-16112-2020_03_30-21_59_30.tgz' },
+ { 'content' => 'backup', 'ctime' => 1585597170, 'format' => 'tar.lzo', 'size' => DEFAULT_SIZE, 'vmid' => '16112', 'volid' => 'local:backup/vzdump-lxc-16112-2020_03_30-21_39_30.tar.lzo' },
+ { 'content' => 'backup', 'ctime' => 1585597770, 'format' => 'tar.gz', 'size' => DEFAULT_SIZE, 'vmid' => '16112', 'volid' => 'local:backup/vzdump-lxc-16112-2020_03_30-21_49_30.tar.gz' },
+ { 'content' => 'backup', 'ctime' => 1585598370, 'format' => 'tgz', 'size' => DEFAULT_SIZE, 'vmid' => '16112', 'volid' => 'local:backup/vzdump-lxc-16112-2020_03_30-21_59_30.tgz' },
],
description => 'VMID: 16112, lxc, raw, backup',
},
@@ -206,8 +206,8 @@ my @tests = (
{ 'content' => 'iso', 'ctime' => DEFAULT_CTIME , 'format' => 'iso', 'size' => DEFAULT_SIZE, 'volid' => 'local:iso/debian-9.12.0-amd64-netinst.iso' },
{ 'content' => 'iso', 'ctime' => DEFAULT_CTIME , 'format' => 'iso', 'size' => DEFAULT_SIZE, 'volid' => 'local:iso/proxmox-ve_6.1-1.iso' },
- { 'content' => 'backup', 'ctime' => DEFAULT_CTIME, 'format' => 'tar.gz', 'size' => DEFAULT_SIZE, 'vmid' => '19253', 'volid' => 'local:backup/vzdump-lxc-19253-2020_02_03-19_57_43.tar.gz' },
- { 'content' => 'backup', 'ctime' => DEFAULT_CTIME, 'format' => 'tar', 'size' => DEFAULT_SIZE, 'vmid' => '19254', 'volid' => 'local:backup/vzdump-lxc-19254-2019_01_21-19_29_19.tar' },
+ { 'content' => 'backup', 'ctime' => 1580756263, 'format' => 'tar.gz', 'size' => DEFAULT_SIZE, 'vmid' => '19253', 'volid' => 'local:backup/vzdump-lxc-19253-2020_02_03-19_57_43.tar.gz' },
+ { 'content' => 'backup', 'ctime' => 1548095359, 'format' => 'tar', 'size' => DEFAULT_SIZE, 'vmid' => '19254', 'volid' => 'local:backup/vzdump-lxc-19254-2019_01_21-19_29_19.tar' },
{ 'content' => 'snippets', 'ctime' => DEFAULT_CTIME, 'format' => 'snippet', 'size' => DEFAULT_SIZE, 'volid' => 'local:snippets/hookscript.pl' },
{ 'content' => 'snippets', 'ctime' => DEFAULT_CTIME, 'format' => 'snippet', 'size' => DEFAULT_SIZE, 'volid' => 'local:snippets/userconfig.yaml' },
--
2.20.1
More information about the pve-devel
mailing list