check_bin ('ssh');
check_bin ('scp');
+$SIG{TERM} = $SIG{QUIT} = $SIG{PIPE} = $SIG{HUP} = $SIG{KILL} = $SIG{INT} =
+ sub {
+ die "Signal aborting sync\n";
+ };
+
sub check_bin {
my ($bin) = @_;
}
sub cut_target_width {
- my ($target, $max) = @_;
+ my ($path, $maxlen) = @_;
+ $path =~ s@/+@/@g;
+
+ return $path if length($path) <= $maxlen;
- return $target if (length($target) <= $max);
- my @spl = split('/', $target);
+ return '..'.substr($path, -$maxlen+2) if $path !~ m@/@;
- my $count = length($spl[@spl-1]);
- return "..\/".substr($spl[@spl-1],($count-$max)+3 , $count) if $count > $max;
+ $path =~ s@/([^/]+/?)$@@;
+ my $tail = $1;
+
+ if (length($tail)+3 == $maxlen) {
+ return "../$tail";
+ } elsif (length($tail)+2 >= $maxlen) {
+ return '..'.substr($tail, -$maxlen+2)
+ }
- $count += length($spl[0]) if @spl > 1;
- return substr($spl[0], 0, $max-4-length($spl[@spl-1]))."\/..\/".$spl[@spl-1] if $count > $max;
+ $path =~ s@(/[^/]+)(?:/|$)@@;
+ my $head = $1;
+ my $both = length($head) + length($tail);
+ my $remaining = $maxlen-$both-4; # -4 for "/../"
- my $rest = 1;
- $rest = $max-$count if ($max-$count > 0);
+ if ($remaining < 0) {
+ return substr($head, 0, $maxlen - length($tail) - 3) . "../$tail"; # -3 for "../"
+ }
- return "$spl[0]".substr($target, length($spl[0]), $rest)."..\/".$spl[@spl-1];
+ substr($path, ($remaining/2), (length($path)-$remaining), '..');
+ return "$head/" . $path . "/$tail";
}
sub lock {
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};
+ get_disks($source) if $source->{vmid};
update_cron($job);
update_state($job);
while ($raw && $raw =~ s/^(.*?)(\n|$)//) {
$line = $1;
- if ($line =~ m/(rep_$name.*)$/) {
+ if ($line =~ m/(rep_\Q${name}\E_\d{4}-\d{2}-\d{2}_\d{2}:\d{2}:\d{2})$/) {
$last_snap = $1 if (!$last_snap);
$old_snap = $1;
}
sub get_disks {
- my ($target, $get_err) = @_;
+ my ($target) = @_;
my $cmd = [];
push @$cmd, 'ssh', "root\@$target->{ip}", '--', if $target->{ip};
my $res = run_cmd($cmd);
- my $disks = parse_disks($res, $target->{ip}, $target->{vm_type}, $get_err);
+ my $disks = parse_disks($res, $target->{ip}, $target->{vm_type});
return $disks;
}
}
sub parse_disks {
- my ($text, $ip, $vm_type, $get_err) = @_;
+ my ($text, $ip, $vm_type) = @_;
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)/)';
+ 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';
+ next if $vm_type eq 'lxc' && ($line =~ m/^mp\d:/) && ($line !~ m/backup=(?i:1|yes|on|true)/);
my $disk = undef;
my $stor = undef;
last;
}
}
-
- } else {
- print "Disk: \"$line\" will not include in pve-sync\n" if $get_err || $error;
+ }
+ if (!defined($disk) || !defined($stor)) {
+ print "Disk: \"$line\" has no valid zfs dataset format and will be skipped\n";
next;
}