]> git.proxmox.com Git - pve-zsync.git/blobdiff - pve-zsync
bump version to 1.7-4
[pve-zsync.git] / pve-zsync
index 1d868e13e054d4a0aa21a37757879717ea3905eb..425ffa2a5220ec001956e9567b59e9fbfb9a9b01 100755 (executable)
--- a/pve-zsync
+++ b/pve-zsync
@@ -2,10 +2,9 @@
 
 use strict;
 use warnings;
-use Data::Dumper qw(Dumper);
+
 use Fcntl qw(:flock SEEK_END);
 use Getopt::Long qw(GetOptionsFromArray);
-use File::Copy qw(move);
 use File::Path qw(make_path);
 use JSON;
 use IO::File;
@@ -22,7 +21,16 @@ my $LXC_CONF = "${PVE_DIR}/lxc";
 my $LOCKFILE = "$CONFIG_PATH/${PROGNAME}.lock";
 my $PROG_PATH = "$PATH/${PROGNAME}";
 my $INTERVAL = 15;
-my $DEBUG = 0;
+my $DEBUG;
+
+BEGIN {
+    $DEBUG = 0; # change default here. not above on declaration!
+    $DEBUG ||= $ENV{ZSYNC_DEBUG};
+    if ($DEBUG) {
+       require Data::Dumper;
+       Data::Dumper->import();
+    }
+}
 
 my $IPV4OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
@@ -55,10 +63,9 @@ if (defined($command) && $command ne 'help' && $command ne 'printpod') {
     check_bin ('scp');
 }
 
-$SIG{TERM} = $SIG{QUIT} = $SIG{PIPE} = $SIG{HUP} = $SIG{KILL} = $SIG{INT} =
-    sub {
-       die "Signal aborting sync\n";
-    };
+$SIG{TERM} = $SIG{QUIT} = $SIG{PIPE} = $SIG{HUP} = $SIG{KILL} = $SIG{INT} =  sub {
+    die "Signaled, aborting sync: $!\n";
+};
 
 sub check_bin {
     my ($bin)  = @_;
@@ -213,6 +220,7 @@ sub parse_argv {
        source_user => undef,
        dest_user => undef,
        properties => undef,
+       dest_config_path => undef,
     };
 
     my ($ret) = GetOptionsFromArray(
@@ -228,6 +236,7 @@ sub parse_argv {
        'source-user=s' => \$param->{source_user},
        'dest-user=s' => \$param->{dest_user},
        'properties' => \$param->{properties},
+       'dest-config-path=s' => \$param->{dest_config_path},
     );
 
     die "can't parse options\n" if $ret == 0;
@@ -296,7 +305,8 @@ sub param_to_job {
     $job->{source} = $param->{source};
     $job->{source_user} = $param->{source_user};
     $job->{dest_user} = $param->{dest_user};
-    $job->{properties} = $param->{properties} ? $param->{properties} : 0;
+    $job->{properties} = !!$param->{properties};
+    $job->{dest_config_path} = $param->{dest_config_path} if $param->{dest_config_path};
 
     return $job;
 }
@@ -365,7 +375,7 @@ sub update_state {
     print $out_fh $text;
 
     close($out_fh);
-    move("$STATE.new", $STATE);
+    rename "$STATE.new", $STATE;
     eval {
        close($in_fh);
     };
@@ -417,7 +427,7 @@ sub update_cron {
     die "can't write to $CRONJOBS.new\n" if !print($new_fh $text);
     close ($new_fh);
 
-    die "can't move $CRONJOBS.new: $!\n" if !move("${CRONJOBS}.new", "$CRONJOBS");
+    die "can't move $CRONJOBS.new: $!\n" if !rename "${CRONJOBS}.new", $CRONJOBS;
     close ($fh);
 }
 
@@ -442,7 +452,8 @@ sub format_job {
     $text .= " --verbose" if $job->{verbose};
     $text .= " --source-user $job->{source_user}";
     $text .= " --dest-user $job->{dest_user}";
-    $text .= " --properties $job->{properties}" if $job->{properties};
+    $text .= " --properties" if $job->{properties};
+    $text .= " --dest-config-path $job->{dest_config_path}" if $job->{dest_config_path};
     $text .= "\n";
 
     return $text;
@@ -620,9 +631,9 @@ sub sync {
                &$sync_path($source, $dest, $job, $param, $date);
            }
            if ($param->{method} eq "ssh" && ($source->{ip} || $dest->{ip})) {
-               send_config($source, $dest,'ssh', $param->{source_user}, $param->{dest_user});
+               send_config($source, $dest,'ssh', $param->{source_user}, $param->{dest_user}, $param->{dest_config_path});
            } else {
-               send_config($source, $dest,'local', $param->{source_user}, $param->{dest_user});
+               send_config($source, $dest,'local', $param->{source_user}, $param->{dest_user}, $param->{dest_config_path});
            }
        } else {
            &$sync_path($source, $dest, $job, $param, $date);
@@ -956,12 +967,13 @@ sub send_image {
 
 
 sub send_config{
-    my ($source, $dest, $method, $source_user, $dest_user) = @_;
+    my ($source, $dest, $method, $source_user, $dest_user, $dest_config_path) = @_;
 
     my $source_target = $source->{vm_type} eq 'qemu' ? "$QEMU_CONF/$source->{vmid}.conf": "$LXC_CONF/$source->{vmid}.conf";
     my $dest_target_new ="$source->{vmid}.conf.$source->{vm_type}.$source->{new_snap}";
 
-    my $config_dir = $dest->{last_part} ?  "${CONFIG_PATH}/$dest->{last_part}" : $CONFIG_PATH;
+    my $config_dir = $dest_config_path // $CONFIG_PATH;
+    $config_dir .= "/$dest->{last_part}" if $dest->{last_part};
 
     $dest_target_new = $config_dir.'/'.$dest_target_new;
 
@@ -1088,6 +1100,10 @@ $PROGNAME create -dest <string> -source <string> [OPTIONS]
        -properties     boolean
 
                Include the dataset's properties in the stream.
+
+       -dest-config-path    string
+
+               specify a custom config path on the destination target. default is /var/lib/pve-zsync
     },
     sync => qq{
 $PROGNAME sync -dest <string> -source <string> [OPTIONS]\n
@@ -1130,6 +1146,10 @@ $PROGNAME sync -dest <string> -source <string> [OPTIONS]\n
        -properties     boolean
 
                Include the dataset's properties in the stream.
+
+       -dest-config-path    string
+
+               specify a custom config path on the destination target. default is /var/lib/pve-zsync
     },
     list => qq{
 $PROGNAME list