8

I need to schedule regular database backup for my web application using Spring. Does Spring Data offer any particular support for backupping? I plan to use TaskScheduler and TaskExecutor.

2 Answers 2

9

No, there is no specific support for that. Spring Data is intended for transactional use, not batch operations. Of course there is findAll() method that you can iterate over and store results somewhere.

Spring Batch is probably a bit better choice as it focuses on long-running, heavy batch processes. But IMHO your application is not a good place for running backup. Why not use database or OS support? It'll be faster and more reliable.

If you really need to backup your database from application level, consider your database manual, maybe there is some simple command to dump the contents of the database to a file. For example in I am using SCRIPT SQL command from JdbcTemplate to dump the database to arbitrary file. But I use this technique to reset database after each integration test. I use JdbcTemplate to minimize overhead. That's why Spring Data is not the best tool for the job.

In MySQL there is a mysqldump process, so it's a bit more cumbersome to run from Java.

Sign up to request clarification or add additional context in comments.

1 Comment

The reason is that the application is distributed over different systems so I would need different configurations on each of them. This is the reason why I was trying to do it via application.
2

Please follow this link and get an idea regarding your matter Spring support it

add the following dependency to pom.xml if ur build a maven project

<dependency>
    <groupId>com.smattme</groupId>
    <artifactId>mysql-backup4j</artifactId>
    <version>1.0.0</version>
</dependency>

if gradle spring project

add the dependency to the build.gradle

compile group: 'com.smattme', name: 'mysql-backup4j', version: '1.0.0'

this article may help to understand

https://dzone.com/articles/how-to-backup-mysql-database-programmatically-usin

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.