[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 15:36:31 UTC 2012


>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;
            }
        } 



More information about the Mono-aspnet-list mailing list