示例#1
0
文件: plugin.py 项目: chder/holland
 def __init__(self, name, config, target_directory, dry_run=False):
     self.config = config
     self.config.validate_config(self.configspec())
     LOG.debug("Validated config: %r", self.config)
     self.name = name
     self.target_directory = target_directory
     self.dry_run = dry_run
     self.client = connect_simple(self.config['mysql:client'])
示例#2
0
 def __init__(self, name, config, target_directory, dry_run=False):
     self.config = config
     self.config.validate_config(self.configspec())
     LOG.debug("Validated config: %r", self.config)
     self.name = name
     self.target_directory = target_directory
     self.dry_run = dry_run
     self.client = connect_simple(self.config["mysql:client"])
示例#3
0
文件: plugin.py 项目: heryke/holland
 def __init__(self, name, config, target_directory, dry_run=False):
     self.config = config
     self.config.validate_config(self.CONFIGSPEC)
     LOG.debug("Validated config: %r", self.config)
     self.name = name
     self.target_directory = target_directory
     self.dry_run = dry_run
     self.client = connect_simple(self.config["mysql:client"])
     self.mysqldump_plugin = MySQLDumpPlugin(name, config, target_directory, dry_run)
示例#4
0
 def __init__(self, name, config, target_directory, dry_run=False):
     self.config = config
     self.config.validate_config(self.CONFIGSPEC)
     LOG.debug("Validated config: %r", self.config)
     self.name = name
     self.target_directory = target_directory
     self.dry_run = dry_run
     self.client = connect_simple(self.config["mysql:client"])
     self.mysqldump_plugin = MySQLDumpPlugin(name, config, target_directory, dry_run)
示例#5
0
 def __init__(self, name, config, target_directory, dry_run=False):
     self.config = config
     self.config.validate_config(self.configspec())
     LOG.debug("Validated config: %r", self.config)
     self.name = name
     self.target_directory = target_directory
     self.dry_run = dry_run
     self.datadir = self.config['mysql-lvm']['data-dir']
     self.use_mysql = self.config['mysql-lvm']['use-mysql']
     self.client = None
     if self.use_mysql:
         self.client = connect_simple(self.config['mysql:client'])
示例#6
0
文件: util.py 项目: soulen3/holland
def setup_actions(snapshot, config, client, snap_datadir, spooldir):
    """Setup actions for a LVM snapshot based on the provided
    configuration.

    Optional actions:
        * MySQL locking
        * InnoDB recovery
        * Recording MySQL replication
    """
    mysql = connect_simple(config['mysql:client'])
    if mysql.show_variable('have_innodb') == 'YES':
        try:
            pathinfo = MySQLPathInfo.from_mysql(mysql)
        finally:
            mysql.close()
        try:
            check_innodb(pathinfo, ensure_subdir_of_datadir=True)
        except BackupError:
            if not config['mysql-lvm']['force-innodb-backup']:
                raise

    if config['mysql-lvm']['lock-tables']:
        extra_flush = config['mysql-lvm']['extra-flush-tables']
        act = FlushAndLockMySQLAction(client, extra_flush)
        snapshot.register('pre-snapshot', act, priority=100)
        snapshot.register('post-snapshot', act, priority=100)
    if config['mysql-lvm'].get('replication', True):
        repl_cfg = config.setdefault('mysql:replication', {})
        act = RecordMySQLReplicationAction(client, repl_cfg)
        snapshot.register('pre-snapshot', act, 0)
    if config['mysql-lvm']['innodb-recovery']:
        mysqld_config = dict(config['mysqld'])
        mysqld_config['datadir'] = snap_datadir
        if not mysqld_config['tmpdir']:
            mysqld_config['tmpdir'] = tempfile.gettempdir()
        ib_log_size = client.show_variable('innodb_log_file_size')
        mysqld_config['innodb-log-file-size'] = ib_log_size
        act = InnodbRecoveryAction(mysqld_config)
        snapshot.register('post-mount', act, priority=100)

    try:
        archive_stream = open_stream(
            os.path.join(spooldir, 'backup.tar'),
            'w',
            method=config['compression']['method'],
            level=config['compression']['level'],
            extra_args=config['compression']['options'])
    except OSError, exc:
        raise BackupError("Unable to create archive file '%s': %s" %
                          (os.path.join(spooldir, 'backup.tar'), exc))
