]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/VZDump.pm
fix #2314: remove GZIP env var
[pve-manager.git] / PVE / VZDump.pm
index 7099fd9855fceeaa878c33da0ae5cb261f239d6c..39669f49cdee8ba99a9cc7a2aa065e7f8cd84b05 100644 (file)
@@ -122,7 +122,7 @@ my $confdesc = {
     }),
     stop => {
        type => 'boolean',
-       description => "Stop runnig backup jobs on this host.",
+       description => "Stop running backup jobs on this host.",
        optional => 1,
        default => 0,
     },
@@ -175,6 +175,11 @@ my $confdesc = {
        optional => 1,
        default => 1,
     },
+    pool => {
+       type => 'string',
+       description => 'Backup all known guest systems included in the specified pool.',
+       optional => 1,
+    }
 };
 
 # Load available plugins
@@ -218,11 +223,11 @@ sub storage_info {
     my $cfg = PVE::Storage::config();
     my $scfg = PVE::Storage::storage_config($cfg, $storage);
     my $type = $scfg->{type};
-    die "can't use storage type '$type' for backup\n" 
+
+    die "can't use storage type '$type' for backup\n"
        if (!($type eq 'dir' || $type eq 'nfs' || $type eq 'glusterfs'
              || $type eq 'cifs' || $type eq 'cephfs'));
-    die "can't use storage '$storage' for backups - wrong content type\n" 
+    die "can't use storage '$storage' for backups - wrong content type\n"
        if (!$scfg->{content}->{backup});
 
     PVE::Storage::activate_storage($cfg, $storage);
@@ -249,7 +254,7 @@ sub format_size {
     } else {
        my $gb = $mb / 1024;
        return sprintf ("%.2fGB", $gb);
-    } 
+    }
 }
 
 sub format_time {
@@ -569,7 +574,7 @@ sub new {
        $errors .= "dumpdir '$opts->{dumpdir}' does not exist"
            if ! -d $opts->{dumpdir};
     } else {
-       die "internal error"; 
+       die "internal error";
     }
 
     if ($opts->{tmpdir} && ! -d $opts->{tmpdir}) {
@@ -620,9 +625,9 @@ sub getlock {
     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")) {
@@ -633,15 +638,15 @@ sub getlock {
     if (!flock (SERVER_FLCK, LOCK_EX|LOCK_NB)) {
 
        if (!$maxwait) {
-           debugmsg ('err', "can't aquire lock '$lockfile' (wait = 0)", undef, 1);
-           die "can't aquire lock '$lockfile' (wait = 0)";
+           debugmsg ('err', "can't acquire lock '$lockfile' (wait = 0)", undef, 1);
+           die "can't acquire lock '$lockfile' (wait = 0)";
        }
 
        debugmsg('info', "trying to get global lock - waiting...", undef, 1);
 
        eval {
            alarm ($maxwait * 60);
-       
+
            local $SIG{ALRM} = sub { alarm (0); die "got timeout\n"; };
 
            if (!flock (SERVER_FLCK, LOCK_EX)) {
@@ -653,12 +658,12 @@ sub getlock {
            alarm (0);
        };
        alarm (0);
-    
+
        my $err = $@;
-       
+
        if ($err) {
-           debugmsg ('err', "can't aquire lock '$lockfile' - $err", undef, 1);
-           die "can't aquire lock '$lockfile' - $err";
+           debugmsg ('err', "can't acquire lock '$lockfile' - $err", undef, 1);
+           die "can't acquire lock '$lockfile' - $err";
        }
 
        debugmsg('info', "got global lock", undef, 1);
@@ -710,7 +715,7 @@ sub compressor_info {
            }
            return ("pigz -p ${pigz_threads}", 'gz');
        } else {
-           return ('gzip', 'gz');
+           return ('gzip --rsyncable', 'gz');
        }
     } else {
        die "internal error - unknown compression option '$opt_compress'";
@@ -732,17 +737,17 @@ sub get_backup_file_list {
 
     return $bklist;
 }
+
 sub exec_backup_task {
     my ($self, $task) = @_;
-        
+
     my $opts = $self->{opts};
 
     my $vmid = $task->{vmid};
     my $plugin = $task->{plugin};
 
     my $vmstarttime = time ();
-    
+
     my $logfd;
 
     my $cleanup = {};
@@ -777,7 +782,9 @@ sub exec_backup_task {
 
        if ($maxfiles && !$opts->{remove}) {
            my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname);
-           die "only $maxfiles backup(s) allowed - please consider to remove old backup files.\n" 
+           die "There is a max backup limit of ($maxfiles) enforced by the".
+           " target storage or the vzdump parameters.".
+           " Either increase the limit or delete old backup(s).\n"
                if scalar(@$bklist) >= $maxfiles;
        }
 
@@ -801,11 +808,11 @@ sub exec_backup_task {
        $task->{vmtype} = $vmtype;
 
        if ($opts->{tmpdir}) {
-           $task->{tmpdir} = "$opts->{tmpdir}/vzdumptmp$$"; 
+           $task->{tmpdir} = "$opts->{tmpdir}/vzdumptmp$$";
        } else {
            # dumpdir is posix? then use it as temporary dir
            my $info = get_mount_info($opts->{dumpdir});
-           if ($vmtype eq 'qemu' || 
+           if ($vmtype eq 'qemu' ||
                grep ($_ eq $info->{fstype}, @posix_filesystems)) {
                $task->{tmpdir} = "$opts->{dumpdir}/$basename.tmp";
            } else {
@@ -856,7 +863,7 @@ sub exec_backup_task {
                debugmsg ('info',  $err, $logfd);
                debugmsg ('info',  "trying 'suspend' mode instead", $logfd);
                $mode = 'suspend'; # so prepare is called again below
-               %$task = %saved_task; 
+               %$task = %saved_task;
            }
        }
 
@@ -884,7 +891,7 @@ sub exec_backup_task {
                $plugin->stop_vm ($task, $vmid);
                $cleanup->{restart} = 1;
            }
+
 
        } elsif ($mode eq 'suspend') {
 
@@ -914,7 +921,7 @@ sub exec_backup_task {
                $self->run_hook_script('post-restart', $task, $logfd);
                $log_vm_online_again->();
            }
-           
+
        } elsif ($mode eq 'snapshot') {
 
            $self->run_hook_script ('backup-start', $task, $logfd);
@@ -949,8 +956,8 @@ sub exec_backup_task {
 
        # assemble archive image
        $plugin->assemble ($task, $vmid);
-       
-       # produce archive 
+
+       # produce archive
 
        if ($opts->{stdout}) {
            debugmsg ('info', "sending archive to stdout", $logfd);
@@ -967,7 +974,7 @@ sub exec_backup_task {
 
        # determine size
        $task->{size} = (-s $task->{tarfile}) || 0;
-       my $cs = format_size ($task->{size}); 
+       my $cs = format_size ($task->{size});
        debugmsg ('info', "archive file size: $cs", $logfd);
 
        # purge older backup
@@ -1007,8 +1014,8 @@ sub exec_backup_task {
        eval { $plugin->set_logfd (undef); };
        warn $@ if $@;
 
-       if ($cleanup->{resume} || $cleanup->{restart}) {        
-           eval { 
+       if ($cleanup->{resume} || $cleanup->{restart}) {
+           eval {
                $self->run_hook_script ('pre-restart', $task, $logfd);
                if ($cleanup->{resume}) {
                    debugmsg ('info', "resume vm", $logfd);
@@ -1055,7 +1062,7 @@ sub exec_backup_task {
     }
 
     close ($logfd) if $logfd;
-    
+
     if ($task->{tmplog} && $task->{logfile}) {
        system {'cp'} 'cp', $task->{tmplog}, $task->{logfile};
     }
@@ -1073,7 +1080,7 @@ sub exec_backup {
     debugmsg ('info', "starting new backup job: $self->{cmdline}", undef, 1);
     debugmsg ('info', "skip external VMs: " . join(', ', @{$self->{skiplist}}))
        if scalar(@{$self->{skiplist}});
+
     my $tasklist = [];
 
     if ($opts->{all}) {
@@ -1143,7 +1150,7 @@ sub exec_backup {
 
     die $err if $err;
 
-    die "job errors\n" if $errcount; 
+    die "job errors\n" if $errcount;
 
     unlink $pidfile;
 }
@@ -1174,7 +1181,10 @@ sub verify_vzdump_parameters {
     raise_param_exc({ exclude => "option conflicts with option 'vmid'"})
        if $param->{exclude} && $param->{vmid};
 
-    $param->{all} = 1 if defined($param->{exclude});
+    raise_param_exc({ pool => "option conflicts with option 'vmid'"})
+       if $param->{pool} && $param->{vmid};
+
+    $param->{all} = 1 if (defined($param->{exclude}) && !$param->{pool});
 
     warn "option 'size' is deprecated and will be removed in a future " .
         "release, please update your script/configuration!\n"
@@ -1183,7 +1193,7 @@ sub verify_vzdump_parameters {
     return if !$check_missing;
 
     raise_param_exc({ vmid => "property is missing"})
-       if !($param->{all} || $param->{stop}) && !$param->{vmid};
+       if !($param->{all} || $param->{stop} || $param->{pool}) && !$param->{vmid};
 
 }
 
@@ -1195,7 +1205,7 @@ sub stop_running_backups {
 
     my $task = PVE::Tools::upid_decode($upid);
 
-    if (PVE::ProcFSTools::check_process_running($task->{pid}, $task->{pstart}) && 
+    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)
@@ -1204,7 +1214,7 @@ sub stop_running_backups {
            last if !PVE::ProcFSTools::check_process_running(($task->{pid}, $task->{pstart}));
            sleep (1);
        }
-       die "stoping backup process $task->{pid} failed\n" if $i == 0;
+       die "stopping backup process $task->{pid} failed\n" if $i == 0;
     }
 }