]> git.proxmox.com Git - pve-guest-common.git/blobdiff - PVE/Replication.pm
change replica log timestamp to a human readable format
[pve-guest-common.git] / PVE / Replication.pm
index 7686222fbba675c59ba4e44df8a64c68edc02857..5a7274e79519a726642e9cef7c5483469de52cd5 100644 (file)
@@ -5,6 +5,7 @@ use strict;
 use Data::Dumper;
 use JSON;
 use Time::HiRes qw(gettimeofday tv_interval);
+use POSIX qw(strftime);
 
 use PVE::INotify;
 use PVE::ProcFSTools;
@@ -19,7 +20,7 @@ use PVE::ReplicationState;
 # regression tests should overwrite this
 sub get_log_time {
 
-    return time();
+    return strftime("%F %H:%M:%S", localtime);
 }
 
 # Find common base replication snapshot, available on local and remote side.
@@ -208,7 +209,7 @@ sub replicate {
        PVE::ReplicationConfig::delete_job($jobid); # update config
        $logfunc->("job removed");
 
-       return;
+       return undef;
     }
 
     my $ssh_info = PVE::Cluster::get_ssh_info($jobcfg->{target}, $migration_network);
@@ -296,13 +297,17 @@ sub replicate {
     remote_finalize_local_job($ssh_info, $jobid, $vmid, $sorted_volids, $start_time, $logfunc);
 
     die $err if $err;
+
+    return $volumes;
 }
 
 my $run_replication_nolock = sub {
-    my ($guest_class, $jobcfg, $iteration, $start_time, $logfunc) = @_;
+    my ($guest_class, $jobcfg, $iteration, $start_time, $logfunc, $verbose) = @_;
 
     my $jobid = $jobcfg->{id};
 
+    my $volumes;
+
     # we normaly write errors into the state file,
     # but we also catch unexpected errors and log them to syslog
     # (for examply when there are problems writing the state file)
@@ -323,13 +328,19 @@ my $run_replication_nolock = sub {
 
            my $ctime = get_log_time();
            print $logfd "$ctime $jobid: $msg\n";
-           $logfunc->("$ctime $jobid: $msg") if $logfunc;
+           if ($logfunc) {
+               if ($verbose) {
+                   $logfunc->("$ctime $jobid: $msg");
+               } else {
+                   $logfunc->($msg);
+               }
+           }
        };
 
        $logfunc_wrapper->("start replication job");
 
        eval {
-           replicate($guest_class, $jobcfg, $state, $start_time, $logfunc_wrapper);
+           $volumes = replicate($guest_class, $jobcfg, $state, $start_time, $logfunc_wrapper);
        };
        my $err = $@;
 
@@ -347,21 +358,26 @@ my $run_replication_nolock = sub {
     if (my $err = $@) {
        warn "$jobid: got unexpected replication job error - $err";
     }
+
+    return $volumes;
 };
 
 sub run_replication {
-    my ($guest_class, $jobcfg, $iteration, $start_time, $logfunc, $noerr) = @_;
+    my ($guest_class, $jobcfg, $iteration, $start_time, $logfunc, $noerr, $verbose) = @_;
+
+    my $volumes;
 
     eval {
        my $timeout = 2; # do not wait too long - we repeat periodically anyways
-       PVE::GuestHelpers::guest_migration_lock(
+       $volumes = PVE::GuestHelpers::guest_migration_lock(
            $jobcfg->{guest}, $timeout, $run_replication_nolock,
-           $guest_class, $jobcfg, $iteration, $start_time, $logfunc);
+           $guest_class, $jobcfg, $iteration, $start_time, $logfunc, $verbose);
     };
     if (my $err = $@) {
        return undef if $noerr;
        die $err;
     }
+    return $volumes;
 }
 
 1;