Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database backup via Spring data

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.

like image 721
Manu Avatar asked Feb 16 '13 16:02

Manu


Video Answer


2 Answers

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 h2 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.

like image 173
Tomasz Nurkiewicz Avatar answered Sep 17 '22 17:09

Tomasz Nurkiewicz


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

like image 35
LalithK90 Avatar answered Sep 21 '22 17:09

LalithK90