Database backup via Spring data
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.