示例#7
0
def setup_actions(snapshot, config, client, snap_datadir, spooldir):
    """Setup actions for a LVM snapshot based on the provided
    configuration.

    Optional actions:
        * MySQL locking
        * InnoDB recovery
        * Recording MySQL replication
    """
    if client is not None:
        mysql = connect_simple(config['mysql:client'])
        if mysql.show_variable('have_innodb') == 'YES':
            try:
                pathinfo = MySQLPathInfo.from_mysql(mysql)
            finally:
                mysql.close()
            try:
                check_innodb(pathinfo, ensure_subdir_of_datadir=True)
            except BackupError:
                if not config['mysql-lvm']['force-innodb-backup']:
                    raise
    
        if config['mysql-lvm']['lock-tables']:
            extra_flush = config['mysql-lvm']['extra-flush-tables']
            act = FlushAndLockMySQLAction(client, extra_flush)
            snapshot.register('pre-snapshot', act, priority=100)
            snapshot.register('post-snapshot', act, priority=100)
        if config['mysql-lvm'].get('replication', True):
            repl_cfg = config.setdefault('mysql:replication', {})
            act = RecordMySQLReplicationAction(client, repl_cfg)
            snapshot.register('pre-snapshot', act, 0)
        if config['mysql-lvm']['innodb-recovery']:
            mysqld_config = dict(config['mysqld'])
            mysqld_config['datadir'] = snap_datadir
            if not mysqld_config['tmpdir']:
                mysqld_config['tmpdir'] = tempfile.gettempdir()
            ib_log_size = client.show_variable('innodb_log_file_size')
            mysqld_config['innodb-log-file-size'] = ib_log_size
            act = InnodbRecoveryAction(mysqld_config)
            snapshot.register('post-mount', act, priority=100)


    archive_stream = open_stream(os.path.join(spooldir, 'backup.tar'),
                                 'w',
                                 **config['compression'])
    act = TarArchiveAction(snap_datadir, archive_stream, config['tar'])
    snapshot.register('post-mount', act, priority=50)

    snapshot.register('pre-remove', log_final_snapshot_size)
示例#8
0
def setup_actions(snapshot, config, client, snap_datadir, spooldir):
    """Setup actions for a LVM snapshot based on the provided
    configuration.

    Optional actions:
        * MySQL locking
        * InnoDB recovery
        * Recording MySQL replication
    """
    mysql = connect_simple(config["mysql:client"])
    if mysql.show_variable("have_innodb") == "YES":
        try:
            pathinfo = MySQLPathInfo.from_mysql(mysql)
        finally:
            mysql.close()
        try:
            check_innodb(pathinfo, ensure_subdir_of_datadir=True)
        except BackupError:
            if not config["mysql-lvm"]["force-innodb-backup"]:
                raise

    if config["mysql-lvm"]["lock-tables"]:
        extra_flush = config["mysql-lvm"]["extra-flush-tables"]
        act = FlushAndLockMySQLAction(client, extra_flush)
        snapshot.register("pre-snapshot", act, priority=100)
        snapshot.register("post-snapshot", act, priority=100)
    if config["mysql-lvm"].get("replication", True):
        repl_cfg = config.setdefault("mysql:replication", {})
        act = RecordMySQLReplicationAction(client, repl_cfg)
        snapshot.register("pre-snapshot", act, 0)
    if config["mysql-lvm"]["innodb-recovery"]:
        mysqld_config = dict(config["mysqld"])
        mysqld_config["datadir"] = snap_datadir
        if not mysqld_config["tmpdir"]:
            mysqld_config["tmpdir"] = tempfile.gettempdir()
        ib_log_size = client.show_variable("innodb_log_file_size")
        mysqld_config["innodb-log-file-size"] = ib_log_size
        act = InnodbRecoveryAction(mysqld_config)
        snapshot.register("post-mount", act, priority=100)
    if config["mysql-lvm"]["archive-method"] == "dir":
        try:
            backup_datadir = os.path.join(spooldir, "backup_data")
            os.mkdir(backup_datadir)
        except OSError as exc:
            raise BackupError("Unable to create archive directory '%s': %s" %
                              (backup_datadir, exc))
        act = DirArchiveAction(snap_datadir, backup_datadir, config["tar"])
        snapshot.register("post-mount", act, priority=50)
    else:
        try:
            archive_stream = open_stream(
                os.path.join(spooldir, "backup.tar"),
                "w",
                method=config["compression"]["method"],
                level=config["compression"]["level"],
                extra_args=config["compression"]["options"],
                inline=config["compression"]["inline"],
                split=config["compression"]["split"],
            )
        except OSError as exc:
            raise BackupError("Unable to create archive file '%s': %s" %
                              (os.path.join(spooldir, "backup.tar"), exc))
        act = TarArchiveAction(snap_datadir, archive_stream, config["tar"])
        snapshot.register("post-mount", act, priority=50)

    snapshot.register("pre-remove", log_final_snapshot_size)
