示例#1
0
    def test_lookup_compression(self):
        """Test looking up compression methods"""
        cmd, ext = compression.lookup_compression("gzip")
        self.assertNotEqual(cmd, None)
        self.assertNotEqual(ext, None)

        cmd, ext = compression.lookup_compression("bzip2")
        self.assertNotEqual(cmd, None)
        self.assertNotEqual(ext, None)

        cmd, ext = compression.lookup_compression("lzop")
        self.assertNotEqual(cmd, None)
        self.assertNotEqual(ext, None)
示例#2
0
    def _backup(self):
        """Real backup method.  May raise BackupError exceptions"""
        config = self.config['mysqldump']
        # setup defaults_file with ignore-table exclusions
        defaults_file = os.path.join(self.target_directory, 'my.cnf')
        write_options(self.mysql_config, defaults_file)
        if config['exclude-invalid-views']:
            LOG.info("* Finding and excluding invalid views...")
            definitions_path = os.path.join(self.target_directory,
                                            'invalid_views.sql')
            exclude_invalid_views(self.schema, self.client, definitions_path)
        add_exclusions(self.schema, defaults_file)
        # find the path to the mysqldump command
        mysqldump_bin = find_mysqldump(path=config['mysql-binpath'])
        LOG.info("Using mysqldump executable: %s", mysqldump_bin)
        # setup the mysqldump environment
        extra_defaults = config['extra-defaults']
        try:
            mysqldump = MySQLDump(defaults_file,
                                  mysqldump_bin,
                                  extra_defaults=extra_defaults)
        except MySQLDumpError as exc:
            raise BackupError(str(exc))
        except Exception as ex:
            LOG.warning(ex)
        LOG.info("mysqldump version %s",
                 '.'.join([str(digit) for digit in mysqldump.version]))
        options = collect_mysqldump_options(config, mysqldump, self.client)
        validate_mysqldump_options(mysqldump, options)

        os.mkdir(os.path.join(self.target_directory, 'backup_data'))

        if self.config['compression']['method'] != 'none' and \
            self.config['compression']['level'] > 0:
            try:
                cmd, ext = lookup_compression(
                    self.config['compression']['method'])
            except OSError as exc:
                raise BackupError(
                    "Unable to load compression method '%s': %s" %
                    (self.config['compression']['method'], exc))
            LOG.info("Using %s compression level %d with args %s",
                     self.config['compression']['method'],
                     self.config['compression']['level'],
                     self.config['compression']['options'])
        else:
            LOG.info("Not compressing mysqldump output")
            cmd = ''
            ext = ''

        try:
            start(mysqldump=mysqldump,
                  schema=self.schema,
                  lock_method=config['lock-method'],
                  file_per_database=config['file-per-database'],
                  open_stream=self._open_stream,
                  compression_ext=ext,
                  arg_per_database=config['arg-per-database'])
        except MySQLDumpError as exc:
            raise BackupError(str(exc))
示例#3
0
def test_lookup_compression():
    global tmpdir

    # should get something back, None if the method wasn't found
    cmd, ext = compression.lookup_compression('gzip')
    assert_not_equal(cmd, None)
    assert_not_equal(ext, None)

    # should get something back, None if the method wasn't found
    cmd, ext = compression.lookup_compression('bzip2')
    assert_not_equal(cmd, None)
    assert_not_equal(ext, None)

    # should get something back, None if the method wasn't found
    cmd, ext = compression.lookup_compression('lzop')
    assert_not_equal(cmd, None)
    assert_not_equal(ext, None)

    # this should fail
    cmd, ext = compression.lookup_compression('bogus_compression')
    assert_equal(cmd, None)
    assert_equal(ext, None)
def test_lookup_compression():
    global tmpdir
    
    # should get something back, None if the method wasn't found
    cmd, ext = compression.lookup_compression('gzip')
    assert_not_equal(cmd, None)
    assert_not_equal(ext, None)
    
    # should get something back, None if the method wasn't found
    cmd, ext = compression.lookup_compression('bzip2')
    assert_not_equal(cmd, None)
    assert_not_equal(ext, None)
    
    # should get something back, None if the method wasn't found
    cmd, ext = compression.lookup_compression('lzop')
    assert_not_equal(cmd, None)
    assert_not_equal(ext, None)
    
    # this should fail
    cmd, ext = compression.lookup_compression('bogus_compression')
    assert_equal(cmd, None)
    assert_equal(ext, None)
