iCode
iCode

Reputation: 9202

Java WebApp Configuration Backup and Restore

I have a Java Spring MVC web Application. And it has some configuration and properties files.

There is a directory, let's say, myappconf. Inside that there are configuration and property folders. Inside that some files are there.

myappconf
  |
  |---conf
  |    |
  |    |__ settings.xml
  |    |__ nodes.xml
  |
  |---prop
       |
       |__ app.properties 

I want to take backup of the entire folder into another location. I already have Quartz implemented to run some other Jobs. I can use the same for taking backups also. To a specified location I can copy the entire folder on a specific interval or when any file is changed.

I am running the application in tomcat.

In case, the application is crashed, or the server is failed, I want to install a new application in the server and it should restore the configuration. The folder will have some data also. I want to restore all.

I am not aware of how to restore it. Has anybody implemented something like this? or anybody has some Guidelines for Backup and restore?

Thanks

Upvotes: 3

Views: 4203

Answers (2)

Ved
Ved

Reputation: 8767

I would do it in this manner -

  1. If you can save state of application each time its loaded/deployed in database OR in a file, that is it freshly installed or restored..
  2. If you are using linux platform, go and update startup.sh file which is executed when tomcat is started.
  3. Assuming you are running only one application in your tomcat instance, you may check the file or database entry which you created in step 1 while startup server.
  4. If that entry says that any previous configuration exist, just deploy that in your application, if not, start a fresh application.

This will continue recursively until you manually remove the entry created in step-1.

Hope this helps.

Upvotes: 2

Steve Siebert
Steve Siebert

Reputation: 1894

Yup, you can simply copy the files in your "exploded war" directory. You can use quartz if you wish, or you can use any file system backup tool. The later may be easier, because it has restore capabilities.

In the event that you do go with your own tooling (ie quartz), to "restore" you would shutdown your tomcat instance, copy the files back into place, optionally overwriting the old ones, and turn tomcat back on. Tomcat reads from the exploded war files, so you'll be good to go.

Edit: ideally, you would want to shutdown tomcat (gracefully) before copying off your files, to ensure that if any changes for those files that were in memory were flushed -- but, in practice, this is rarely an issue with these kinds of files (my opinion).

Upvotes: 1

Related Questions