Пример #1
0
 def pre_restore(self):
     self.app.stop_db()
     LOG.info(_("Cleaning out restore location: %s."),
              self.restore_location)
     operating_system.chmod(self.restore_location, FileMode.SET_FULL,
                            as_root=True)
     utils.clean_out(self.restore_location)
Пример #2
0
 def _pre_restore(self):
     LOG.debug("Cleaning out restore location: %s", self.restore_location)
     utils.execute_with_timeout("sudo", "chmod", "-R",
                                    "0777", self.restore_location)
     utils.clean_out(self.restore_location)
     app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
     app.stop_db()
Пример #3
0
 def pre_restore(self):
     self.app.stop_db()
     LOG.info("Cleaning out restore location: %s.",
              self.restore_location)
     operating_system.chmod(self.restore_location, FileMode.SET_FULL,
                            as_root=True)
     utils.clean_out(self.restore_location)
Пример #4
0
    def execute_restore(self, context, backup_id, restore_location):

        try:
            LOG.debug("Cleaning out restore location: %s", restore_location)
            utils.execute_with_timeout("sudo", "chmod", "-R", "0777", restore_location)
            utils.clean_out(restore_location)

            LOG.debug("Finding backup %s to restore", backup_id)
            backup = DBBackup.find_by(id=backup_id)

            LOG.debug("Getting Restore Runner of type %s", backup.backup_type)
            restore_runner = self._get_restore_runner(backup.backup_type)

            LOG.debug("Getting Storage Strategy")
            storage_strategy = get_storage_strategy(CONF.storage_strategy, CONF.storage_namespace)(context)

            LOG.debug("Preparing storage to download stream.")
            download_stream = storage_strategy.load(context, backup.location, restore_runner.is_zipped, backup.checksum)

            with restore_runner(restore_stream=download_stream, restore_location=restore_location) as runner:
                LOG.debug("Restoring instance from backup %s to %s", backup_id, restore_location)
                content_size = runner.restore()
                LOG.info("Restore from backup %s completed successfully to %s", backup_id, restore_location)
                LOG.info("Restore size: %s", content_size)

                utils.execute_with_timeout("sudo", "chown", "-R", "mysql", restore_location)

        except Exception as e:
            LOG.error(e)
            LOG.error("Error restoring backup %s", backup_id)
            raise

        else:
            LOG.info("Restored Backup %s", backup_id)
Пример #5
0
 def pre_restore(self):
     app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
     app.stop_db()
     LOG.info("Cleaning out restore location: %s", self.restore_location)
     utils.execute_with_timeout("sudo", "chmod", "-R", "0777",
                                self.restore_location)
     utils.clean_out(self.restore_location)
Пример #6
0
 def pre_restore(self):
     app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
     app.stop_db()
     LOG.info(_("Cleaning out restore location: %s."),
              self.restore_location)
     operating_system.chmod(self.restore_location, FileMode.SET_FULL,
                            as_root=True)
     utils.clean_out(self.restore_location)
Пример #7
0
 def pre_restore(self):
     app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
     app.stop_db()
     LOG.info(_("Cleaning out restore location: %s."),
              self.restore_location)
     operating_system.chmod(self.restore_location, FileMode.SET_FULL,
                            as_root=True)
     utils.clean_out(self.restore_location)
Пример #8
0
 def pre_restore(self):
     app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
     app.stop_db()
     LOG.info(_("Cleaning out restore location: %s"), self.restore_location)
     utils.execute_with_timeout("chmod", "-R", "0777",
                                self.restore_location,
                                root_helper="sudo",
                                run_as_root=True)
     utils.clean_out(self.restore_location)
Пример #9
0
 def pre_restore(self):
     app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
     app.stop_db()
     LOG.info(_("Cleaning out restore location: %s."),
              self.restore_location)
     utils.execute_with_timeout("chmod", "-R", "0777",
                                self.restore_location,
                                root_helper="sudo",
                                run_as_root=True)
     utils.clean_out(self.restore_location)
