使用spring batch实现数据迁移实例

Table of Contents

数据迁移Data migration概述

数据迁移的类型及其挑战

一个数据迁移代码实例

spring cloud data flow介绍

在使用Spring Bacth以及Spring Cloud data flow时遇到的问题收集

问题1

问题2

问题3

问题4

问题5

问题6

问题7

问题8

问题9


数据迁移Data migration概述

在实际的软件产品开发过程当中,由于软件的不停迭代和升级,或者是一些商业上,战略上的策略调整,我们的系统总是有可能会遇到需要从一个数据库产品迁移到另一个数据库上的场景。这意味着我们不得不将以前的数据迁移到新的数据库上去,因为我们不可能因为搬迁平台而丢掉用户的数据,这对于任何一个产品来说都是一件不可能被允许的事情。

数据迁移的类型及其挑战

数据迁移过程分三个级别执行。

Storage migration 存储迁移

通过技术更新证明存储迁移是合理的,并且该过程被用作通过识别过时或损坏数据来进行数据验证和减少的最佳时间。 该过程涉及将存储和文件块从一个存储系统移动到另一个存储系统,无论是在磁盘,磁带还是云上。 有许多存储迁移产品和工具可以帮助我们顺利完成整个过程。 存储迁移还提供了修复任何孤立存储或低效的机会。


Database migration 数据库迁移

当需要更改数据库供应商,升级数据库软件或将数据库移动到云时,可以完成数据库迁移。 在这种类型的迁移中,底层数据可能会发生变化,这会在协议或数据语言发生变化时影响应用程序层。 数据库中的数据迁移涉及修改数据而不更改模式。 一些关键任务包括评估数据库大小以确定需要多少存储,测试应用程序以及保证数据机密性。 迁移过程中可能会出现兼容性问题,因此首先测试该过程非常重要。

Application migration 应用迁移

切换到其他供应商应用程序或平台时,可能会发生应用程 这个过程有其固有的复杂层,因为应用程序与其他应用程序交互,每个应用程序都有自己的数据模型。 应用程序不是为便携式而设计的。 管理工具,操作系统和虚拟机配置都可以与开发或部署应用程序的环境不同。 成功的应用程序迁移可能需要使用中间件产品来弥合技术差距。

云迁移是一项主要的技术趋势,因为云为内部部署基础架构提供按需灵活性,可扩展性和Capex的减少。 公共云提供商为存储,数据库和应用程序迁移提供各种服务。

一个数据迁移代码实例

下面这个例子基于spring boot和maven,实现的功能是从file当中读取数据,同时写入到另一个文件里面。在实际做数据迁移的时候,只需要将代码当中读取数据,写数据的相应逻辑替换即可,流程和框架是一样的。

maven依赖如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>io.spring.cloud.dataflow.ingest</groupId>
    <artifactId>ingest</artifactId>
    <version>1.0.0.BUILD-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
    </parent>
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
        <spring.cloud.task.version>1.2.2.RELEASE</spring.cloud.task.version>
        <checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
        <checkstyle.plugin.version>2.17</checkstyle.plugin.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-task-core</artifactId>
            <version>${spring.cloud.task.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-task-batch</artifactId>
            <version>${spring.cloud.task.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <testSource>${java.version}</testSource>
                    <testTarget>${java.version}</testTarget>
                    <compilerArgument>-Xlint:all</compilerArgument>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>repository.spring.milestone</id>
            <name>Spring Milestone Repository</name>
            <url>http://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/m
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值