Exemplo n.º 1
0
    def test_snapshot_fsm(self):
        lv = LogicalVolume.lookup('%s/%s' % (TEST_VG, TEST_LV))
        name = lv.lv_name + '_snapshot'
        size = 1 # extent

        snapshot = Snapshot(name, size, self.tmpdir)
        snapshot.start(lv)
Exemplo n.º 2
0
    def test_snapshot_fsm_with_failures(self):
        """Test Snapshot"""
        log_vol = LogicalVolume.lookup("%s/%s" % (TEST_VG, TEST_LV))
        name = log_vol.lv_name + "_snapshot"
        size = 1  # extent

        snapshot = Snapshot(name, size, self.__class__.tmpdir)

        def bad_callback(event, *args, **kwargs):
            raise Exception("Oooh nooo!")

        for evt in (
                "initialize",
                "pre-snapshot",
                "post-snapshot",
                "pre-mount",
                "post-mount",
                "pre-unmount",
                "post-unmount",
                "pre-remove",
                "post-remove",
                "finish",
        ):
            snapshot.register(evt, bad_callback)
            self.assertRaises(CallbackFailuresError, snapshot.start, log_vol)
            snapshot.unregister(evt, bad_callback)
            if snapshot.sigmgr._handlers:
                raise Exception(
                    "sigmgr handlers still exist when checking event => %r",
                    evt)
Exemplo n.º 3
0
    def test_snapshot_fsm(self):
        lv = LogicalVolume.lookup('%s/%s' % (TEST_VG, TEST_LV))
        name = lv.lv_name + '_snapshot'
        size = 1 # extent

        snapshot = Snapshot(name, size, self.tmpdir)
        snapshot.start(lv)
Exemplo n.º 4
0
    def test_snapshot_fsm(self):
        """Test snapshot"""
        log_vol = LogicalVolume.lookup("%s/%s" % (TEST_VG, TEST_LV))
        name = log_vol.lv_name + "_snapshot"
        size = 1  # extent

        snapshot = Snapshot(name, size, self.__class__.tmpdir)
        snapshot.start(log_vol)
Exemplo n.º 5
0
    def backup(self):
        """Run a backup by running through a LVM snapshot against the device
        the MySQL datadir resides on
        """
        # connect to mysql and lookup what we're supposed to snapshot
        try:
            self.client.connect()
            datadir = os.path.realpath(self.client.show_variable("datadir"))
        except MySQLError as exc:
            raise BackupError("[%d] %s" % exc.args)

        LOG.info("Backing up %s via snapshot", datadir)
        # lookup the logical volume mysql's datadir sits on

        try:
            volume = LogicalVolume.lookup_from_fspath(datadir)
        except LookupError as exc:
            raise BackupError("Failed to lookup logical volume for %s: %s" %
                              (datadir, str(exc)))
        except Exception as ex:
            raise BackupError("Failed to lookup logical volume for %s: %s" %
                              (datadir, str(ex)))

        # create a snapshot manager
        snapshot = build_snapshot(self.config["mysql-lvm"],
                                  volume,
                                  suppress_tmpdir=self.dry_run)
        # calculate where the datadirectory on the snapshot will be located
        rpath = relpath(datadir, getmount(datadir))
        snap_datadir = os.path.abspath(os.path.join(snapshot.mountpoint,
                                                    rpath))
        # setup actions to perform at each step of the snapshot process
        setup_actions(
            snapshot=snapshot,
            config=self.config,
            client=self.client,
            snap_datadir=snap_datadir,
            spooldir=self.target_directory,
        )

        if self.dry_run:
            return _dry_run(self.target_directory, volume, snapshot, datadir)

        try:
            snapshot.start(volume)
        except CallbackFailuresError as exc:
            for callback, error in exc.errors:
                LOG.error("%s: %s", callback, error)
            raise BackupError(
                "Error occurred during snapshot process. Aborting.")
        except LVMCommandError as exc:
            # Something failed in the snapshot process
            raise BackupError(str(exc))
        except BaseException as ex:
            LOG.debug(ex)

        return None
