Ejemplo n.º 1
0
        public void SaveFullBackup(string DestinationPath)
        {
            string GlobalFileName = txtFileName.Text.Trim();
            
            string DestinationPathTemp = DestinationPath + GlobalFileName + "\\";
            string ApplicationBackupPathTemp = DestinationPathTemp + "Application\\";
            string DatabaseBackupPathTemp = DestinationPathTemp + "Database\\";
            string SourcePath = Server.MapPath("~");
            string DatabaseBackupFileName = GlobalFileName + "_Db.bak";
            string DatabaseBackupZipFileName = GlobalFileName + "_Database.zip";
            string ApplicationBackupZipFileName = GlobalFileName + "_Application.zip";
            string ZipFileName = GlobalFileName + "_Full.zip";

            //Create Folder
            if (!Directory.Exists(@DestinationPathTemp))
                Directory.CreateDirectory(@DestinationPathTemp);

            if (!Directory.Exists(@ApplicationBackupPathTemp))
                Directory.CreateDirectory(@ApplicationBackupPathTemp);

            if (!Directory.Exists(@DatabaseBackupPathTemp))
                Directory.CreateDirectory(@DatabaseBackupPathTemp);


            //Copy Application Folder            
            bool Result = CopyDirectory(SourcePath, ApplicationBackupPathTemp, true);

            string[] dirTemp = Directory.GetDirectories(ApplicationBackupPathTemp);
            foreach (string dir in dirTemp)
            {
                if (dir == "Backup")
                {
                    DirectoryInfo dirBackupInfo = new DirectoryInfo(ApplicationBackupPathTemp + dir);
                    dirBackupInfo.Delete(true);
                }
                if (dir == "ExternalAssembly")
                {
                    DirectoryInfo dirExternalAssemblyInfo = new DirectoryInfo(ApplicationBackupPathTemp + dir);
                    dirExternalAssemblyInfo.Delete(true);
                }
            }

            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(ApplicationBackupPathTemp);
                zip.Save(DestinationPathTemp + ApplicationBackupZipFileName);

                //delete original folder
                DirectoryInfo dirApplicationBackupPathTemp = new DirectoryInfo(ApplicationBackupPathTemp);
                if (dirApplicationBackupPathTemp.Exists)
                {
                    //dirApplicationBackupPathTemp.Delete(true);
                    //OriginalBackupFile.Delete();
                }
            }

            //Save .bak file in folder
            using (BackupDal objBackupDal = new BackupDal())
            {
                int ResultBackp = objBackupDal.InsertBackup(DatabaseBackupFileName, DatabaseBackupPathTemp);
            }

            //Make zip file of backup
            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(DatabaseBackupPathTemp);
                zip.Save(DestinationPathTemp + DatabaseBackupZipFileName);

                //delete original folder
                DirectoryInfo dirDatabaseBackupPathTemp = new DirectoryInfo(DatabaseBackupPathTemp);
                if (dirDatabaseBackupPathTemp.Exists)
                {
                    dirDatabaseBackupPathTemp.Delete(true);
                    //OriginalBackupFile.Delete();
                }
            }

            // create Full backup zip
            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(DestinationPathTemp);
                zip.Save(DestinationPath + ZipFileName);

                //delete original folder
                DirectoryInfo dirDestinationPathTemp = new DirectoryInfo(DestinationPathTemp);
                if (dirDestinationPathTemp.Exists)
                {
                    dirDestinationPathTemp.Delete(true);
                    //OriginalBackupFile.Delete();
                }
            }

            //Create New FileName
            GlobalFileName = FileName();
            txtFileName.Text = GlobalFileName;


        }
Ejemplo n.º 2
0
        public bool SaveOnlyDatabase(string DestinationPath)
        {
            try
            {
                string GlobalFileName = txtFileName.Text.Trim();

                //string DestinationPath = ((Server.MapPath("~/Backup")).Replace("\\CRM.Presentation\\CRM.WebApp", "") + "\\" + GlobalFileName + "_Db");
                string DestinationPathTemp = DestinationPath + GlobalFileName + "\\";
                string BackupFileName = GlobalFileName + "_Db.bak";
                string ZipFileName = GlobalFileName + "_Database.zip";

                //Create Folder
                if (!Directory.Exists(@DestinationPathTemp))
                    System.IO.Directory.CreateDirectory(@DestinationPathTemp);

                //Save .bak file in folder
                using (BackupDal objBackupDal = new BackupDal())
                {
                    int Result = objBackupDal.InsertBackup(BackupFileName, DestinationPathTemp);
                }

                //Makezip file 
                using (ZipFile zip = new ZipFile())
                {
                    zip.AddDirectory(DestinationPathTemp);
                    zip.Save(DestinationPath + ZipFileName);

                    //delete original folder
                    DirectoryInfo dirDestinationPathTemp = new DirectoryInfo(DestinationPathTemp);
                    if (dirDestinationPathTemp.Exists)
                    {
                        dirDestinationPathTemp.Delete(true);
                        //OriginalBackupFile.Delete();
                    }
                }

                //Create New FileName
                GlobalFileName = FileName();
                txtFileName.Text = GlobalFileName;

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }