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.",
$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 => '',
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" },
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 {
properties => {
node => get_standard_option('pve-node'),
filename => $backup_filename_property,
- statistic => $include_statistic_property,
config => {
description => "Restore system configuration.",
type => 'boolean',
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" },