Exemplo n.º 6
0
    def test_snapshot_fsm_with_callbacks(self):
        lv = LogicalVolume.lookup('%s/%s' % (TEST_VG, TEST_LV))
        name = lv.lv_name + '_snapshot'
        size = 1 # extent

        snapshot = Snapshot(name, size, self.tmpdir)
        def handle_event(event, *args, **kwargs):
            pass

        snapshot.register('pre-mount', handle_event)
        snapshot.register('post-mount', handle_event)
        snapshot.start(lv)
Exemplo n.º 7
0
    def test_snapshot_fsm_with_callbacks(self):
        lv = LogicalVolume.lookup('%s/%s' % (TEST_VG, TEST_LV))
        name = lv.lv_name + '_snapshot'
        size = 1 # extent

        snapshot = Snapshot(name, size, self.tmpdir)
        def handle_event(event, *args, **kwargs):
            pass

        snapshot.register('pre-mount', handle_event)
        snapshot.register('post-mount', handle_event)
        snapshot.start(lv)
Exemplo n.º 8
0
 def backup(self):
     """Run a backup by running through a LVM snapshot against the device
     the MySQL datadir resides on
     """
     # connect to mysql and lookup what we're supposed to snapshot
     self.client.connect()
     datadir = os.path.realpath(self.client.show_variable("datadir"))
     LOG.info("Backing up %s via snapshot", datadir)
     # lookup the logical volume mysql's datadir sits on
     try:
         volume = LogicalVolume.lookup_from_fspath(datadir)
     except LookupError, exc:
         raise BackupError("Failed to lookup logical volume for %s: %s" % (datadir, str(exc)))
Exemplo n.º 9
0
    def backup(self):
        """Run a backup by running through a LVM snapshot against the device
        the MySQL datadir resides on
        """
        # connect to mysql and lookup what we're supposed to snapshot
        try:
            self.client.connect()
            datadir = os.path.realpath(self.client.show_variable("datadir"))
        except MySQLError as exc:
            raise BackupError("[%d] %s" % exc.args)

        LOG.info("Backing up %s via snapshot", datadir)
        # lookup the logical volume mysql's datadir sits on

        try:
            volume = LogicalVolume.lookup_from_fspath(datadir)
        except LookupError as exc:
            raise BackupError("Failed to lookup logical volume for %s: %s" % (datadir, str(exc)))
        except Exception as ex:
            raise BackupError("Failed to lookup logical volume for %s: %s" % (datadir, str(ex)))

        # create a snapshot manager
        snapshot = build_snapshot(self.config["mysql-lvm"], volume, suppress_tmpdir=self.dry_run)
        # calculate where the datadirectory on the snapshot will be located
        rpath = relpath(datadir, getmount(datadir))
        snap_datadir = os.path.abspath(os.path.join(snapshot.mountpoint, rpath))
        # setup actions to perform at each step of the snapshot process
        setup_actions(
            snapshot=snapshot,
            config=self.config,
            client=self.client,
            snap_datadir=snap_datadir,
            spooldir=self.target_directory,
        )

        if self.dry_run:
            return _dry_run(self.target_directory, volume, snapshot, datadir)

        try:
            snapshot.start(volume)
        except CallbackFailuresError as exc:
            for callback, error in exc.errors:
                LOG.error("%s: %s", callback, error)
            raise BackupError("Error occurred during snapshot process. Aborting.")
        except LVMCommandError as exc:
            # Something failed in the snapshot process
            raise BackupError(str(exc))
        except BaseException as ex:
            LOG.debug(ex)

        return None
