use PVE::RPCEnvironment;
use PVE::Storage;
use PVE::Cluster qw(cfs_read_file);
-use PVE::VZDump::OpenVZ;
use Time::localtime;
use Time::Local;
use PVE::JSONSchema qw(get_standard_option);
+use PVE::HA::Env::PVE2;
+use PVE::HA::Config;
my @posix_filesystems = qw(ext3 ext4 nfs nfs4 reiserfs xfs);
my $lockfile = '/var/run/vzdump.lock';
+my $pidfile = '/var/run/vzdump.pid';
+
my $logdir = '/var/log/vzdump';
-my @plugins = qw (PVE::VZDump::OpenVZ);
+my @plugins = qw();
+
+my $confdesc = {
+ vmid => {
+ type => 'string', format => 'pve-vmid-list',
+ description => "The ID of the VM you want to backup.",
+ completion => \&PVE::Cluster::complete_local_vmid,
+ optional => 1,
+ },
+ node => get_standard_option('pve-node', {
+ description => "Only run if executed on this node.",
+ completion => \&PVE::Cluster::get_nodelist,
+ optional => 1,
+ }),
+ all => {
+ type => 'boolean',
+ description => "Backup all known VMs on this host.",
+ optional => 1,
+ default => 0,
+ },
+ stdexcludes => {
+ type => 'boolean',
+ description => "Exclude temorary files and logs.",
+ optional => 1,
+ default => 1,
+ },
+ compress => {
+ type => 'string',
+ description => "Compress dump file.",
+ optional => 1,
+ enum => ['0', '1', 'gzip', 'lzo'],
+ default => 'lzo',
+ },
+ pigz=> {
+ type => "integer",
+ description => "Uses pigz instead of gzip when N>0.".
+ " N=1 uses half of cores, N>1 uses N as thread count.",
+ optional => 1,
+ default => 0,
+ },
+ quiet => {
+ type => 'boolean',
+ description => "Be quiet.",
+ optional => 1,
+ default => 0,
+ },
+ mode => {
+ type => 'string',
+ description => "Backup mode.",
+ optional => 1,
+ default => 'stop',
+ enum => [ 'snapshot', 'suspend', 'stop' ],
+ },
+ exclude => {
+ type => 'string', format => 'pve-vmid-list',
+ description => "exclude specified VMs (assumes --all)",
+ optional => 1,
+ },
+ 'exclude-path' => {
+ type => 'string', format => 'string-alist',
+ description => "exclude certain files/directories (shell globs).",
+ optional => 1,
+ },
+ mailto => {
+ type => 'string', format => 'string-list',
+ description => "",
+ optional => 1,
+ },
+ mailnotification => {
+ type => 'string',
+ description => "Specify when to send an email",
+ optional => 1,
+ enum => [ 'always', 'failure' ],
+ default => 'always',
+ },
+ tmpdir => {
+ type => 'string',
+ description => "Store temporary files to specified directory.",
+ optional => 1,
+ },
+ dumpdir => {
+ type => 'string',
+ description => "Store resulting files to specified directory.",
+ optional => 1,
+ },
+ script => {
+ type => 'string',
+ description => "Use specified hook script.",
+ optional => 1,
+ },
+ storage => get_standard_option('pve-storage-id', {
+ description => "Store resulting file to this storage.",
+ completion => \&complete_backup_storage,
+ optional => 1,
+ }),
+ stop => {
+ type => 'boolean',
+ description => "Stop runnig backup jobs on this host.",
+ optional => 1,
+ default => 0,
+ },
+ size => {
+ type => 'integer',
+ description => "LVM snapshot size in MB.",
+ optional => 1,
+ minimum => 500,
+ },
+ bwlimit => {
+ type => 'integer',
+ description => "Limit I/O bandwidth (KBytes per second).",
+ optional => 1,
+ minimum => 0,
+ },
+ ionice => {
+ type => 'integer',
+ description => "Set CFQ ionice priority.",
+ optional => 1,
+ minimum => 0,
+ maximum => 8,
+ },
+ lockwait => {
+ type => 'integer',
+ description => "Maximal time to wait for the global lock (minutes).",
+ optional => 1,
+ minimum => 0,
+ },
+ stopwait => {
+ type => 'integer',
+ description => "Maximal time to wait until a VM is stopped (minutes).",
+ optional => 1,
+ minimum => 0,
+ },
+ maxfiles => {
+ type => 'integer',
+ description => "Maximal number of backup files per VM.",
+ optional => 1,
+ minimum => 1,
+ },
+ remove => {
+ type => 'boolean',
+ description => "Remove old backup files if there are more than 'maxfiles' backup files.",
+ optional => 1,
+ default => 1,
+ },
+};
# Load available plugins
-my $pveplug = "/usr/share/perl5/PVE/VZDump/QemuServer.pm";
-if (-f $pveplug) {
- eval { require $pveplug; };
- if (!$@) {
- PVE::VZDump::QemuServer->import ();
- push @plugins, "PVE::VZDump::QemuServer";
- } else {
- warn $@;
- }
+my @pve_vzdump_classes = qw(PVE::VZDump::QemuServer PVE::VZDump::LXC);
+foreach my $plug (@pve_vzdump_classes) {
+ my $filename = "/usr/share/perl5/$plug.pm";
+ $filename =~ s!::!/!g;
+ if (-f $filename) {
+ eval { require $filename; };
+ if (!$@) {
+ $plug->import ();
+ push @plugins, $plug;
+ } else {
+ warn $@;
+ }
+ }
}
# helper functions
my $type = $scfg->{type};
die "can't use storage type '$type' for backup\n"
- if (!($type eq 'dir' || $type eq 'nfs'));
- die "can't use storage for backups - wrong content type\n"
+ if (!($type eq 'dir' || $type eq 'nfs' || $type eq 'glusterfs'));
+ die "can't use storage '$storage' for backups - wrong content type\n"
if (!$scfg->{content}->{backup});
PVE::Storage::activate_storage($cfg, $storage);
return {
dumpdir => PVE::Storage::get_backup_dir($cfg, $storage),
+ maxfiles => $scfg->{maxfiles},
};
}
my $fn = "/etc/vzdump.conf";
- my $res = {
+ my $defaults = {
bwlimit => 0,
ionice => 7,
size => 1024,
stopwait => 10, # 10 minutes
mode => 'snapshot',
maxfiles => 1,
+ pigz => 0,
};
- my $fh = IO::File->new ("<$fn");
- return $res if !$fh;
-
- my $line;
- while (defined ($line = <$fh>)) {
- next if $line =~ m/^\s*$/;
- next if $line =~ m/^\#/;
-
- if ($line =~ m/tmpdir:\s*(.*\S)\s*$/) {
- $res->{tmpdir} = $1;
- } elsif ($line =~ m/dumpdir:\s*(.*\S)\s*$/) {
- $res->{dumpdir} = $1;
- } elsif ($line =~ m/storage:\s*(\S+)\s*$/) {
- $res->{storage} = $1;
- } elsif ($line =~ m/script:\s*(.*\S)\s*$/) {
- $res->{script} = $1;
- } elsif ($line =~ m/bwlimit:\s*(\d+)\s*$/) {
- $res->{bwlimit} = int($1);
- } elsif ($line =~ m/ionice:\s*([0-8])\s*$/) {
- $res->{ionice} = int($1);
- } elsif ($line =~ m/lockwait:\s*(\d+)\s*$/) {
- $res->{lockwait} = int($1);
- } elsif ($line =~ m/stopwait:\s*(\d+)\s*$/) {
- $res->{stopwait} = int($1);
- } elsif ($line =~ m/size:\s*(\d+)\s*$/) {
- $res->{size} = int($1);
- } elsif ($line =~ m/maxfiles:\s*(\d+)\s*$/) {
- $res->{maxfiles} = int($1);
- } elsif ($line =~ m/exclude-path:\s*(.*)\s*$/) {
- $res->{'exclude-path'} = PVE::Tools::split_args($1);
- } elsif ($line =~ m/mode:\s*(stop|snapshot|suspend)\s*$/) {
- $res->{mode} = $1;
- } else {
- debugmsg ('warn', "unable to parse configuration file '$fn' - error at line " . $., undef, 1);
- }
+ my $raw;
+ eval { $raw = PVE::Tools::file_get_contents($fn); };
+ return $defaults if $@;
+ my $conf_schema = { type => 'object', properties => $confdesc, };
+ my $res = PVE::JSONSchema::parse_config($conf_schema, $fn, $raw);
+ if (my $excludes = $res->{'exclude-path'}) {
+ $res->{'exclude-path'} = PVE::Tools::split_args($excludes);
}
- close ($fh);
-
- return $res;
-}
-
-sub find_add_exclude {
- my ($self, $excltype, $value) = @_;
-
- if (($excltype eq '-regex') || ($excltype eq '-files')) {
- $value = "\.$value";
+ foreach my $key (keys %$defaults) {
+ $res->{$key} = $defaults->{$key} if !$res->{$key};
}
- if ($excltype eq '-files') {
- push @{$self->{findexcl}}, "'('", '-not', '-type', 'd', '-regex' , "'$value'", "')'", '-o';
- } else {
- push @{$self->{findexcl}}, "'('", $excltype , "'$value'", '-prune', "')'", '-o';
- }
+ return $res;
}
-my $sendmail = sub {
- my ($self, $tasklist, $totaltime) = @_;
+sub sendmail {
+ my ($self, $tasklist, $totaltime, $err) = @_;
my $opts = $self->{opts};
}
}
- my $stat = $ecount ? 'backup failed' : 'backup successful';
+ my $notify = $opts->{mailnotification} || 'always';
+ return if (!$ecount && !$err && ($notify eq 'failure'));
+
+ my $stat = ($ecount || $err) ? 'backup failed' : 'backup successful';
+ $stat .= ": $err" if $err;
my $hostname = `hostname -f` || PVE::INotify::nodename();
chomp $hostname;
foreach my $r (@$mailto) {
$rcvrarg .= " '$r'";
}
+ my $dcconf = PVE::Cluster::cfs_read_file('datacenter.cfg');
+ my $mailfrom = $dcconf->{email_from} || "root";
- open (MAIL,"|sendmail -B 8BITMIME $rcvrarg") ||
+ open (MAIL,"|sendmail -B 8BITMIME -f $mailfrom $rcvrarg") ||
die "unable to open 'sendmail' - $!";
my $rcvrtxt = join (', ', @$mailto);
print MAIL "Content-Type: multipart/alternative;\n";
print MAIL "\tboundary=\"$boundary\"\n";
- print MAIL "FROM: vzdump backup tool <root>\n";
+ print MAIL "MIME-Version: 1.0\n";
+
+ print MAIL "FROM: vzdump backup tool <$mailfrom>\n";
print MAIL "TO: $rcvrtxt\n";
print MAIL "SUBJECT: vzdump backup status ($hostname) : $stat\n";
print MAIL "\n";
my $defaults = read_vzdump_defaults();
- my $maxfiles = $opts->{maxfiles};
+ my $maxfiles = $opts->{maxfiles}; # save here, because we overwrite with default
+
$opts->{remove} = 1 if !defined($opts->{remove});
foreach my $k (keys %$defaults) {
+ next if $k eq 'exclude-path'; # dealt with separately
if ($k eq 'dumpdir' || $k eq 'storage') {
$opts->{$k} = $defaults->{$k} if !defined ($opts->{dumpdir}) &&
!defined ($opts->{storage});
$skiplist = [] if !$skiplist;
my $self = bless { cmdline => $cmdline, opts => $opts, skiplist => $skiplist };
- #always skip '.'
- push @{$self->{findexcl}}, "'('", '-regex' , "'^\\.\$'", "')'", '-o';
-
- $self->find_add_exclude ('-type', 's'); # skip sockets
-
+ my $findexcl = $self->{findexcl} = [];
if ($defaults->{'exclude-path'}) {
- foreach my $path (@{$defaults->{'exclude-path'}}) {
- $self->find_add_exclude ('-regex', $path);
- }
+ push @$findexcl, @{$defaults->{'exclude-path'}};
}
if ($opts->{'exclude-path'}) {
- foreach my $path (@{$opts->{'exclude-path'}}) {
- $self->find_add_exclude ('-regex', $path);
- }
+ push @$findexcl, @{$opts->{'exclude-path'}};
}
if ($opts->{stdexcludes}) {
- $self->find_add_exclude ('-files', '/var/log/.+');
- $self->find_add_exclude ('-regex', '/tmp/.+');
- $self->find_add_exclude ('-regex', '/var/tmp/.+');
- $self->find_add_exclude ('-regex', '/var/run/.+pid');
+ push @$findexcl, '/var/log/?*',
+ '/tmp/?*',
+ '/var/tmp/?*',
+ '/var/run/?*pid';
}
foreach my $p (@plugins) {
my $pd = $p->new ($self);
push @{$self->{plugins}}, $pd;
-
- if (!$opts->{dumpdir} && !$opts->{storage} &&
- ($p eq 'PVE::VZDump::OpenVZ')) {
- $opts->{dumpdir} = $pd->{dumpdir};
- }
}
if (!$opts->{dumpdir} && !$opts->{storage}) {
- die "no dumpdir/storage specified - use option '--dumpdir' or option '--storage'\n";
+ $opts->{storage} = 'local';
}
if ($opts->{storage}) {
my $info = storage_info ($opts->{storage});
$opts->{dumpdir} = $info->{dumpdir};
- $maxfiles = $info->{maxfiles} if !$maxfiles && $info->{maxfiles};
+ $maxfiles = $info->{maxfiles} if !defined($maxfiles) && defined($info->{maxfiles});
} elsif ($opts->{dumpdir}) {
die "dumpdir '$opts->{dumpdir}' does not exist\n"
if ! -d $opts->{dumpdir};
die "tmpdir '$opts->{tmpdir}' does not exist\n";
}
- $opts->{maxfiles} = $maxfiles if $maxfiles;
+ $opts->{maxfiles} = $maxfiles if defined($maxfiles);
return $self;
sub get_mount_info {
my ($dir) = @_;
+ # Note: df 'available' can be negative, and percentage set to '-'
+
my $cmd = [ 'df', '-P', '-T', '-B', '1', $dir];
my $res;
my $parser = sub {
my $line = shift;
- if (my ($fsid, $fstype, $mp) = $line =~
- m|^(\S+.*)\s+(\S+)\s+\d+\s+\d+\s+\d+\s+\d+%\s+(/.*)$|) {
+ if (my ($fsid, $fstype, undef, $mp) = $line =~
+ m!(\S+.*)\s+(\S+)\s+\d+\s+\-?\d+\s+\d+\s+(\d+%|-)\s+(/.*)$!) {
$res = {
device => $fsid,
fstype => $fstype,
}
sub getlock {
- my ($self) = @_;
+ my ($self, $upid) = @_;
+ my $fh;
+
my $maxwait = $self->{opts}->{lockwait} || $self->{lockwait};
+ die "missimg UPID" if !$upid; # should not happen
+
if (!open (SERVER_FLCK, ">>$lockfile")) {
debugmsg ('err', "can't open lock on file '$lockfile' - $!", undef, 1);
- exit (-1);
+ die "can't open lock on file '$lockfile' - $!";
}
- if (flock (SERVER_FLCK, LOCK_EX|LOCK_NB)) {
- return;
- }
+ if (!flock (SERVER_FLCK, LOCK_EX|LOCK_NB)) {
- if (!$maxwait) {
- debugmsg ('err', "can't aquire lock '$lockfile' (wait = 0)", undef, 1);
- exit (-1);
- }
+ if (!$maxwait) {
+ debugmsg ('err', "can't aquire lock '$lockfile' (wait = 0)", undef, 1);
+ die "can't aquire lock '$lockfile' (wait = 0)";
+ }
- debugmsg('info', "trying to get global lock - waiting...", undef, 1);
+ debugmsg('info', "trying to get global lock - waiting...", undef, 1);
- eval {
- alarm ($maxwait * 60);
+ eval {
+ alarm ($maxwait * 60);
- local $SIG{ALRM} = sub { alarm (0); die "got timeout\n"; };
+ local $SIG{ALRM} = sub { alarm (0); die "got timeout\n"; };
- if (!flock (SERVER_FLCK, LOCK_EX)) {
- my $err = $!;
- close (SERVER_FLCK);
+ if (!flock (SERVER_FLCK, LOCK_EX)) {
+ my $err = $!;
+ close (SERVER_FLCK);
+ alarm (0);
+ die "$err\n";
+ }
alarm (0);
- die "$err\n";
- }
+ };
alarm (0);
- };
- alarm (0);
- my $err = $@;
+ my $err = $@;
+
+ if ($err) {
+ debugmsg ('err', "can't aquire lock '$lockfile' - $err", undef, 1);
+ die "can't aquire lock '$lockfile' - $err";
+ }
- if ($err) {
- debugmsg ('err', "can't aquire lock '$lockfile' - $err", undef, 1);
- exit (-1);
+ debugmsg('info', "got global lock", undef, 1);
}
- debugmsg('info', "got global lock", undef, 1);
+ PVE::Tools::file_set_contents($pidfile, $upid);
}
sub run_hook_script {
local %ENV;
- foreach my $ek (qw(vmtype dumpdir hostname tarfile logfile)) {
+ # set immutable opts directly (so they are available in all phases)
+ $ENV{STOREID} = $opts->{storage} if $opts->{storage};
+ $ENV{DUMPDIR} = $opts->{dumpdir} if $opts->{dumpdir};
+
+ foreach my $ek (qw(vmtype hostname tarfile logfile)) {
$ENV{uc($ek)} = $task->{$ek} if $task->{$ek};
}
}
sub compressor_info {
- my ($opt_compress) = @_;
+ my ($opts) = @_;
+ my $opt_compress = $opts->{compress};
if (!$opt_compress || $opt_compress eq '0') {
return undef;
} elsif ($opt_compress eq '1' || $opt_compress eq 'lzo') {
return ('lzop', 'lzo');
} elsif ($opt_compress eq 'gzip') {
- return ('gzip', 'gz');
+ if ($opts->{pigz} > 0) {
+ # As default use int((#cores + 1)/2), we need #cores+1 for the case that #cores = 1
+ my $cores = POSIX::sysconf(84);
+ my $pigz_threads = ($opts->{pigz} > 1) ? $opts->{pigz} : int(($cores + 1)/2);
+ return ("pigz -p ${pigz_threads}", 'gz');
+ } else {
+ return ('gzip', 'gz');
+ }
} else {
die "internal error - unknown compression option '$opt_compress'";
}
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(\.(gz|lzo))?)))$!) {
+ if ($fn =~ m!/(${bkname}-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?)))$!) {
$fn = "$dir/$1"; # untaint
my $t = timelocal ($7, $6, $5, $4, $3 - 1, $2 - 1900);
push @$bklist, [$fn, $t];
eval {
die "unable to find VM '$vmid'\n" if !$plugin;
+ # for now we deny backups of a running ha managed service in *stop* mode
+ # as it interferes with the HA stack (enabled services should not stop).
+ if ($opts->{mode} eq 'stop' &&
+ PVE::HA::Config::vm_is_ha_managed($vmid, 'enabled'))
+ {
+ die "Cannot execute a backup with stop mode on a HA managed and".
+ " enabled Service. Use snapshot mode or disable the Service.\n";
+ }
+
my $vmtype = $plugin->type();
my $tmplog = "$logdir/$vmtype-$vmid.log";
my $logfile = $task->{logfile} = "$opts->{dumpdir}/$basename.log";
- my $ext = '.tar';
- my ($comp, $comp_ext) = compressor_info($opts->{compress});
+ my $ext = $vmtype eq 'qemu' ? '.vma' : '.tar';
+ my ($comp, $comp_ext) = compressor_info($opts);
if ($comp && $comp_ext) {
$ext .= ".${comp_ext}";
}
die "unable to create log file '$tmplog'";
$task->{dumpdir} = $opts->{dumpdir};
-
+ $task->{storeid} = $opts->{storage};
$task->{tmplog} = $tmplog;
unlink $logfile;
$self->run_hook_script ('backup-start', $task, $logfd);
- if ($vmtype eq 'openvz') {
+ if ($vmtype eq 'lxc') {
# pre-suspend rsync
- $plugin->copy_data_phase1 ($task, $vmid);
+ $plugin->copy_data_phase1($task, $vmid);
}
debugmsg ('info', "suspend vm", $logfd);
$plugin->suspend_vm ($task, $vmid);
$cleanup->{resume} = 1;
- if ($vmtype eq 'openvz') {
+ if ($vmtype eq 'lxc') {
# post-suspend rsync
- $plugin->copy_data_phase2 ($task, $vmid);
+ $plugin->copy_data_phase2($task, $vmid);
debugmsg ('info', "resume vm", $logfd);
$cleanup->{resume} = 0;
- $self->run_hook_script ('pre-restart', $task, $logfd);
- $plugin->resume_vm ($task, $vmid);
+ $self->run_hook_script('pre-restart', $task, $logfd);
+ $plugin->resume_vm($task, $vmid);
my $delay = time () - $vmstoptime;
- debugmsg ('info', "vm is online again after $delay seconds", $logfd);
+ debugmsg('info', "vm is online again after $delay seconds", $logfd);
}
-
+
} elsif ($mode eq 'snapshot') {
+ $self->run_hook_script ('backup-start', $task, $logfd);
+
my $snapshot_count = $task->{snapshot_count} || 0;
$self->run_hook_script ('pre-stop', $task, $logfd);
debugmsg ('info', "delete old backup '$d->[0]'", $logfd);
unlink $d->[0];
my $logfn = $d->[0];
- $logfn =~ s/\.(tgz|(tar(\.(gz|lzo))?))$/\.log/;
+ $logfn =~ s/\.(tgz|((tar|vma)(\.(gz|lzo))?))$/\.log/;
unlink $logfn;
}
}
warn $@ if $@;
}
- eval { $plugin->cleanup ($task, $vmid) };
- warn $@ if $@;
+ if (defined($task->{mode})) {
+ # only call cleanup when necessary (when prepare was executed)
+ eval { $plugin->cleanup ($task, $vmid) };
+ warn $@ if $@;
+ }
eval { $plugin->set_logfd (undef); };
warn $@ if $@;
debugmsg ('info', "resume vm", $logfd);
$plugin->resume_vm ($task, $vmid);
} else {
- debugmsg ('info', "restarting vm", $logfd);
- $plugin->start_vm ($task, $vmid);
+ my $running = $plugin->vm_status($vmid);
+ if (!$running) {
+ debugmsg ('info', "restarting vm", $logfd);
+ $plugin->start_vm ($task, $vmid);
+ }
}
};
my $err = $@;
my $totaltime = time() - $starttime;
- eval { $self->$sendmail ($tasklist, $totaltime); };
+ eval { $self->sendmail ($tasklist, $totaltime); };
debugmsg ('err', $@) if $@;
die $err if $err;
die "job errors\n" if $errcount;
+
+ unlink $pidfile;
}
-my $confdesc = {
- vmid => {
- type => 'string', format => 'pve-vmid-list',
- description => "The ID of the VM you want to backup.",
- optional => 1,
- },
- node => get_standard_option('pve-node', {
- description => "Only run if executed on this node.",
- optional => 1,
- }),
- all => {
- type => 'boolean',
- description => "Backup all known VMs on this host.",
- optional => 1,
- default => 0,
- },
- stdexcludes => {
- type => 'boolean',
- description => "Exclude temorary files and logs.",
- optional => 1,
- default => 1,
- },
- compress => {
- type => 'string',
- description => "Compress dump file.",
- optional => 1,
- enum => ['0', '1', 'gzip', 'lzo'],
- default => 'lzo',
- },
- quiet => {
- type => 'boolean',
- description => "Be quiet.",
- optional => 1,
- default => 0,
- },
- mode => {
- type => 'string',
- description => "Backup mode.",
- optional => 1,
- default => 'stop',
- enum => [ 'snapshot', 'suspend', 'stop' ],
- },
- exclude => {
- type => 'string', format => 'pve-vmid-list',
- description => "exclude specified VMs (assumes --all)",
- optional => 1,
- },
- 'exclude-path' => {
- type => 'string', format => 'string-alist',
- description => "exclude certain files/directories (regex).",
- optional => 1,
- },
- mailto => {
- type => 'string', format => 'string-list',
- description => "",
- optional => 1,
- },
- tmpdir => {
- type => 'string',
- description => "Store temporary files to specified directory.",
- optional => 1,
- },
- dumpdir => {
- type => 'string',
- description => "Store resulting files to specified directory.",
- optional => 1,
- },
- script => {
- type => 'string',
- description => "Use specified hook script.",
- optional => 1,
- },
- storage => get_standard_option('pve-storage-id', {
- description => "Store resulting file to this storage.",
- optional => 1,
- }),
- size => {
- type => 'integer',
- description => "LVM snapshot size im MB.",
- optional => 1,
- minimum => 500,
- },
- bwlimit => {
- type => 'integer',
- description => "Limit I/O bandwidth (KBytes per second).",
- optional => 1,
- minimum => 0,
- },
- ionice => {
- type => 'integer',
- description => "Set CFQ ionice priority.",
- optional => 1,
- minimum => 0,
- maximum => 8,
- },
- lockwait => {
- type => 'integer',
- description => "Maximal time to wait for the global lock (minutes).",
- optional => 1,
- minimum => 0,
- },
- stopwait => {
- type => 'integer',
- description => "Maximal time to wait until a VM is stopped (minutes).",
- optional => 1,
- minimum => 0,
- },
- maxfiles => {
- type => 'integer',
- description => "Maximal number of backup files per VM.",
- optional => 1,
- minimum => 1,
- },
- remove => {
- type => 'boolean',
- description => "Remove old backup files if there are more than 'maxfiles' backup files.",
- optional => 1,
- default => 1,
- },
-};
sub option_exists {
my $key = shift;
return if !$check_missing;
raise_param_exc({ vmid => "property is missing"})
- if !$param->{all} && !$param->{vmid};
+ if !($param->{all} || $param->{stop}) && !$param->{vmid};
+
+}
+sub stop_running_backups {
+ my($self) = @_;
+
+ my $upid = PVE::Tools::file_read_firstline($pidfile);
+ return if !$upid;
+
+ my $task = PVE::Tools::upid_decode($upid);
+
+ if (PVE::ProcFSTools::check_process_running($task->{pid}, $task->{pstart}) &&
+ PVE::ProcFSTools::read_proc_starttime($task->{pid}) == $task->{pstart}) {
+ kill(15, $task->{pid});
+ # wait max 15 seconds to shut down (else, do nothing for now)
+ my $i;
+ for ($i = 15; $i > 0; $i--) {
+ last if !PVE::ProcFSTools::check_process_running(($task->{pid}, $task->{pstart}));
+ sleep (1);
+ }
+ die "stoping backup process $task->{pid} failed\n" if $i == 0;
+ }
}
sub command_line {
}
foreach my $p (keys %$param) {
- next if $p eq 'id' || $p eq 'vmid' || $p eq 'starttime' || $p eq 'dow';
+ next if $p eq 'id' || $p eq 'vmid' || $p eq 'starttime' ||
+ $p eq 'dow' || $p eq 'stdout' || $p eq 'enabled';
my $v = $param->{$p};
my $pd = $confdesc->{$p} || die "no such vzdump option '$p'\n";
if ($p eq 'exclude-path') {
return $cmd;
}
+# bash completion helpers
+sub complete_backup_storage {
+
+ my $cfg = PVE::Storage::config();
+ my $ids = $cfg->{ids};
+
+ my $nodename = PVE::INotify::nodename();
+
+ my $res = [];
+ foreach my $sid (keys %$ids) {
+ my $scfg = $ids->{$sid};
+ next if !PVE::Storage::storage_check_enabled($cfg, $sid, $nodename, 1);
+ next if !$scfg->{content}->{backup};
+ push @$res, $sid;
+ }
+
+ return $res;
+}
+
1;