From 3db33e1f60babafa14cc719bd0856d8bb56942e8 Mon Sep 17 00:00:00 2001 From: Wolfgang Link Date: Wed, 11 Nov 2015 10:24:52 +0100 Subject: [PATCH] fix bug #813: allow mountpoints or VMdisk which are not on zfs, if they are not include in backup. LXC: MP are in the default setting exclude from backup, so we do not sync mp at default. if they have the flag backup=1 we sync them. QEMU: VMDisk will be synced always except they have a flag backup=no. --- pve-zsync | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/pve-zsync b/pve-zsync index 283b55c..f824fc4 100644 --- a/pve-zsync +++ b/pve-zsync @@ -479,11 +479,15 @@ sub init { my $vm_type = vm_exists($source); $job->{vm_type} = $vm_type; + $source->{vm_type} = $vm_type; die "VM $source->{vmid} doesn't exist\n" if $param->{vmid} && !$vm_type; die "Config already exists\n" if $cfg->{$job->{source}}->{$job->{name}}; + #check if vm has zfs disks if not die; + get_disks($source, 1) if $source->{vmid}; + update_cron($job); update_state($job); @@ -698,7 +702,7 @@ sub write_cron { } sub get_disks { - my ($target) = @_; + my ($target, $get_err) = @_; my $cmd = []; push @$cmd, 'ssh', "root\@$target->{ip}", '--', if $target->{ip}; @@ -713,7 +717,7 @@ sub get_disks { my $res = run_cmd($cmd); - my $disks = parse_disks($res, $target->{ip}, $target->{vm_type}); + my $disks = parse_disks($res, $target->{ip}, $target->{vm_type}, $get_err); return $disks; } @@ -736,24 +740,32 @@ sub run_cmd { } sub parse_disks { - my ($text, $ip, $vm_type) = @_; + my ($text, $ip, $vm_type, $get_err) = @_; my $disks; my $num = 0; while ($text && $text =~ s/^(.*?)(\n|$)//) { my $line = $1; + my $error = $vm_type eq 'qemu' ? 1 : 0 ; next if $line =~ /cdrom|none/; next if $line !~ m/^(?:((?:virtio|ide|scsi|sata|mp)\d+)|rootfs): /; + #QEMU if backup is not set include in sync + next if $vm_type eq 'qemu && ($line =~ m/backup=(?i:0|no|off|false)/)'; + + #LXC if backup is not set do no in sync + $error = ($line =~ m/backup=(?i:1|yes|on|true)/) if $vm_type eq 'lxc'; + my $disk = undef; my $stor = undef; if($line =~ m/^(?:((?:virtio|ide|scsi|sata|mp)\d+)|rootfs): (.+:)([A-Za-z0-9\-]+),(.*)$/) { $disk = $3; $stor = $2; } else { - die "disk is not on ZFS Storage\n"; + print "Disk: \"$line\" will not include in pve-sync\n" if $get_err || $error; + next; } my $cmd = []; @@ -796,6 +808,7 @@ sub parse_disks { } } + die "Vm include no disk on zfs.\n" if !$disks->{0}; return $disks; } -- 2.39.2