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?
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();
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With