parameters: (self, cmd)
return_statement: return True
docstring: Start bareos_vadp_dumper
          Parameters
          - cmd: must be "dump" or "restore"
docstring_summary: Start bareos_vadp_dumper
          Parameters
          - cmd: must be "dump" or "restore"
docstring_tokens: Start bareos_vadp_dumper Parameters - cmd : must be dump or restore
function: def start_dumper(self, cmd):
          """
          Start bareos_vadp_dumper
          Parameters
          - cmd: must be "dump" or "restore"
          """
          bareos_vadp_dumper_bin = "bareos_vadp_dumper_wrapper.sh"
  
          # options for bareos_vadp_dumper:
          # -S: Cleanup on Start
          # -D: Cleanup on Disconnect
          # -M: Save metadata of VMDK on dump action
          # -R: Restore metadata of VMDK on restore action
          # -l: Write to a local VMDK
          # -C: Create local VMDK
          # -d: Specify local VMDK name
          # -f: Specify forced transport method
          # -v - Verbose output
          bareos_vadp_dumper_opts = {}
          bareos_vadp_dumper_opts["dump"] = "-S -D -M"
          if "transport" in self.options:
              bareos_vadp_dumper_opts["dump"] += " -f %s" % self.options["transport"]
          if self.restore_vmdk_file:
              if os.path.exists(self.restore_vmdk_file):
                  # restore of diff/inc, local vmdk exists already,
                  # handling of replace options is done in create_file()
                  bareos_vadp_dumper_opts["restore"] = "-l -R -d "
              else:
                  # restore of full, must pass -C to create local vmdk
                  # and make sure the target directory exists
                  self.mkdir(os.path.dirname(self.restore_vmdk_file))
                  bareos_vadp_dumper_opts["restore"] = "-l -C -R -d "
              bareos_vadp_dumper_opts["restore"] += (
                  '"' + StringCodec.encode(self.restore_vmdk_file) + '"'
              )
          else:
              bareos_vadp_dumper_opts["restore"] = "-S -D -R"
              if "transport" in self.options:
                  bareos_vadp_dumper_opts["restore"] += (
                      " -f %s" % self.options["transport"]
                  )
  
          if self.options.get("vadp_dumper_verbose") == "yes":
              bareos_vadp_dumper_opts[cmd] = "-v " + bareos_vadp_dumper_opts[cmd]
  
          bareosfd.DebugMessage(
              100,
              "start_dumper(): dumper options: %s\n"
              % (repr(bareos_vadp_dumper_opts[cmd])),
          )
  
          bareosfd.DebugMessage(
              100,
              "Type of self.cbt_json_local_file_path is %s\n"
              % (type(self.cbt_json_local_file_path)),
          )
  
          bareosfd.DebugMessage(
              100,
              "self.cbt_json_local_file_path: %s\n" % (self.cbt_json_local_file_path),
          )
  
          bareos_vadp_dumper_command = '%s %s %s "%s"' % (
              bareos_vadp_dumper_bin,
              bareos_vadp_dumper_opts[cmd],
              cmd,
              self.cbt_json_local_file_path,
          )
  
          bareosfd.DebugMessage(
              100,
              "start_dumper(): dumper command(repr): %s\n"
              % (repr(bareos_vadp_dumper_command)),
          )
  
          bareos_vadp_dumper_command_args = shlex.split(bareos_vadp_dumper_command)
          bareosfd.DebugMessage(
              100,
              "start_dumper(): bareos_vadp_dumper_command_args: %s\n"
              % (repr(bareos_vadp_dumper_command_args)),
          )
  
          log_path = "/var/log/bareos"
          if self.options.get("log_path"):
              log_path = self.options["log_path"]
  
          stderr_log_fd = tempfile.NamedTemporaryFile(dir=log_path, delete=False)
  
          bareos_vadp_dumper_process = None
          bareos_vadp_dumper_logfile = None
          try:
              if cmd == "dump":
                  # backup
                  bareos_vadp_dumper_process = subprocess.Popen(
                      bareos_vadp_dumper_command_args,
                      bufsize=-1,
                      stdin=open("/dev/null"),
                      stdout=subprocess.PIPE,
                      stderr=stderr_log_fd,
                      close_fds=True,
                  )
              else:
                  # restore
                  bareos_vadp_dumper_process = subprocess.Popen(
                      bareos_vadp_dumper_command_args,
                      bufsize=-1,
                      stdin=subprocess.PIPE,
                      stdout=open("/dev/null"),
                      stderr=stderr_log_fd,
                      close_fds=True,
                  )
  
              # rename the stderr log file to one containing the JobId and PID
              bareos_vadp_dumper_logfile = "%s/bareos_vadp_dumper.%s-%s.log" % (
                  log_path,
                  bareosfd.GetValue(bareosfd.bVarJobId),
                  bareos_vadp_dumper_process.pid,
              )
              os.rename(stderr_log_fd.name, bareos_vadp_dumper_logfile)
              bareosfd.DebugMessage(
                  100,
                  "start_dumper(): started %s, log stderr to %s\n"
                  % (repr(bareos_vadp_dumper_command), bareos_vadp_dumper_logfile),
              )
  
          except Exception as e:
              # kill children if they arent done
              if bareos_vadp_dumper_process:
                  bareosfd.JobMessage(
                      bareosfd.M_WARNING,
                      "Failed to start %s: %s\n"
                      % (repr(bareos_vadp_dumper_command), str(e)),
                  )
                  if (
                      bareos_vadp_dumper_process is not None
                      and bareos_vadp_dumper_process.returncode is None
                  ):
                      bareosfd.JobMessage(
                          bareosfd.M_WARNING,
                          "Killing probably stuck %s PID %s with signal 9\n"
                          % (
                              repr(bareos_vadp_dumper_command),
                              bareos_vadp_dumper_process.pid,
                          ),
                      )
                      os.kill(bareos_vadp_dumper_process.pid, 9)
                  try:
                      if bareos_vadp_dumper_process is not None:
                          bareosfd.DebugMessage(
                              100,
                              "Waiting for command %s PID %s to terminate\n"
                              % (
                                  repr(bareos_vadp_dumper_command),
                                  bareos_vadp_dumper_process.pid,
                              ),
                          )
                          os.waitpid(bareos_vadp_dumper_process.pid, 0)
                          bareosfd.DebugMessage(
                              100,
                              "Command %s PID %s terminated\n"
                              % (
                                  repr(bareos_vadp_dumper_command),
                                  bareos_vadp_dumper_process.pid,
                              ),
                          )
  
                  except Exception as e:
                      bareosfd.DebugMessage(
                          100,
                          "Failed to wait for PID %s to terminate:%s\n"
                          % (
                              bareos_vadp_dumper_process.pid,
                              str(e),
                          ),
                      )
  
                  raise
              else:
                  raise
  
          # bareos_vadp_dumper should be running now, set the process object
          # for further processing
          self.dumper_process = bareos_vadp_dumper_process
          self.dumper_stderr_log = bareos_vadp_dumper_logfile
  
          # check if dumper is running to catch any error that occured
          # immediately after starting it
          if not self.check_dumper():
              return False
  
          return True
