コード例 #1
0
ファイル: frmProgress.cs プロジェクト: mmecs/Test
 private void BackupStart(BackupSetInfo SettingsInfoOf)
 {
     response = backup.BackupFiles(SettingsInfoOf);
     if (_Info == true)
     {
         this.Invoke(new BackupFinishedDelegate(BackupFinished));
     }
 }
コード例 #2
0
        public BackupResponseInfo BackupFiles(BackupSetInfo BackupSetInfoOf)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();

            string             backupLocation = "";
            BackupResponseInfo response       = new BackupResponseInfo();

            foreach (string sS in BackupSetInfoOf.BackupDirectories)
            {
                if (!Directory.Exists(sS))
                {
                    response.IsSuccess = false;
                    response.Message  += "Fehler im Backup.  Verzeichniss " + sS + " existiert nicht.\r\n";
                }
                if (!Directory.Exists(BackupSetInfoOf.BackupToDirectory))
                {
                    response.IsSuccess = false;
                    response.Message  += "Fehler im Backup.  Verzeichniss " + BackupSetInfoOf.BackupToDirectory + " existiert nicht.\r\n";
                }
            }

            if (BackupSetInfoOf.BackupZip == "true")
            {
                backupLocation = BackupSetInfoOf.BackupToDirectory + BackupSetInfoOf.BackupName;
                mZip           = "true";
            }
            else
            {
                backupLocation = BackupSetInfoOf.BackupToDirectory + BackupSetInfoOf.BackupName + "_" + DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + "\\";
            }

            if (response.Message.Length < 1)
            {
// Zählen
                foreach (string sS in BackupSetInfoOf.BackupDirectories)
                {
                    if (BackupSetInfoOf.BackupZip == "false")
                    {
                        DirectoryInfo dD = new DirectoryInfo(backupLocation + sS.Replace(":", ""));
                        dD.Create();
                        CopyDirectory(new DirectoryInfo(sS), dD, true);
                    }
                    //else
                    //{
                    //    DirectoryInfo zD = new DirectoryInfo(backupLocation);
                    //    ZipDirectory(new DirectoryInfo(sS), zD, false);
                    //}
                }
// Kopieren
                int    _z = 0;
                string _backupLocation = backupLocation;
                foreach (string sS in BackupSetInfoOf.BackupDirectories)
                {
                    if (BackupSetInfoOf.BackupZip == "false")
                    {
                        DirectoryInfo dD = new DirectoryInfo(backupLocation + sS.Replace(":", ""));
                        dD.Create();
                        CopyDirectory(new DirectoryInfo(sS), dD, false);
                    }
                    else
                    {
                        _z             = _z + 1;
                        backupLocation = _backupLocation + "_" + Convert.ToString(_z) + "--" + Convert.ToString(BackupSetInfoOf.BackupDirectories.Count) + "_" + DateTime.Now.ToString("dd-MM-yyyy hh-mm-ss") + ".zip";
                        DirectoryInfo zD = new DirectoryInfo(backupLocation);
                        ZipDirectory(new DirectoryInfo(sS), zD, false);;
                    }
                }
// Fertig
                watch.Stop();
                response.IsSuccess = true;
                response.Message  += "Backup erfolgreich beendet. Time spent: " + watch.Elapsed;
            }
            return(response);
        }