Пример #10
0
 def pre_restore(self):
     self.app.stop_db()
     LOG.info(_("Cleaning out restore location: %s."),
              self.restore_location)
     operating_system.chmod(self.restore_location, FileMode.SET_FULL,
                            as_root=True)
     utils.clean_out(self.restore_location)
     # IF AOF is set, we need to turn it off temporarily
     if self.aof_set:
         self.app.configuration_manager.apply_system_override(
             self.aof_off_cfg, change_id=self.CONF_LABEL_AOF_TEMP_OFF)
Пример #11
0
    def restore_backup(self, context, backup_info, restore_location):
        backup_id = backup_info['id']
        storage_driver = CONF.storage_strategy
        backup_driver = self.get_backup_strategy()
        user_token = context.auth_token
        auth_url = CONF.service_credentials.auth_url
        user_tenant = context.project_id
        image = self.get_backup_image()
        name = 'db_restore'
        volumes = {'/var/lib/mysql': {'bind': '/var/lib/mysql', 'mode': 'rw'}}

        command = (
            f'/usr/bin/python3 main.py --nobackup '
            f'--storage-driver={storage_driver} --driver={backup_driver} '
            f'--os-token={user_token} --os-auth-url={auth_url} '
            f'--os-tenant-id={user_tenant} '
            f'--restore-from={backup_info["location"]} '
            f'--restore-checksum={backup_info["checksum"]}')
        if CONF.backup_aes_cbc_key:
            command = (f"{command} "
                       f"--backup-encryption-key={CONF.backup_aes_cbc_key}")

        LOG.debug(
            'Stop the database and clean up the data before restore '
            'from %s', backup_id)
        self.stop_db()
        operating_system.chmod(restore_location,
                               operating_system.FileMode.SET_FULL,
                               as_root=True)
        utils.clean_out(restore_location)

        # Start to run restore inside a separate docker container
        LOG.info('Starting to restore backup %s, command: %s', backup_id,
                 command)
        output, ret = docker_util.run_container(self.docker_client,
                                                image,
                                                name,
                                                volumes=volumes,
                                                command=command)
        result = output[-1]
        if not ret:
            msg = f'Failed to run restore container, error: {result}'
            LOG.error(msg)
            raise Exception(msg)

        LOG.debug('Deleting ib_logfile files after restore from backup %s',
                  backup_id)
        operating_system.chown(restore_location,
                               CONF.database_service_uid,
                               CONF.database_service_uid,
                               force=True,
                               as_root=True)
        self.wipe_ib_logfiles()
Пример #12
0
    def execute_restore(self, context, backup_id, restore_location):

        try:
            LOG.debug("Cleaning out restore location: %s", restore_location)
            utils.execute_with_timeout("sudo", "chmod", "-R", "0777",
                                       restore_location)
            utils.clean_out(restore_location)

            LOG.debug("Finding backup %s to restore", backup_id)
            backup = DBBackup.find_by(id=backup_id)

            LOG.debug("Getting Restore Runner of type %s", backup.backup_type)
            restore_runner = self._get_restore_runner(backup.backup_type)

            LOG.debug("Getting Storage Strategy")
            storage_strategy = get_storage_strategy(
                CONF.storage_strategy, CONF.storage_namespace)(context)

            LOG.debug("Preparing storage to download stream.")
            download_stream = storage_strategy.load(context, backup.location,
                                                    restore_runner.is_zipped,
                                                    backup.checksum)

            with restore_runner(restore_stream=download_stream,
                                restore_location=restore_location) as runner:
                LOG.debug("Restoring instance from backup %s to %s", backup_id,
                          restore_location)
                content_size = runner.restore()
                LOG.info("Restore from backup %s completed successfully to %s",
                         backup_id, restore_location)
                LOG.info("Restore size: %s", content_size)

                utils.execute_with_timeout("sudo", "chown", "-R", "mysql",
                                           restore_location)

        except Exception as e:
            LOG.error(e)
            LOG.error("Error restoring backup %s", backup_id)
            raise

        else:
            LOG.info("Restored Backup %s", backup_id)