]> git.proxmox.com Git - pmg-api.git/blobdiff - PMG/API2/Backup.pm
UserConfig: rename verity_entry to verify_entry
[pmg-api.git] / PMG / API2 / Backup.pm
index 6c439e31a9c698925ab019e456c04fe4814b0b4e..0bfcfc9f97a58bbf1a5ebd6ef576b082f7556657 100644 (file)
@@ -18,7 +18,7 @@ use PMG::Backup;
 use base qw(PVE::RESTHandler);
 
 my $backup_dir = "/var/lib/pmg/backup";
-my $backup_filename_pattern = 'pmg-backup_(\d{4})_(\d\d)_(\d\d)_([0-9A-F]+)\.tgz';
+my $backup_filename_pattern = 'pmg-backup_[0-9A-Za-z_-]+\.tgz';
 
 my $backup_filename_property = {
     description => "The backup file name.",
@@ -69,27 +69,29 @@ __PACKAGE__->register_method ({
            $backup_dir,
            $backup_filename_pattern,
            sub {
-               my ($filename, $year, $mon, $mday, $timestamp_hex) = @_;
+               my ($filename) = @_;
+
+               my $path = "$backup_dir/$filename";
+               my @sa = stat($path);
+
+               my $timestamp = $sa[9] // 0; # mtime
+               my $size = $sa[7] // 0; # size
+
+               # prefer timestamp from filename
+               if ($filename =~ m/.*_([0-9A-F]+)\.tgz/) {
+                   $timestamp = hex($1);
+               }
+
                push @$res, {
                    filename => $filename,
-                   size => -s "$backup_dir/$filename",
-                   year => int($year),
-                   mon => int($mon),
-                   mday => int($mday),
-                   timestamp => hex($timestamp_hex),
+                   size => $size,
+                   timestamp => $timestamp,
                };
            });
 
        return $res;
     }});
 
-my $include_statistic_property = {
-    description => "Backup/Restore statistic databases.",
-    type => 'boolean',
-    optional => 1,
-    default => 0,
-};
-
 __PACKAGE__->register_method ({
     name => 'backup',
     path => '',
@@ -102,7 +104,12 @@ __PACKAGE__->register_method ({
        additionalProperties => 0,
        properties => {
            node => get_standard_option('pve-node'),
-           statistic => $include_statistic_property,
+           statistic => {
+               description => "Backup statistic databases.",
+               type => 'boolean',
+               optional => 1,
+               default => 1,
+           },
        },
     },
     returns => { type => "string" },
@@ -112,8 +119,11 @@ __PACKAGE__->register_method ({
        my $rpcenv = PMG::RESTEnvironment->get();
        my $authuser = $rpcenv->get_user();
 
-       my (undef, undef, undef, $mday, $mon, $year) = localtime(time);
-       my $bkfile = sprintf("pmg-backup_%04d_%02d_%02d_%08X.tgz", $year + 1900, $mon + 1, $mday, time());
+       $param->{statistic} //= 1;
+
+       my $ctime = time();
+       my (undef, undef, undef, $mday, $mon, $year) = localtime($ctime);
+       my $bkfile = sprintf("pmg-backup_%04d_%02d_%02d_%08X.tgz", $year + 1900, $mon + 1, $mday, $ctime);
        my $filename = "${backup_dir}/$bkfile";
 
        my $worker = sub {
@@ -194,7 +204,6 @@ __PACKAGE__->register_method ({
        properties => {
            node => get_standard_option('pve-node'),
            filename => $backup_filename_property,
-           statistic => $include_statistic_property,
            config => {
                description => "Restore system configuration.",
                type => 'boolean',
@@ -207,6 +216,12 @@ __PACKAGE__->register_method ({
                optional => 1,
                default => 1,
            },
+           statistic => {
+               description => "Restore statistic databases. Only considered when you restore the 'database'.",
+               type => 'boolean',
+               optional => 1,
+               default => 0,
+           },
        },
     },
     returns => { type => "string" },