[Mono-aspnet-list] How to backup PostgreSql database from browser in MVC2 application on Mono in Linux
Andrus
kobruleht2 at hot.ee
Sat Mar 24 19:32:06 UTC 2012
>I'm not at home, so it's tough to look up - can you specify the response output stream as the target for the standard >output redirection for the process? If so, that would connect the two, and you'd likely not even need to read from >the process and write to the output.
I tried
process.StandardOutput = Response.OutputStream;
and
Response.OutputStream = process.StandardOutput;
but got compile error that property is read only in both cases.
>You might need to fiddle with the flush interval for the stream, so it doesn't
>try to accrue the whole result before writing it.
Code
[AcceptVerbs(HttpVerbs.Get)]
public FileStreamResult BackupPipe()
{
var process = new Process();
process.StartInfo.Arguments = " -ib -Z6 -Fc -h 1.2.3.4";
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = “/usr/pgsql/9.1/bin/pg_dump”;
process.StartInfo.RedirectStandardOutput = true;
Server.ScriptTimeout = 8 * 60 * 60; // 8 hours
process.Start();
return new FileStreamResult(process.StandardOutput.BaseStream, "application/backup");
}
seems to work in both Linux and Windows.
top shows mono.bin and after download starts httpd %MEM values up to 36%
How to add error reporting so that user can notified if error occurs? Currently bad file is received without any notice.
Before download starts, pg_dump runs without data being sent to browser and users sees hourglass for a long time.
File download prompt in browser occurs only after pg_dump and mono.bin commands are completed.
How to force download to start earlier or show some progress message to user in browser during pg_dump run?
Andrus.
Note.
Wrapping process creation to use statement:
use ( var process = new Process() ) {
process.StartInfo.Arguments = " -ib -Z6 -Fc -h 1.2.3.4";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = “/usr/pgsql/9.1/bin/pg_dump”;
Server.ScriptTimeout = 8 * 60 * 60; // 8 hours
process.Start();
return new FileStreamResult(process.StandardOutput.BaseStream, "application/backup");
}
causes “object is used after being disposed” exception in Mono but works in windows.
Is this mono bug ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-aspnet-list/attachments/20120324/440435ac/attachment.html>
More information about the Mono-aspnet-list
mailing list