Exemplo n.º 10
0
    def test_snapshot_fsm_with_callbacks(self):
        """Test snapshot"""
        log_vol = LogicalVolume.lookup("%s/%s" % (TEST_VG, TEST_LV))
        name = log_vol.lv_name + "_snapshot"
        size = 1  # extent

        snapshot = Snapshot(name, size, self.__class__.tmpdir)

        def handle_event(event, *args, **kwargs):
            pass

        snapshot.register("pre-mount", handle_event)
        snapshot.register("post-mount", handle_event)
        snapshot.start(log_vol)
Exemplo n.º 11
0
 def backup(self):
     """Run a backup by running through a LVM snapshot against the device
     the MySQL datadir resides on
     """
     # connect to mysql and lookup what we're supposed to snapshot
     self.client.connect()
     datadir = os.path.realpath(self.client.show_variable('datadir'))
     LOG.info("Backing up %s via snapshot", datadir)
     # lookup the logical volume mysql's datadir sits on
     try:
         volume = LogicalVolume.lookup_from_fspath(datadir)
     except LookupError, exc:
         raise BackupError("Failed to lookup logical volume for %s: %s" %
                           (datadir, str(exc)))
Exemplo n.º 12
0
    def test_snapshot_fsm_with_failures(self):
        lv = LogicalVolume.lookup('%s/%s' % (TEST_VG, TEST_LV))
        name = lv.lv_name + '_snapshot'
        size = 1 # extent

        snapshot = Snapshot(name, size, self.tmpdir)

        def bad_callback(event, *args, **kwargs):
            raise Exception("Oooh nooo!")

        for evt in ('initialize', 'pre-snapshot', 'post-snapshot',
                    'pre-mount', 'post-mount', 'pre-unmount', 'post-unmount',
                    'pre-remove', 'post-remove', 'finish'):
            snapshot.register(evt, bad_callback)
            assert_raises(CallbackFailuresError, snapshot.start, lv)
            snapshot.unregister(evt, bad_callback)
            if snapshot.sigmgr._handlers:
                raise Exception("WTF. sigmgr handlers still exist when checking event => %r", evt)
Exemplo n.º 13
0
    def test_snapshot_fsm_with_failures(self):
        lv = LogicalVolume.lookup('%s/%s' % (TEST_VG, TEST_LV))
        name = lv.lv_name + '_snapshot'
        size = 1 # extent

        snapshot = Snapshot(name, size, self.tmpdir)

        def bad_callback(event, *args, **kwargs):
            raise Exception("Oooh nooo!")

        for evt in ('initialize', 'pre-snapshot', 'post-snapshot', 
                    'pre-mount', 'post-mount', 'pre-unmount', 'post-unmount',
                    'pre-remove', 'post-remove', 'finish'):
            snapshot.register(evt, bad_callback)
            assert_raises(CallbackFailuresError, snapshot.start, lv)
            snapshot.unregister(evt, bad_callback)
            if snapshot.sigmgr._handlers:
                raise Exception("WTF. sigmgr handlers still exist when checking event => %r", evt)
