One-click website backup with asp.net

I want to back up my website regularly, but instead of backing up my files through an ftp program, I need one click that will copy all my files and zip them and allow them to download. Can this be done using asp.net on the same website or do I need to write a .net application for this purpose?

+4
source share
2 answers

Backing up was very easy with DotNetZip . Just provide the name of the directory to back up and wait for the file to download. It can even set a password for zip. I like 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(); } 
+6
source

I think you can do what you won in this way.

Find a zip library like SharpZipLib and you just program to create a zip file and include the main path to HttpContext.Current.Request.PhysicalApplicationPath applications, including all the paths.

Save this created zip file in the tempo directory and just upload it.

This is a quick fix and maybe some problems, for example, you probably cannot open locked files ...

If you won to back up only your database, you have to make different thoughts.

I hope for this help.

+2
source

Source: https://habr.com/ru/post/1311483/


All Articles