File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Execute pg_dump from within web app    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Execute pg_dump from within web app    " Watch "Execute pg_dump from within web app    " New topic
Author

Execute pg_dump from within web app

Pete Dawn
Greenhorn

Joined: Sep 28, 2006
Posts: 17
guys,

i am trying to implement a database backup functionality from within my web app. now in order to run pg_dump I am using the Runtime functions.

now so far I have got this but its not working,
Process p = Runtime.getRuntime().exec( new String[] {
"cmd.exe",
"/E:1900",
"/C",
"C:/Program Files/PostgreSQL/8.1/bin/pg_dump.exe -i -h localhost -p 5432 -U postgres -F t -b -v -f C:/test.backup TESTDB"});

can somebody help me out. thanks.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Can you expand a little on 'its not working' ?

You might want to look at the Process.getInputStream() and Process.getErrorStream() methods. These will let you see any output from your program.


Joanne
Pete Dawn
Greenhorn

Joined: Sep 28, 2006
Posts: 17
if i execute this code, it executes without any error but nothing happens. i think that the code is running into an error, which i am trying to catch using getErrorStream().

But perhaps it would be quicker if somebody could tell me if my syntax is correct in the first place, I have a feeling that my syntax is wrong.

Please help. Thanks.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
If you are not even sure the command works you should try it in a command prompt first. Once you have it working, then try calling it from a Java program.
Pete Dawn
Greenhorn

Joined: Sep 28, 2006
Posts: 17
the command works fine when i execute it from the command prompt and it performs the backup. but i am not sure of whats the best way of running the same command from within my java code. so the command is correct, but the syntax from within java code is incorrect. any help guys.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Well if you only want help from guys, then I guess I'd best drop out of the conversation

Seriously though, the first thing I'd try is to change all the '/' characters in your path names to '\'. Don't forget to escape them.
i.e.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Execute pg_dump from within web app
 
Similar Threads
Backup postgres database
Doing a pg_dump in Postgres using Ant - password poblem
web app question
...bootstrap.jar doesnot exists
Relative path Issue