Exemplo n.º 14
0
    def backup(self):
        """Run a backup by running through a LVM snapshot against the device
        the MySQL datadir resides on
        """
        # connect to mysql and lookup what we're supposed to snapshot
        self.client.connect()
        datadir = os.path.realpath(self.client.show_variable('datadir'))
        LOG.info("Backing up %s via snapshot", datadir)
        # lookup the logical volume mysql's datadir sits on
        try:
            volume = LogicalVolume.lookup_from_fspath(datadir)
        except LookupError as exc:
            raise BackupError("Failed to lookup logical volume for %s: %s" %
                              (datadir, str(exc)))
        except Exception as ex:
            LOG.debug(ex)

        try:
            # create a snapshot manager
            snapshot = build_snapshot(self.config['mysql-lvm'],
                                      volume,
                                      suppress_tmpdir=self.dry_run)
            # calculate where the datadirectory on the snapshot will be located
            rpath = relpath(datadir, getmount(datadir))
            snap_datadir = os.path.abspath(
                os.path.join(snapshot.mountpoint or '/tmp', rpath))

            LOG.debug("Snap Datadir: %s" % snap_datadir)
            # setup actions to perform at each step of the snapshot process
            setup_actions(snapshot=snapshot,
                          config=self.config,
                          client=self.client,
                          datadir=snap_datadir,
                          spooldir=self.target_directory,
                          plugin=self.mysqldump_plugin)
        except Exception as ex:
            LOG.debug(ex)

        if self.config['mysqldump']['bin-log-position']:
            LOG.warn("bin-log-position is not supported with mysqldump-lvm.")
            LOG.warn(
                "Replication status will be saved to the "
                "[mysql:replication] section in %s", self.config.filename)
            self.config['mysqldump']['bin-log-position'] = False

        if self.dry_run:
            self._dry_run(volume, snapshot, datadir)
            # do the normal mysqldump dry-run
            return self.mysqldump_plugin.backup()

        try:
            snapshot.start(volume)
        except CallbackFailuresError as exc:
            # XXX: one of our actions failed.  Log this better
            for callback, error in exc.errors:
                LOG.error("%s", error)
            raise BackupError(
                "Error occurred during snapshot process. Aborting.")
        except LVMCommandError as exc:
            # Something failed in the snapshot process
            raise BackupError(str(exc))
Exemplo n.º 15
0
        # connect to mysql and lookup what we're supposed to snapshot
        if self.use_mysql:
            try:
                self.client.connect()
                dir = os.path.realpath(self.client.show_variable('datadir'))
                if datadir != dir:
                    LOG.warn('MySQL reports its datadir as %s, not %s as configured in backupset.  Overriding config', dir, datadir)
                    datadir = dir
            except MySQLError, exc:
                raise BackupError("[%d] %s" % exc.args)

        LOG.info("Backing up %s via snapshot", datadir)
        # lookup the logical volume mysql's datadir sits on

        try:
            volume = LogicalVolume.lookup_from_fspath(datadir)
        except LookupError, exc:
            raise BackupError("Failed to lookup logical volume for %s: %s" %
                              (datadir, str(exc)))


        # create a snapshot manager
        snapshot = build_snapshot(self.config['mysql-lvm'], volume,
                                  suppress_tmpdir=self.dry_run)
        # calculate where the datadirectory on the snapshot will be located
        rpath = relpath(datadir, getmount(datadir))
        snap_datadir = os.path.abspath(os.path.join(snapshot.mountpoint, rpath))
        # setup actions to perform at each step of the snapshot process
        setup_actions(snapshot=snapshot,
                      config=self.config,
                      client=self.client,
Exemplo n.º 16
0
    def backup(self):
        """Run a backup by running through a LVM snapshot against the device
        the MySQL datadir resides on
        """
        # connect to mysql and lookup what we're supposed to snapshot
        try:
            self.client.connect()
            datadir = os.path.realpath(self.client.show_variable('datadir'))
        except MySQLError, exc:
            raise BackupError("[%d] %s" % exc.args)

        LOG.info("Backing up %s via snapshot", datadir)
        # lookup the logical volume mysql's datadir sits on

        try:
            volume = LogicalVolume.lookup_from_fspath(datadir)
        except LookupError, exc:
            raise BackupError("Failed to lookup logical volume for %s: %s" %
                              (datadir, str(exc)))

        # create a snapshot manager
        snapshot = build_snapshot(self.config['mysql-lvm'],
                                  volume,
                                  suppress_tmpdir=self.dry_run)
        # calculate where the datadirectory on the snapshot will be located
        rpath = relpath(datadir, getmount(datadir))
        snap_datadir = os.path.abspath(os.path.join(snapshot.mountpoint,
                                                    rpath))
        # setup actions to perform at each step of the snapshot process
        setup_actions(snapshot=snapshot,
                      config=self.config,