示例#1
0
 def backup_mysql(self):
     """FLag to backup MySQL or not"""
     try:
         return self.__cfg.getboolean("source", "backup_mysql")
     except NoOptionError:
         return False
     except NoSectionError as err:
         LOG.error("Section 'source' is mandatory")
         raise ConfigurationError(err) from err
示例#2
0
 def backup_dirs(self):
     """Directories to backup"""
     try:
         dirs = self.__cfg.get("source", "backup_dirs")
         return split(dirs)
     except NoOptionError:
         return []
     except NoSectionError as err:
         LOG.error("Section 'source' is mandatory")
         raise ConfigurationError(err) from err
示例#3
0
    def destination(self, backup_source=socket.gethostname()):
        """
        :param backup_source: Hostname of the host where backup is taken from.
        :type backup_source: str
        :return: Backup destination instance
        :rtype: BaseDestination
        """
        try:
            backup_destination = self.__cfg.get("destination",
                                                "backup_destination")
            if backup_destination == "ssh":
                return Ssh(
                    self.ssh.path,
                    hostname=backup_source,
                    ssh_host=self.ssh.host,
                    ssh_port=self.ssh.port,
                    ssh_user=self.ssh.user,
                    ssh_key=self.ssh.key,
                )
            elif backup_destination == "s3":
                return S3(
                    bucket=self.s3.bucket,
                    aws_access_key_id=self.s3.aws_access_key_id,
                    aws_secret_access_key=self.s3.aws_secret_access_key,
                    aws_default_region=self.s3.aws_default_region,
                    hostname=backup_source,
                )
            elif backup_destination == "gcs":
                return GCS(
                    bucket=self.gcs.bucket,
                    gc_credentials_file=self.gcs.gc_credentials_file,
                    gc_encryption_key=self.gcs.gc_encryption_key,
                    hostname=backup_source,
                )

            else:
                raise ConfigurationError("Unsupported destination '%s'" %
                                         backup_destination)
        except NoSectionError as err:
            raise ConfigurationError(
                "%s is missing required section 'destination'" %
                self._config_file) from err
示例#4
0
    def __init__(self, **kwargs):
        self._program = kwargs.get("program",
                                   list(COMPRESSION_MODIFIERS.keys())[0])
        if self.program not in COMPRESSION_MODIFIERS:
            raise ConfigurationError("Unsupported compression tool %s" %
                                     self.program)

        self._threads = (int(kwargs.get("threads"))
                         if "threads" in kwargs else None)

        self._level = int(kwargs.get("level")) if "level" in kwargs else None
示例#5
0
    def exporter(self):
        """
        Read config and return export transport instance

        :return: Instance of export transport, if it is set
        :rtype: BaseExporter
        :raise: ConfigurationError, if transport isn't implemented
        """
        try:
            try:
                transport = self.__cfg.get("export", "transport")
                if transport == "datadog":
                    app_key = self.__cfg.get("export", "app_key")
                    api_key = self.__cfg.get("export", "api_key")
                    return DataDogExporter(app_key, api_key)
                else:
                    raise ConfigurationError(
                        "Metric exported '%s' is not implemented" % transport)
            except NoOptionError as err:
                raise ConfigurationError(err) from err

        except NoSectionError:
            return None