[Mono-aspnet-list] How to backup PostgreSql database from browser in MVC2 application on Mono in Linux
Daniel J. Summers
daniel.summers.2415 at gmail.com
Sat Mar 24 16:23:18 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. 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.
Alternately, if you can't do that, get rid of the "var b2" declaration and
just write the process.StandardOutput.ReadToEnd() call; you don't need to
allocate that space to write it. You can also call Response.Flush() after
each write; this will send the current buffer to the browser, which frees
that memory (or at least makes it available to be freed).
This is an interesting piece of code. On-demand downloadable Postgres
backups would be pretty cool. :) Be sure to post the final working code!
On Mar 24, 2012 9:53 AM, "Andrus" <kobruleht2 at hot.ee> wrote:
>> Looks like you could set it as part of the Action. :)
> I tried code below but it tries to read whole result to memory and causes
> out of memory exception.
> How to change it to be pipe ?
> public class BackupController : ControllerBase
> public ActionResult BackupPipe()
> string.Format("attachment; filename=\"backup.backup\"");
> Response.ContentType = "application/backup";
> using (var process = new Process())
> process.StartInfo.Arguments =" -ib -Z6 -Fc -h \"126.96.36.199\" -U
> process.StartInfo.FileName = "usr/bin/pgsql/pg_dump";
> process.StartInfo.**UseShellExecute = false;
> process.StartInfo.**RedirectStandardOutput = true;
> Server.ScriptTimeout = 8*60*60; // 8 hours
> while (!process.HasExited)
> var b = process.StandardOutput.**ReadToEnd();
> if (process.ExitCode != 0)
> return new ContentResult()
> Content = "Error " + process.ExitCode.ToString()
> var b2 = process.StandardOutput.**ReadToEnd();
> return null;
> Mono-aspnet-list mailing list
> Mono-aspnet-list at lists.ximian.**com <Mono-aspnet-list at lists.ximian.com>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-aspnet-list