function_tokens: def start_dumper ( self , cmd ) : bareos_vadp_dumper_bin = "bareos_vadp_dumper_wrapper.sh" # options for bareos_vadp_dumper: # -S: Cleanup on Start # -D: Cleanup on Disconnect # -M: Save metadata of VMDK on dump action # -R: Restore metadata of VMDK on restore action # -l: Write to a local VMDK # -C: Create local VMDK # -d: Specify local VMDK name # -f: Specify forced transport method # -v - Verbose output bareos_vadp_dumper_opts = { } bareos_vadp_dumper_opts [ "dump" ] = "-S -D -M" if "transport" in self . options : bareos_vadp_dumper_opts [ "dump" ] += " -f %s" % self . options [ "transport" ] if self . restore_vmdk_file : if os . path . exists ( self . restore_vmdk_file ) : # restore of diff/inc, local vmdk exists already, # handling of replace options is done in create_file() bareos_vadp_dumper_opts [ "restore" ] = "-l -R -d " else : # restore of full, must pass -C to create local vmdk # and make sure the target directory exists self . mkdir ( os . path . dirname ( self . restore_vmdk_file ) ) bareos_vadp_dumper_opts [ "restore" ] = "-l -C -R -d " bareos_vadp_dumper_opts [ "restore" ] += ( '"' + StringCodec . encode ( self . restore_vmdk_file ) + '"' ) else : bareos_vadp_dumper_opts [ "restore" ] = "-S -D -R" if "transport" in self . options : bareos_vadp_dumper_opts [ "restore" ] += ( " -f %s" % self . options [ "transport" ] ) if self . options . get ( "vadp_dumper_verbose" ) == "yes" : bareos_vadp_dumper_opts [ cmd ] = "-v " + bareos_vadp_dumper_opts [ cmd ] bareosfd . DebugMessage ( 100 , "start_dumper(): dumper options: %s\n" % ( repr ( bareos_vadp_dumper_opts [ cmd ] ) ) , ) bareosfd . DebugMessage ( 100 , "Type of self.cbt_json_local_file_path is %s\n" % ( type ( self . cbt_json_local_file_path ) ) , ) bareosfd . DebugMessage ( 100 , "self.cbt_json_local_file_path: %s\n" % ( self . cbt_json_local_file_path ) , ) bareos_vadp_dumper_command = '%s %s %s "%s"' % ( bareos_vadp_dumper_bin , bareos_vadp_dumper_opts [ cmd ] , cmd , self . cbt_json_local_file_path , ) bareosfd . DebugMessage ( 100 , "start_dumper(): dumper command(repr): %s\n" % ( repr ( bareos_vadp_dumper_command ) ) , ) bareos_vadp_dumper_command_args = shlex . split ( bareos_vadp_dumper_command ) bareosfd . DebugMessage ( 100 , "start_dumper(): bareos_vadp_dumper_command_args: %s\n" % ( repr ( bareos_vadp_dumper_command_args ) ) , ) log_path = "/var/log/bareos" if self . options . get ( "log_path" ) : log_path = self . options [ "log_path" ] stderr_log_fd = tempfile . NamedTemporaryFile ( dir = log_path , delete = False ) bareos_vadp_dumper_process = None bareos_vadp_dumper_logfile = None try : if cmd == "dump" : # backup bareos_vadp_dumper_process = subprocess . Popen ( bareos_vadp_dumper_command_args , bufsize = - 1 , stdin = open ( "/dev/null" ) , stdout = subprocess . PIPE , stderr = stderr_log_fd , close_fds = True , ) else : # restore bareos_vadp_dumper_process = subprocess . Popen ( bareos_vadp_dumper_command_args , bufsize = - 1 , stdin = subprocess . PIPE , stdout = open ( "/dev/null" ) , stderr = stderr_log_fd , close_fds = True , ) # rename the stderr log file to one containing the JobId and PID bareos_vadp_dumper_logfile = "%s/bareos_vadp_dumper.%s-%s.log" % ( log_path , bareosfd . GetValue ( bareosfd . bVarJobId ) , bareos_vadp_dumper_process . pid , ) os . rename ( stderr_log_fd . name , bareos_vadp_dumper_logfile ) bareosfd . DebugMessage ( 100 , "start_dumper(): started %s, log stderr to %s\n" % ( repr ( bareos_vadp_dumper_command ) , bareos_vadp_dumper_logfile ) , ) except Exception as e : # kill children if they arent done if bareos_vadp_dumper_process : bareosfd . JobMessage ( bareosfd . M_WARNING , "Failed to start %s: %s\n" % ( repr ( bareos_vadp_dumper_command ) , str ( e ) ) , ) if ( bareos_vadp_dumper_process is not None and bareos_vadp_dumper_process . returncode is None ) : bareosfd . JobMessage ( bareosfd . M_WARNING , "Killing probably stuck %s PID %s with signal 9\n" % ( repr ( bareos_vadp_dumper_command ) , bareos_vadp_dumper_process . pid , ) , ) os . kill ( bareos_vadp_dumper_process . pid , 9 ) try : if bareos_vadp_dumper_process is not None : bareosfd . DebugMessage ( 100 , "Waiting for command %s PID %s to terminate\n" % ( repr ( bareos_vadp_dumper_command ) , bareos_vadp_dumper_process . pid , ) , ) os . waitpid ( bareos_vadp_dumper_process . pid , 0 ) bareosfd . DebugMessage ( 100 , "Command %s PID %s terminated\n" % ( repr ( bareos_vadp_dumper_command ) , bareos_vadp_dumper_process . pid , ) , ) except Exception as e : bareosfd . DebugMessage ( 100 , "Failed to wait for PID %s to terminate:%s\n" % ( bareos_vadp_dumper_process . pid , str ( e ) , ) , ) raise else : raise # bareos_vadp_dumper should be running now, set the process object # for further processing self . dumper_process = bareos_vadp_dumper_process self . dumper_stderr_log = bareos_vadp_dumper_logfile # check if dumper is running to catch any error that occured # immediately after starting it if not self . check_dumper ( ) : return False return True