我想定期备份我的网站,但不是通过ftp程序备份我的文件,我想要一个一键式的解决方案,它将复制我的所有文件,并压缩它们,并允许下载。在同一网站上使用asp.net可以做到这一点吗?或者我必须为此编写一个.net应用程序?
发布于 2010-06-02 05:32:55
使用DotNetZip备份非常简单。只需给出要备份的目录名,然后等待文件下载即可。甚至可以为zip设置密码。我喜欢开源的解决方案。
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();
}发布于 2010-06-01 15:42:38
我认为,通过这种方式,你可以做你赢得的事情。
找到像SharpZipLib这样的zip库,您只需编程创建一个zip文件并包含基本应用程序路径HttpContext.Current.Request.PhysicalApplicationPath (包括所有路径)即可。
将这个zip创建的文件保存在tempo目录中,然后下载即可。
这是一个快速的解决方案,可能会有一些问题,例如可能无法打开锁定的文件...
如果您成功地只备份您的数据库,那么您必须进行不同的思考。
希望这能有所帮助。
https://stackoverflow.com/questions/2947832
复制相似问题