Exemple #1
0
 def checkRemoteServer(self):
   """Checks if a connection to the remote server can be established"""
   self.logger.logmsg('DEBUG', _('Attempting to connect to server %s...') % self.options['RemoteHost'])
   thread = fwbackups.runFuncAsThread(sftp.testConnection,
                                      self.options['RemoteHost'], self.options['RemoteUsername'],
                                      self.options['RemotePassword'], self.options['RemotePort'],
                                      self.options['RemoteFolder'])
   while thread.retval == None:
     time.sleep(0.1)
   # Check for errors, if any
   import paramiko
   import socket
   if thread.retval == True:
     self.logger.logmsg('DEBUG', _('Attempt to connect succeeded.'))
     return True
   elif type(thread.exception) == IOError:
     self.logger.logmsg('ERROR', _('The backup destination was either not ' + \
                    'found or it cannot be written to due to insufficient permissions.'))
     return False
   elif type(thread.exception) == paramiko.AuthenticationException:
     self.logger.logmsg('ERROR', _('A connection was established, but authentication ' + \
                     'failed. Please verify the username and password ' + \
                     'and try again.'))
     return False
   elif type(thread.exception) == socket.gaierror or type(thread.exception) == socket.error:
     self.logger.logmsg('ERROR', _('A connection to the server could not be established.\n' + \
                     'Error %(a)s: %(b)s' % {'a': type(thread.exception), 'b': str(thread.exception)} + \
                     '\nPlease verify your settings and try again.'))
     return False
   elif type(thread.exception) == socket.timeout:
     self.logger.logmsg('ERROR', _('A connection to the server has timed out. ' + \
                     'Please verify your settings and try again.'))
     return False
   elif type(thread.exception) == paramiko.SSHException:
     self.logger.logmsg('ERROR', _('A connection to the server could not be established ' + \
                     'because an error occurred: %s' % str(thread.exception) + \
                     '\nPlease verify your settings and try again.'))
     return False
   else: # not remote, just pass
     return True
Exemple #2
0
    def start(self):
        """Restores a backup"""
        wasErrors = False
        if self.options['RemoteSource']:  # check if server settings are OK
            self.logger.logmsg('DEBUG', _('Attempting to connect to server'))
            thread = fwbackups.runFuncAsThread(sftp.testConnection,
                                               self.options['RemoteHost'],
                                               self.options['RemoteUsername'],
                                               self.options['RemotePassword'],
                                               self.options['RemotePort'],
                                               self.options['RemoteSource'])
            while thread.retval == None:
                time.sleep(0.1)
            # Check for errors, if any
            import paramiko
            import socket
            if thread.retval == True:
                pass
            elif type(thread.exception) == IOError:
                self.logger.logmsg('ERROR', _('The restore source was either not ' + \
                               'found or it cannot be read due to insufficient permissions.'))
                return False
            elif type(thread.exception) == paramiko.AuthenticationException:
                self.logger.logmsg('ERROR', _('A connection was established, but authentication ' + \
                                'failed. Please verify the username and password ' + \
                                'and try again.'))
                return False
            elif type(thread.exception) == socket.gaierror or type(
                    thread.exception) == socket.error:
                self.logger.logmsg('ERROR', _('A connection to the server could not be established.\n' + \
                                'Error %(a)s: %(b)s' % {'a': type(thread.exception), 'b': str(thread.exception)} + \
                                '\nPlease verify your settings and try again.'))
                return False
            elif type(thread.exception) == socket.timeout:
                self.logger.logmsg('ERROR', _('A connection to the server has timed out. ' + \
                                'Please verify your settings and try again.'))
                return False
            elif type(thread.exception) == paramiko.SSHException:
                self.logger.logmsg('ERROR', _('A connection to the server could not be established ' + \
                                'because an error occurred: %s' % str(thread.exception) + \
                                '\nPlease verify your settings and try again.'))
                return False
        # source types:     'set' 'local archive' 'local folder'
        #                   'remote archive (SSH)', 'remote folder (SSH)'

        # We don't want to raise a hard error, that's already in the log.
        # So we settle for a simple return false.
        # don't need source type logic, /destination/ is always a folder
        if not self.prepareDestinationFolder(self.options['Destination']):
            return False
        # Receive files from remote server
        if self.options['RemoteSource']:
            self.logger.logmsg('INFO', _('Receiving files from server'))
            self._status = STATUS_RECEIVING_FROM_REMOTE  # receiving files
            try:
                # download file to location where we expect source to be
                client, sftpClient = sftp.connect(
                    self.options['RemoteHost'], self.options['RemoteUsername'],
                    self.options['RemotePassword'], self.options['RemotePort'])
                retval = sftp.receive(sftpClient, self.options['RemoteSource'],
                                      self.options['Destination'])
                # This is used later to terminate the restore operation early
                remoteSourceIsFolder = sftp.isFolder(
                    sftpClient, self.options['RemoteSource'])
                sftpClient.close()
                client.close()
            except Exception, error:
                self.logger.logmsg(
                    'ERROR',
                    _('Could not receive file from server: %s' % error))
                wasErrors = True
            if wasErrors or remoteSourceIsFolder:
                # We are dealing with a remote folder - our job here is done
                # Either that or an error was encountered above
                self.logger.logmsg('INFO', _('Finished restore operation'))
                return not wasErrors
