public void RemoveBackupTemplate(long id) { BackupTemplate item = this._BackupTemplateRepository.Find(id); this._BackupTemplateRepository.Remove(item); this.ClientConfigUpdated(item.IDClient); }
/// <summary> /// when the selected template to edit changes /// </summary> protected void OnEditChanged() { if (SelectedAddOrEdit()) { // selected new = clear inputs txtEditName.Text = txtEditPathsExclude.Text = txtEditPaths.Text = txtTypeFilter.Text = lblLastUsed.Text = ""; chbInvertType.Checked = false; } else { // selected existing = show values of this template BackupTemplate template = TemplateHandler.GetTemplateByName(cmbTemplatesEdit.Text); if (template == null) { SendOutput("[Templates] Selected template doesn't exist", true); return; } txtEditName.Text = template.BackupName; // append "," for adding new values txtEditPaths.Text = template.GetBackupPathsString() + ","; txtEditPathsExclude.Text = template.GetExcludePathsString() + ","; txtTypeFilter.Text = template.GetTypeFilterString() + ","; chbInvertType.Checked = template.TypeInverted; lblLastUsed.Text = template.LastUsed.ToString(); } // show buttons DisplayDeleteButton(); }
private void dataGrid_BackupTemplates_SelectionChanged(object sender, SelectionChangedEventArgs e) { BackupTemplate bt = this.dataGrid_Templates.SelectedItem as BackupTemplate; this._loadTemplateInfo(bt); e.Handled = true; }
public void SetTemplateStatus(long id, bool IsEnabled) { BackupTemplate item = this._BackupTemplateRepository.Find(id); item.Enabled = IsEnabled; this._BackupTemplateRepository.Update(item); this.ClientConfigUpdated(item.IDClient); }
private void btn_Template_Remove_Click(object sender, RoutedEventArgs e) { if (Xceed.Wpf.Toolkit.MessageBox.Show(this, "Are you sure?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { ESBackupServerAdminServiceClient client = new ESBackupServerAdminServiceClient(); BackupTemplate bt = this.dataGrid_Templates.SelectedItem as BackupTemplate; this._gridTemplatesList.Remove(bt); client.RemoveBackupTemplate(bt.ID); client.Close(); } }
/// <summary> /// copy the template that was used for the backup /// used to restore later /// </summary> private void AddUsedTemplate(string path, BackupTemplate template) { try { template.LastUsed = DateTime.Now; File.WriteAllText(path + ExportTemplatePath, template.ToXML()); } catch (Exception ex) { communication.SendOutput("[Backup] Could not add used template at" + path + ex.Message); } }
private List <BackupInfo> DoIncrementalBackup(BackupTemplate template) { //TODO: Do incremental and pass parameters into IncrBackup List <BackupInfo> data = new List <BackupInfo>(); foreach (BackupTemplatePath path in template.Paths) { this._Manager = new BackupManager(new LocalAccess()); //this.Manager.IncrementalBackup(); } return(data); }
private void btn_Template_Cancel_Click(object sender, RoutedEventArgs e) { BackupTemplate bt = this.dataGrid_Templates.SelectedItem as BackupTemplate; this.TemplateMode = TemplateInputModes.None; if (this._gridTemplatesList.Count == 0) { this.btn_Template_Edit.IsEnabled = false; } this._loadTemplateInfo(bt); }
private List <BackupInfo> DoDifferencialBackup(BackupTemplate template) { //TODO: Create backup infos and pass parameters into DiffBackup List <BackupInfo> data = new List <BackupInfo>(); foreach (BackupTemplatePath path in template.Paths) { this._Manager = new BackupManager(new LocalAccess()); //this.Manager.DifferentialBackup(); } return(data); }
/// <summary> /// copy list of folders, sets counters for output /// </summary> protected void CopyDirectories(BackupTemplate template, string targetPath, bool checkDate) { foldersToCopy = template.PathsBackup.Count; foldersCopied = 0; foreach (string source in template.PathsBackup) { if (source.Contains("\\")) { foldersCopied++; CopyDirectory(source, targetPath + source.Substring(source.LastIndexOf('\\')) + @"\", template, checkDate); } } }
public void ScheduleTemplate(BackupTemplate template, Guid sessionID) { IJobDetail job = JobBuilder.Create <TemplateBackupJob>() .WithIdentity("job_" + template.ID.ToString()) .Build(); job.JobDataMap.Add("template", template); job.JobDataMap.Add("sessionID", sessionID); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger_" + template.ID.ToString()) .StartNow() .WithCronSchedule(template.CRONRepeatInterval) .Build(); this._scheduler.ScheduleJob(job, trigger); }
private bool MakeBackup(string targetPath, string backupname, bool onlyChanged) { BackupTemplate template = TemplateHandler.GetTemplateByName(backupname); if (template == null) { communication.SendOutput("[Backup] " + (backupname ?? "NULL") + " template does not exist", true); return(false); } if (string.IsNullOrEmpty(targetPath)) { communication.SendOutput("[Backup] Destination folder does not exist: ", true); return(false); } try { // create destination, for sorting in explorer format year, month, day targetPath += "\\" + template.BackupName + "_" + DateTime.Now.ToString("yyyy_MM_dd"); if (onlyChanged) { targetPath += "_INC"; } // if backup does already exist add hour + minute if (Directory.Exists(targetPath)) { targetPath += "_" + DateTime.Now.ToString("HH_mm"); } Directory.CreateDirectory(targetPath); } catch { communication.SendOutput("[Backup] Could not create destination folder at " + targetPath, true); return(false); } communication.OnBackupProgressChanged("Started " + backupname); // copy files and folders CopyDirectories(template, targetPath, onlyChanged); AddUsedTemplate(targetPath, template); communication.SendOutput("[Backup] Saved at: " + targetPath); return(true); }
private void btn_Template_StatusChange_Click(object sender, RoutedEventArgs e) { ESBackupServerAdminServiceClient client = new ESBackupServerAdminServiceClient(); BackupTemplate template = this.dataGrid_Templates.SelectedItem as BackupTemplate; if (template.Enabled) { this.btn_Template_StatusChange.Content = "Enable"; template.Enabled = false; client.SetTemplateStatus(template.ID, false); } else if (!template.Enabled) { this.btn_Template_StatusChange.Content = "Disable"; template.Enabled = true; client.SetTemplateStatus(template.ID, true); } client.Close(); }
private List <BackupInfo> DoFullBackup(BackupTemplate template) { //TODO: Create backup infos List <BackupInfo> data = new List <BackupInfo>(); ushort i = 1; foreach (BackupTemplatePath path in template.Paths) { DateTime Begin = DateTime.UtcNow; this._Manager = new BackupManager(new LocalAccess()); this._Manager.FullBackup(path.Source, path.Destination + $"//{DateTime.UtcNow.ToString()}", template.SearchPattern, ".*", template.Compression); DateTime End = DateTime.UtcNow; data.Add(new BackupInfo() { IDClient = template.IDClient, IDBackupTemplate = template.ID, Name = template.Name, Description = "Backup created by template " + template.Name + "at time " + DateTime.UtcNow.ToShortDateString(), BackupType = 0, Source = path.Source, Destination = path.Destination, Compressed = template.Compression, UTCStart = Begin, UTCEnd = End, Status = 0, PathOrder = i, EmailSent = template.IsEmailNotificationEnabled } ); i++; } return(data); }
/// <summary> /// get the used template from a folder, returns null if not found /// </summary> private BackupTemplate GetTemplateToRestore(string path) { string templateSourceText = null; try { templateSourceText = File.ReadAllText(path + ExportTemplatePath); } catch { communication.SendOutput("[Restore] Could not find " + ExportTemplatePath + " in " + path); return(null); } BackupTemplate template = BackupTemplate.FromXML(templateSourceText); if (template == null) { communication.SendOutput("[Restore] could not read template from " + ExportTemplatePath + " file", true); } return(template); }
public void Execute(IJobExecutionContext context) { var dataMap = context.MergedJobDataMap; BackupTemplate template = (BackupTemplate)dataMap["template"]; this._SessionID = (Guid)dataMap["sessionID"]; switch (template.BackupType) { case 0: this.StoreInfo(this.DoFullBackup(template)); break; case 1: this.StoreInfo(this.DoDifferencialBackup(template)); break; case 2: this.StoreInfo(this.DoIncrementalBackup(template)); break; default: break; } }
private void SaveItemsToDisk() { var saveFileDialog = new Ookii.Dialogs.Wpf.VistaSaveFileDialog(); saveFileDialog.AddExtension = true; saveFileDialog.Filter = "Easy Backup Files | *.ebf"; saveFileDialog.DefaultExt = "ebf"; saveFileDialog.OverwritePrompt = true; saveFileDialog.Title = "Choose Save Location"; if (File.Exists(_lastSaveFilePath)) { saveFileDialog.FileName = _lastSaveFilePath; } if (saveFileDialog.ShowDialog(Application.Current.MainWindow).GetValueOrDefault()) { var backupTemplate = new BackupTemplate() { Paths = Items.ToList(), BackupLocation = BackupLocation }; var json = Newtonsoft.Json.JsonConvert.SerializeObject(backupTemplate); File.WriteAllText(saveFileDialog.FileName, json); UpdateLastUsedBackupPath(saveFileDialog.FileName); } }
/// <summary> /// copying function without recursion: /// "*", SearchOption.AllDirectories /// </summary> protected void CopyDirectory(string sourceDirName, string destDirName, BackupTemplate template, bool checkDate) { try { Directory.CreateDirectory(destDirName); } catch { communication.SendOutput("[Copying] Can't copy to " + destDirName ?? "NULL"); return; } // get files + folders to copy string destination = ""; List <string> copyDirectories; List <string> copyFiles; try { // excluding: after changing to none recursive some problems, solution: ShouldBeCopied copyDirectories = Directory.GetDirectories(sourceDirName, "*", SearchOption.AllDirectories).ToList(); copyFiles = Directory.GetFiles(sourceDirName, "*", SearchOption.AllDirectories).ToList(); // single files copyFiles.AddRange(template.PathsSingleFiles); filesCopied = 0; filesToCopy = copyFiles.Count; } catch { communication.SendOutput("[Copying] Could not get files to copy, make sure " + (sourceDirName ?? "NULL") + " is accessable", true); return; } // 1. create target directories foreach (string copyDir in copyDirectories) { try { // destination = target directory + path without source folder destination = Path.Combine(destDirName, copyDir.Substring(sourceDirName.Length + 1)); if (template.ShouldBeCopied(copyDir, false, checkDate)) { Directory.CreateDirectory(destination); } } catch (Exception ex) { AddCopyError(copyDir, ex); continue; } } // 2. copy files foreach (string copyFile in copyFiles) { try { destination = Path.Combine(destDirName, copyFile.Substring(sourceDirName.Length + 1)); if (template.ShouldBeCopied(copyFile, true, checkDate)) { File.Copy(copyFile, destination, overrideFiles); filesCopied++; } bgrWorker.ReportProgress(1); } catch (Exception ex) { AddCopyError(copyFile, ex); continue; } } // counters: totalFilesCopied += filesCopied; totalFilesToCopy += filesToCopy; }
public void SaveTemplate(BackupTemplate item) { this._BackupTemplateRepository.Update(item); this.ClientConfigUpdated(item.IDClient); }
internal List <BackupTemplatePath> Find(BackupTemplate template) { return(this._Context.TemplatesPaths.Where(x => x.IDBackupTemplate == template.ID).ToList()); }
private void _loadTemplateInfo(BackupTemplate bt) { this.TemplateMode = TemplateInputModes.None; this._templateTab_DisableComponents(); this._gridTemplateSourceList.Clear(); this._gridTemplateDestinationList.Clear(); if (bt != null) { this.btn_Template_Remove.IsEnabled = true; this.textBox_Template_Name.Text = bt.Name; this.textBox_Template_Description.Text = bt.Description; switch (bt.BackupType) { case 0: this.radioBtn_Template_Full.IsChecked = true; break; case 1: this.radioBtn_Template_Diff.IsChecked = true; break; case 2: this.radioBtn_Template_Increm.IsChecked = true; break; default: break; } this.radioBtn_Template_Compress.IsChecked = bt.Compression; if (bt.Paths != null) { foreach (BackupTemplatePath item in bt.Paths) { //TODO: Remake source path, ONLY ONE! if (this._gridTemplateSourceList.Where(x => x.Value == item.Source).FirstOrDefault() == null) { this._gridTemplateSourceList.Add(new SourcePathInfo(item.Source)); } this.dataGrid_Template_Source.ItemsSource = this._gridTemplateSourceList; if (this._gridTemplateDestinationList.Where(x => x.Value == item.Destination).FirstOrDefault() == null) { this._gridTemplateDestinationList.Add(new DestinationPathInfo(item.Destination, item.TargetType)); } this.dataGrid_Template_Destination.ItemsSource = this._gridTemplateDestinationList; } } if (!string.IsNullOrWhiteSpace(bt.SearchPattern)) { this.checkBox_Template_SearchPattern.IsChecked = true; this.textBox_Template_SearchPattern.Text = bt.SearchPattern; } this.textBox_Template_CRON.Text = bt.CRONRepeatInterval; if (bt.DaysToExpiration != null) { this.dateTimePicker_Template_Expire.Value = DateTime.Now.AddDays(Convert.ToDouble(bt.DaysToExpiration)); } else { this.dateTimePicker_Template_Expire.Value = null; } this.radioBtn_Template_NotifEnable.IsChecked = bt.IsNotificationEnabled; this.checkBox_Template_EmailReport.IsChecked = bt.IsEmailNotificationEnabled; this.btn_Template_StatusChange.Content = bt.Enabled ? "Disable" : "Enable"; this.btn_Template_StatusChange.IsEnabled = true; } else { this._templateTab_SetDefaultValues(); } }
private bool ExecuteRestore(string pathToRestore) { // get paths that will be restored and the template for the destination paths if (string.IsNullOrEmpty(pathToRestore)) { communication.SendOutput("[Restore] invalid path for restoring"); return(false); } // paths from the folder to restore string[] pathsToRestore; try { pathsToRestore = Directory.GetDirectories(pathToRestore); } catch { communication.SendOutput("[Restore] could not get folders to restore", true); return(false); } // template for destination paths BackupTemplate restoreTemplate = GetTemplateToRestore(pathToRestore); if (restoreTemplate == null) { return(false); // output already in get template method } communication.OnBackupProgressChanged("Started " + restoreTemplate.BackupName); // check if anything will be overwritten, if yes backup first bool needBackup = false; foreach (string pathExists in restoreTemplate.PathsBackup) { if (Directory.Exists(pathExists)) { needBackup = true; break; } } if (needBackup) { communication.SendOutput("[Restore] Creating backup of current files before overriding them"); //throw new NotImplementedException(); string targetPath = pathToRestore + "\\before_restore_" + DateTime.Now.ToString("dd_MM_yyyy__HH_mm"); CopyDirectories(restoreTemplate, targetPath, false); if (!DisplayCopyErrors("[Backup before restore]")) { // errors at copy before restore: ask if continue if (DarkDialog.DialogBoxDark.ShowDialog("Some files could not be saved before restoring." + "\nDo you want to overwrite them and restore anyway?", "Current files will be lost") != DialogResult.Yes) { return(false); } } } // name of template path string tempName = ""; // need to search target path for all paths from template, can't use copyDirectory foreach (string tempPath in restoreTemplate.PathsBackup) { tempName = GetNameOfPath(tempPath); foldersToCopy = pathsToRestore.Length + 1; foldersCopied = 0; foreach (string restore in pathsToRestore) { if (GetNameOfPath(restore) == tempName) { foldersCopied++; CopyDirectory(restore, tempPath, restoreTemplate, false); break; } } } return(true); }
private void btn_Template_Edit_Click(object sender, RoutedEventArgs e) { ESBackupServerAdminServiceClient client = new ESBackupServerAdminServiceClient(); if (this.TemplateMode == TemplateInputModes.Add) { Client c = this.listBox_Clients.SelectedItem as Client; BackupTemplate template = new BackupTemplate(); template.IDClient = c.ID; template.Name = this.textBox_Template_Name.Text; template.Description = this.textBox_Template_Description.Text; template.BackupType = this._template_GetTemplateType(); template.Compression = this.radioBtn_Template_Compress.IsChecked == true ? true: false; List <BackupTemplatePath> paths = new List <BackupTemplatePath>(); foreach (SourcePathInfo source in this._gridTemplateSourceList) { foreach (DestinationPathInfo dest in this._gridTemplateDestinationList) { paths.Add(new BackupTemplatePath() { Source = source.Value, Destination = dest.Value, PathOrder = Convert.ToInt16(paths.Count), TargetType = dest.TypeByte }); } } template.Paths = paths; if (this.checkBox_Template_SearchPattern.IsChecked == true) { template.SearchPattern = this.textBox_Template_SearchPattern.Text; } else { template.SearchPattern = ".*"; } template.CRONRepeatInterval = this.textBox_Template_CRON.Text; if (this.dateTimePicker_Template_Expire.Value != null) { template.DaysToExpiration = (uint?)((DateTime)this.dateTimePicker_Template_Expire.Value - DateTime.Now).Days; } template.IsNotificationEnabled = this.radioBtn_Template_NotifEnable.IsChecked == true ? true :false; template.IsEmailNotificationEnabled = this.checkBox_Template_EmailReport.IsChecked == true ? true : false; client.SaveTemplate(template); this._templateTab_DisableComponents(); this.TemplateMode = TemplateInputModes.None; this.TemplatesLoaded = false; this.LoadTemplatesData(c); this.dataGrid_Templates.SelectedIndex = this.dataGrid_Templates.Items.Count - 1; } else if (this.TemplateMode == TemplateInputModes.Edit) { BackupTemplate template = this.dataGrid_Templates.SelectedItem as BackupTemplate; template.Name = this.textBox_Template_Name.Text; template.Description = this.textBox_Template_Description.Text; template.BackupType = this._template_GetTemplateType(); template.Compression = this.radioBtn_Template_Compress.IsChecked == true ? true : false; //TODO: Maybe rework? //List<BackupTemplatePath> paths = new List<BackupTemplatePath>(); //foreach (SourcePathInfo source in this._gridTemplateSourceList) //{ // foreach (DestinationPathInfo dest in this._gridTemplateDestinationList) // { // paths.Add(new BackupTemplatePath() // { // IDBackupTemplate = template.ID, // Source = source.Value, // Destination = dest.Value, // PathOrder = Convert.ToInt16(paths.Count), // TargetType = dest.TypeByte // }); // } //} //template.Paths = paths; if (this.checkBox_Template_SearchPattern.IsChecked == true) { template.SearchPattern = this.textBox_Template_SearchPattern.Text; } else { template.SearchPattern = "*"; } template.CRONRepeatInterval = this.textBox_Template_CRON.Text; if (this.dateTimePicker_Template_Expire.Value != null) { template.DaysToExpiration = (uint?)((DateTime)this.dateTimePicker_Template_Expire.Value - DateTime.Now).Days; } template.IsNotificationEnabled = this.radioBtn_Template_NotifEnable.IsChecked == true ? true : false; template.IsEmailNotificationEnabled = this.checkBox_Template_EmailReport.IsChecked == true ? true : false; client.SaveTemplate(template); this._templateTab_DisableComponents(); this.TemplateMode = TemplateInputModes.None; } else if (this.TemplateMode == TemplateInputModes.None) { this.TemplateMode = TemplateInputModes.Edit; this._templateTab_EnableComponents(); this.groupBox_Template_Path.IsEnabled = false; this.groupBox_Template_Type.IsEnabled = false; } client.Close(); }