示例#9
0
def setup_actions(snapshot, config, client, snap_datadir, spooldir):
    """Setup actions for a LVM snapshot based on the provided
    configuration.

    Optional actions:
        * MySQL locking
        * InnoDB recovery
        * Recording MySQL replication
    """
    mysql = connect_simple(config["mysql:client"])
    if mysql.show_variable("have_innodb") == "YES":
        try:
            pathinfo = MySQLPathInfo.from_mysql(mysql)
        finally:
            mysql.close()
        try:
            check_innodb(pathinfo, ensure_subdir_of_datadir=True)
        except BackupError:
            if not config["mysql-lvm"]["force-innodb-backup"]:
                raise

    if config["mysql-lvm"]["lock-tables"]:
        extra_flush = config["mysql-lvm"]["extra-flush-tables"]
        act = FlushAndLockMySQLAction(client, extra_flush)
        snapshot.register("pre-snapshot", act, priority=100)
        snapshot.register("post-snapshot", act, priority=100)
    if config["mysql-lvm"].get("replication", True):
        repl_cfg = config.setdefault("mysql:replication", {})
        act = RecordMySQLReplicationAction(client, repl_cfg)
        snapshot.register("pre-snapshot", act, 0)
    if config["mysql-lvm"]["innodb-recovery"]:
        mysqld_config = dict(config["mysqld"])
        mysqld_config["datadir"] = snap_datadir
        if not mysqld_config["tmpdir"]:
            mysqld_config["tmpdir"] = tempfile.gettempdir()
        ib_log_size = client.show_variable("innodb_log_file_size")
        mysqld_config["innodb-log-file-size"] = ib_log_size
        act = InnodbRecoveryAction(mysqld_config)
        snapshot.register("post-mount", act, priority=100)
    if config["mysql-lvm"]["archive-method"] == "dir":
        try:
            backup_datadir = os.path.join(spooldir, "backup_data")
            os.mkdir(backup_datadir)
        except OSError as exc:
            raise BackupError("Unable to create archive directory '%s': %s" % (backup_datadir, exc))
        act = DirArchiveAction(snap_datadir, backup_datadir, config["tar"])
        snapshot.register("post-mount", act, priority=50)
    else:
        try:
            archive_stream = open_stream(
                os.path.join(spooldir, "backup.tar"), "w", **config["compression"]
            )
        except OSError as exc:
            raise BackupError(
                "Unable to create archive file '%s': %s"
                % (os.path.join(spooldir, "backup.tar"), exc)
            )
        act = TarArchiveAction(snap_datadir, archive_stream, config["tar"])
        snapshot.register("post-mount", act, priority=50)

    snapshot.register("pre-remove", log_final_snapshot_size)