views:

78

answers:

2

Hi, I want to backup my web site regularly but instead of backup my files via ftp program I want a one-click solution which will copy all my files and zip them and allow to download. Can this be done with asp.net at same web site or I have to write a .net app for this purpose?

+2  A: 

I think that you can do what you won, by this way.

Find a zip library like SharpZipLib and you just programming to create a zip file and include the basic application path HttpContext.Current.Request.PhysicalApplicationPath including all paths.

Save this zip created file on a tempo dir and just download it.

This is a fast solution and maybe have some problems, for example probably fail to open locked files...

If you won to backup only your database, then you must do different thinks.

Hope this help.

Aristos
Better use http://dotnetzip.codeplex.com/ instead SharpZipLib
HasanGursoy
@HasanGursoy thank you for the info, I will give it a try and see this lib. The other one I give you I use it all ready and works fine, but I will check the new one also.
Aristos
+1  A: 

Backup was very easy with DotNetZip. Just give a directory name to backup and wait file to be downloaded. Even can set a password for the zip. I love open-source solutions.

using Ionic.Zip;

public void btnOneClickZip_Click(Object sender, EventArgs e)
{
    Response.Clear();
    Response.BufferOutput = false;

    string archiveName = String.Format("backup-{0}.zip",
    DateTime.Now.ToString("yyyy-MM-dd-HHmmss"));
    Response.ContentType = "application/zip";
    Response.AddHeader("content-disposition", "filename=" + archiveName);

    using (ZipFile zip = new ZipFile())
    {
        zip.AddDirectory(Server.MapPath("~/Assets/Upload/"),
            "httpdocs/Assets/Upload");
        zip.AddDirectory(Server.MapPath("~/App_Data/"), "httpdocs/App_Data");

        zip.Save(Response.OutputStream);
    }
    Response.Close();
}
HasanGursoy
Thank you for sharing the final code :)
Aristos