1

I have a Tomcat web server running a web application that uses PostgreSQL. All the manual process of the organization are automated through the web application with persistence layer as Hibernate. I would like to provide a backup and restore option for the user.

Backup would somehow get all of the data/schema (maybe not schema) from the DB and zip it and send it to the user through the web-app to allow them to save the backup on their local machine. They could then select this backup file to restore the DB to the state that it was when the backup was taken.

We're using Tomcat container, Spring+Hibernate with PostgreSql.

How can this be done?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
Aniket Kulkarni
  • 1,985
  • 2
  • 17
  • 22
  • I'd try a combination of `pg_dump --data-only --clean` and then http://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program to get the output of the script. – jcern Mar 19 '13 at 00:12

1 Answers1

1

I have seen people put together custom backup routines. I really, really don't recommend it. When things go wrong, they tend to go horribly wrong.

Your best option is to use well-tested tools which are other people's code. The best option IMO is to call a shell escape and run pg_dump. This gives you quite a bit of flexibility and quite more robustness than you would get yourself. Then open the file, and send it to the client. This is what we do with LedgerSMB with our own persistence layer and Perl, but it should be more or less the same on any other system.

Backups are important. The main code for ensuring the backup is internally consistent really is best not kept in-house.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182