Exemple #3
0
  def start(self):
    """Restores a backup"""
    wasErrors = False
    if self.options['RemoteSource']: # check if server settings are OK
      self.logger.logmsg('DEBUG', _('Attempting to connect to server'))
      thread = fwbackups.runFuncAsThread(sftp.testConnection,
                                         self.options['RemoteHost'], self.options['RemoteUsername'],
                                         self.options['RemotePassword'], self.options['RemotePort'],
                                         self.options['RemoteSource'])
      while thread.retval == None:
        time.sleep(0.1)
      # Check for errors, if any
      import paramiko
      import socket
      if thread.retval == True:
        pass
      elif type(thread.exception) == IOError:
        self.logger.logmsg('ERROR', _('The restore source was either not ' + \
                       'found or it cannot be read due to insufficient permissions.'))
        return False
      elif type(thread.exception) == paramiko.AuthenticationException:
        self.logger.logmsg('ERROR', _('A connection was established, but authentication ' + \
                        'failed. Please verify the username and password ' + \
                        'and try again.'))
        return False
      elif type(thread.exception) == socket.gaierror or type(thread.exception) == socket.error:
        self.logger.logmsg('ERROR', _('A connection to the server could not be established.\n' + \
                        'Error %(a)s: %(b)s' % {'a': type(thread.exception), 'b': str(thread.exception)} + \
                        '\nPlease verify your settings and try again.'))
        return False
      elif type(thread.exception) == socket.timeout:
        self.logger.logmsg('ERROR', _('A connection to the server has timed out. ' + \
                        'Please verify your settings and try again.'))
        return False
      elif type(thread.exception) == paramiko.SSHException:
        self.logger.logmsg('ERROR', _('A connection to the server could not be established ' + \
                        'because an error occurred: %s' % str(thread.exception) + \
                        '\nPlease verify your settings and try again.'))
        return False
    # source types:     'set' 'local archive' 'local folder'
    #                   'remote archive (SSH)', 'remote folder (SSH)'

    # We don't want to raise a hard error, that's already in the log.
    # So we settle for a simple return false.
    # don't need source type logic, /destination/ is always a folder
    if not self.prepareDestinationFolder(self.options['Destination']):
      return False
    # Receive files from remote server
    if self.options['RemoteSource']:
      self.logger.logmsg('INFO', _('Receiving files from server'))
      self._status = STATUS_RECEIVING_FROM_REMOTE # receiving files
      try:
        # download file to location where we expect source to be
        client, sftpClient = sftp.connect(self.options['RemoteHost'], self.options['RemoteUsername'], self.options['RemotePassword'], self.options['RemotePort'])
        retval = sftp.receive(sftpClient, self.options['RemoteSource'], self.options['Destination'])
        # This is used later to terminate the restore operation early
        remoteSourceIsFolder = sftp.isFolder(sftpClient, self.options['RemoteSource'])
        sftpClient.close()
        client.close()
      except Exception, error:
        self.logger.logmsg('ERROR', _('Could not receive file from server: %s' % error))
        wasErrors = True
      if wasErrors or remoteSourceIsFolder:
          # We are dealing with a remote folder - our job here is done
          # Either that or an error was encountered above
          self.logger.logmsg('INFO', _('Finished restore operation'))
          return not wasErrors
Exemple #4
0
    def checkRemoteServer(self):
        """Checks if a connection to the remote server can be established"""
        self.logger.logmsg("DEBUG", _("Attempting to connect to server %s...") % self.options["RemoteHost"])
        thread = fwbackups.runFuncAsThread(
            sftp.testConnection,
            self.options["RemoteHost"],
            self.options["RemoteUsername"],
            self.options["RemotePassword"],
            self.options["RemotePort"],
            self.options["RemoteFolder"],
        )
        while thread.retval == None:
            time.sleep(0.1)
        # Check for errors, if any
        import paramiko
        import socket

        if thread.retval == True:
            self.logger.logmsg("DEBUG", _("Attempt to connect succeeded."))
            return True
        elif type(thread.exception) == IOError:
            self.logger.logmsg(
                "ERROR",
                _(
                    "The backup destination was either not "
                    + "found or it cannot be written to due to insufficient permissions."
                ),
            )
            return False
        elif type(thread.exception) == paramiko.AuthenticationException:
            self.logger.logmsg(
                "ERROR",
                _(
                    "A connection was established, but authentication "
                    + "failed. Please verify the username and password "
                    + "and try again."
                ),
            )
            return False
        elif type(thread.exception) == socket.gaierror or type(thread.exception) == socket.error:
            self.logger.logmsg(
                "ERROR",
                _(
                    "A connection to the server could not be established.\n"
                    + "Error %(a)s: %(b)s" % {"a": type(thread.exception), "b": str(thread.exception)}
                    + "\nPlease verify your settings and try again."
                ),
            )
            return False
        elif type(thread.exception) == socket.timeout:
            self.logger.logmsg(
                "ERROR", _("A connection to the server has timed out. " + "Please verify your settings and try again.")
            )
            return False
        elif type(thread.exception) == paramiko.SSHException:
            self.logger.logmsg(
                "ERROR",
                _(
                    "A connection to the server could not be established "
                    + "because an error occurred: %s" % str(thread.exception)
                    + "\nPlease verify your settings and try again."
                ),
            )
            return False
        else:  # not remote, just pass
            return True