[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:
>
> http://msdn.microsoft.com/en-**us/library/system.web.**httpserverutility.
>> **scripttimeout.aspx<http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.scripttimeout.aspx>
>> 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 ?
>
> Andrus.
>
> [Authorize]
> public class BackupController : ControllerBase
> {
> [AcceptVerbs(HttpVerbs.Get)]
> public ActionResult BackupPipe()
> {
> Response.ClearContent();
> Response.AddHeader("content-**disposition",
> string.Format("attachment; filename=\"backup.backup\"");
> Response.ContentType = "application/backup";
> using (var process = new Process())
> {
> process.StartInfo.Arguments =" -ib -Z6 -Fc -h \"1.2.3.4\" -U
> \"";
> process.StartInfo.FileName = "usr/bin/pgsql/pg_dump";
> process.StartInfo.**UseShellExecute = false;
> process.StartInfo.**RedirectStandardOutput = true;
> Server.ScriptTimeout = 8*60*60; // 8 hours
> process.Start();
> while (!process.HasExited)
> {
> var b = process.StandardOutput.**ReadToEnd();
> Response.Write(b);
> Thread.Sleep(2000);
> }
> process.WaitForExit();
> if (process.ExitCode != 0)
> {
> return new ContentResult()
> {
> Content = "Error " + process.ExitCode.ToString()
> };
> }
> var b2 = process.StandardOutput.**ReadToEnd();
> Response.Write(b2);
> process.Close();
> Response.End();
> return null;
> }
> }
> ______________________________**_________________
> Mono-aspnet-list mailing list
> Mono-aspnet-list at lists.ximian.**com <Mono-aspnet-list at lists.ximian.com>
> http://lists.ximian.com/**mailman/listinfo/mono-aspnet-**list<http://lists.ximian.com/mailman/listinfo/mono-aspnet-list>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-aspnet-list/attachments/20120324/d247fbce/attachment.html>
More information about the Mono-aspnet-list
mailing list