示例#5
0
文件: plugin.py 项目: chder/holland
                                  mysqldump_bin,
                                  extra_defaults=extra_defaults)
        except MySQLDumpError, exc:
            raise BackupError(str(exc))

        LOG.info("mysqldump version %s",
                 '.'.join([str(digit) for digit in mysqldump.version]))
        options = collect_mysqldump_options(config, mysqldump, self.client)
        validate_mysqldump_options(mysqldump, options)

        os.mkdir(os.path.join(self.target_directory, 'backup_data'))

        if self.config['compression']['method'] != 'none' and \
            self.config['compression']['level'] > 0:
            try:
                cmd, ext = lookup_compression(
                    self.config['compression']['method'])
            except OSError, exc:
                raise BackupError(
                    "Unable to load compression method '%s': %s" %
                    (self.config['compression']['method'], exc))
            LOG.info("Using %s compression level %d with args %s",
                     self.config['compression']['method'],
                     self.config['compression']['level'],
                     self.config['compression']['options'])
        else:
            LOG.info("Not compressing mysqldump output")
            cmd = ''
            ext = ''

        try:
            start(mysqldump=mysqldump,
示例#6
0
文件: plugin.py 项目: heryke/holland
    def _backup(self):
        """Real backup method.  May raise BackupError exceptions"""
        config = self.config["mysqldump"]
        # setup defaults_file with ignore-table exclusions
        defaults_file = os.path.join(self.target_directory, "my.cnf")
        write_options(self.mysql_config, defaults_file)
        if config["exclude-invalid-views"]:
            LOG.info("* Finding and excluding invalid views...")
            definitions_path = os.path.join(self.target_directory,
                                            "invalid_views.sql")
            exclude_invalid_views(self.schema, self.client, definitions_path)
        add_exclusions(self.schema, defaults_file)
        # find the path to the mysqldump command
        mysqldump_bin = find_mysqldump(path=config["mysql-binpath"])
        LOG.info("Using mysqldump executable: %s", mysqldump_bin)
        # setup the mysqldump environment
        extra_defaults = config["extra-defaults"]
        try:
            mysqldump = MySQLDump(defaults_file,
                                  mysqldump_bin,
                                  extra_defaults=extra_defaults,
                                  mock_env=self.mock_env)
        except MySQLDumpError as exc:
            raise BackupError(str(exc))
        except Exception as ex:  # pylint: disable=W0703
            LOG.warning(ex)
        mysqldump_version = ".".join(
            [str(digit) for digit in mysqldump.version])
        LOG.info("mysqldump version %s", mysqldump_version)
        options = collect_mysqldump_options(config, mysqldump, self.client)
        validate_mysqldump_options(mysqldump, options)

        os.mkdir(os.path.join(self.target_directory, "backup_data"))

        if (self.config["compression"]["method"] != "none"
                and self.config["compression"]["level"] > 0):
            try:
                _, ext = lookup_compression(
                    self.config["compression"]["method"])
            except OSError as exc:
                raise BackupError(
                    "Unable to load compression method '%s': %s" %
                    (self.config["compression"]["method"], exc))
            LOG.info(
                "Using %s compression level %d with args %s",
                self.config["compression"]["method"],
                self.config["compression"]["level"],
                self.config["compression"]["options"],
            )
        else:
            LOG.info("Not compressing mysqldump output")
            ext = ""

        try:
            start(
                mysqldump=mysqldump,
                schema=self.schema,
                lock_method=config["lock-method"],
                file_per_database=config["file-per-database"],
                open_stream=self._open_stream,
                compression_ext=ext,
                arg_per_database=config["arg-per-database"],
            )
        except MySQLDumpError as exc:
            raise BackupError(str(exc))
示例#7
0
    def _backup(self):
        """Real backup method.  May raise BackupError exceptions"""
        config = self.config["mysqldump"]
        # setup defaults_file with ignore-table exclusions
        defaults_file = os.path.join(self.target_directory, "my.cnf")
        write_options(self.mysql_config, defaults_file)
        if config["exclude-invalid-views"]:
            LOG.info("* Finding and excluding invalid views...")
            definitions_path = os.path.join(self.target_directory, "invalid_views.sql")
            exclude_invalid_views(self.schema, self.client, definitions_path)
        add_exclusions(self.schema, defaults_file)
        # find the path to the mysqldump command
        mysqldump_bin = find_mysqldump(path=config["mysql-binpath"])
        LOG.info("Using mysqldump executable: %s", mysqldump_bin)
        # setup the mysqldump environment
        extra_defaults = config["extra-defaults"]
        try:
            mysqldump = MySQLDump(
                defaults_file, mysqldump_bin, extra_defaults=extra_defaults, mock_env=self.mock_env
            )
        except MySQLDumpError as exc:
            raise BackupError(str(exc))
        except Exception as ex:  # pylint: disable=W0703
            LOG.warning(ex)
        mysqldump_version = ".".join([str(digit) for digit in mysqldump.version])
        LOG.info("mysqldump version %s", mysqldump_version)
        options = collect_mysqldump_options(config, mysqldump, self.client)
        validate_mysqldump_options(mysqldump, options)

        os.mkdir(os.path.join(self.target_directory, "backup_data"))

        if (
            self.config["compression"]["method"] != "none"
            and self.config["compression"]["level"] > 0
        ):
            try:
                _, ext = lookup_compression(self.config["compression"]["method"])
            except OSError as exc:
                raise BackupError(
                    "Unable to load compression method '%s': %s"
                    % (self.config["compression"]["method"], exc)
                )
            LOG.info(
                "Using %s compression level %d with args %s",
                self.config["compression"]["method"],
                self.config["compression"]["level"],
                self.config["compression"]["options"],
            )
        else:
            LOG.info("Not compressing mysqldump output")
            ext = ""

        try:
            start(
                mysqldump=mysqldump,
                schema=self.schema,
                lock_method=config["lock-method"],
                file_per_database=config["file-per-database"],
                open_stream=self._open_stream,
                compression_ext=ext,
                arg_per_database=config["arg-per-database"],
            )
        except MySQLDumpError as exc:
            raise BackupError(str(exc))
示例#8
0
        # setup the mysqldump environment
        extra_defaults = config["extra-defaults"]
        try:
            mysqldump = MySQLDump(defaults_file, mysqldump_bin, extra_defaults=extra_defaults)
        except MySQLDumpError, exc:
            raise BackupError(str(exc))

        LOG.info("mysqldump version %s", ".".join([str(digit) for digit in mysqldump.version]))
        options = collect_mysqldump_options(config, mysqldump, self.client)
        validate_mysqldump_options(mysqldump, options)

        os.mkdir(os.path.join(self.target_directory, "backup_data"))

        if self.config["compression"]["method"] != "none" and self.config["compression"]["level"] > 0:
            cmd, ext = lookup_compression(self.config["compression"]["method"])
            LOG.info("Using %s compression level %d", cmd, self.config["compression"]["level"])
        else:
            LOG.info("Not compressing mysqldump output")
            cmd = ""
            ext = ""

        try:
            start(
                mysqldump=mysqldump,
                schema=self.schema,
                lock_method=config["lock-method"],
                file_per_database=config["file-per-database"],
                open_stream=self._open_stream,
                compression_ext=ext,
            )
示例#9
0
                                  mysqldump_bin, 
                                  extra_defaults=extra_defaults)
        except MySQLDumpError, exc:
            raise BackupError(str(exc))

        LOG.info("mysqldump version %s", '.'.join([str(digit)
                for digit in mysqldump.version]))
        options = collect_mysqldump_options(config, mysqldump, self.client)
        validate_mysqldump_options(mysqldump, options)

        os.mkdir(os.path.join(self.target_directory, 'backup_data'))

        if self.config['compression']['method'] != 'none' and \
            self.config['compression']['level'] > 0:
            try:
                cmd, ext = lookup_compression(self.config['compression']['method'])
            except OSError, exc:
                raise BackupError("Unable to load compression method '%s': %s" %
                                  (self.config['compression']['method'], exc))
            LOG.info("Using %s compression level %d with args %s",
                     self.config['compression']['method'],
                     self.config['compression']['level'],
                     self.config['compression']['options'])
        else:
            LOG.info("Not compressing mysqldump output")
            cmd = ''
            ext = ''

        try:
            start(mysqldump=mysqldump,
                  schema=self.schema,