private UploaderSettings GenerateUploaderSetting(Config.Categories.BackupConfiguration configuration) { var s3Settings = BackupTask.GetBackupConfigurationFromScript(Configuration.Connection.S3Settings, x => JsonDeserializationServer.S3Settings(x), Database, updateServerWideSettingsFunc: null, serverWide: false); var azureSettings = BackupTask.GetBackupConfigurationFromScript(Configuration.Connection.AzureSettings, x => JsonDeserializationServer.AzureSettings(x), Database, updateServerWideSettingsFunc: null, serverWide: false); var glacierSettings = BackupTask.GetBackupConfigurationFromScript(Configuration.Connection.GlacierSettings, x => JsonDeserializationServer.GlacierSettings(x), Database, updateServerWideSettingsFunc: null, serverWide: false); var googleCloudSettings = BackupTask.GetBackupConfigurationFromScript(Configuration.Connection.GoogleCloudSettings, x => JsonDeserializationServer.GoogleCloudSettings(x), Database, updateServerWideSettingsFunc: null, serverWide: false); var ftpSettings = BackupTask.GetBackupConfigurationFromScript(Configuration.Connection.FtpSettings, x => JsonDeserializationServer.FtpSettings(x), Database, updateServerWideSettingsFunc: null, serverWide: false); return(new UploaderSettings(configuration) { S3Settings = s3Settings, AzureSettings = azureSettings, GlacierSettings = glacierSettings, GoogleCloudSettings = googleCloudSettings, FtpSettings = ftpSettings, DatabaseName = Database.Name, TaskName = Name }); }
public BackupMasterForm(ProgramOptions options, List <BackupTask> backupTasksChain) { InitializeComponent(); if (Program.PackageIsBroken || Program.SevenZipIsBroken) { throw new InvalidOperationException("Tried to perform operation that requires package state is ok."); } tasksListView.Columns[0].Width = tasksListView.Width - 40; processingStateInformationColumnHeader.Width = 0; //TODO: please move to controller if (backupTasksChain.Count == 0) { using (var form = new SelectTaskToRunForm(options.BackupTasks)) { if (form.ShowDialog() == DialogResult.OK) { backupTasksChain = form.TasksToRun; } else { Environment.Exit(-1); } } } _task = backupTasksChain[0]; _controller = new BackupUiMaster(_task, options); _controller.BackupFinished += OnBackupFinsihed; CompressionItemsListViewResize(null, null); ApplyLocalization(Translation.Current); }
public void OpenBackupUiMaster(string[] taskTitles, bool runFormAsApplication) { if (taskTitles == null) { throw new ArgumentNullException("taskTitles"); } if (Program.PackageIsBroken || Program.SevenZipIsBroken) { return; } if (!runFormAsApplication) { var arguments = new StringBuilder(Arguments.RunBackupMaster); foreach (var taskTitle in taskTitles) { arguments.Append(string.Format(" \"{0}={1}\"", Arguments.RunTask, taskTitle)); } Process.Start(Application.ExecutablePath, arguments.ToString()); return; } LoadSettings(); //TODO: now we suppoprt execution of just one task. But it will be great if we could execute each tasl one by one // here among checked in task selection form var backupTasksChain = new List <BackupTask>(); foreach (var taskTitle in taskTitles) { BackupTask backupTask = null; foreach (var task in ProgramOptions.BackupTasks) { if (task.Key == taskTitle) { backupTask = task.Value; } } if (backupTask == null) { Messages.ShowErrorBox(string.Format("Missing task '{0}' is missing.", taskTitle)); } else { backupTasksChain.Add(backupTask); } } // This must be refactored in order to use something like Tool pattern using (var form = new BackupMasterForm(_profileOptions, backupTasksChain)) { Application.Run(form); } Environment.Exit(0); }
private void NotifyIcon_MouseMove(object sender, MouseEventArgs e) { try { BackupTask backupTask = viewModel.BackupTask; if (backupTask != null && !backupTask.Result.HasValue) { notifyIcon.Text = "Is Backuping"; } else { BackupConfig config = viewModel.Config; if (config == null || config.NextScheduledBackup == DateTime.MaxValue || !config.IsBackupEnabled) { notifyIcon.Text = "No Backup scheduled"; } else { TimeSpan timeUntilNextBackup = config.NextScheduledBackup - DateTime.Now; notifyIcon.Text = ConvertTimeSpanToStringLong(timeUntilNextBackup); } } } catch (Exception exc) { DebugEvent.SaveText("NotifyIcon_MouseMove", exc); } }
public void Backup_CanUploadDatabaseBackup() { DatabaseTargetConfigurationElement config = GetBackupTarget(); BackupTask task = new BackupTask(config); string path = task.BackupDatabase(); task.UploadBackup(path); }
public static bool TryExtractDateFromFileName(string filePath, out DateTime lastModified) { // file name format: 2017-06-01-00-00-00 // legacy incremental backup format: 2017-06-01-00-00-00-0 var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath); var match = FileNameRegex.Match(fileNameWithoutExtension); if (match.Success) { fileNameWithoutExtension = match.Value; } if (DateTime.TryParseExact( fileNameWithoutExtension, BackupTask.GetDateTimeFormat(fileNameWithoutExtension), CultureInfo.InvariantCulture, DateTimeStyles.None, out lastModified) == false) { return(false); } return(true); }
public void Backup_CanBackupDatabase() { DatabaseTargetConfigurationElement config = GetBackupTarget(); BackupTask task = new BackupTask(config); string path = task.BackupDatabase(); Assert.IsTrue(File.Exists(path)); }
public void Backup_CanExecuteBackupTask() { DatabaseTargetConfigurationElement config = GetBackupTarget(); BackupTask task = new BackupTask(config); task.Execute(); }
private static void ExecuteBackup(DatabaseTargetConfigurationElement target) { try { BackupTask task = new BackupTask(target); task.BackupComplete += new EventHandler <DatabaseTargetEventArgs>(BackupComplete); task.BackupStart += new EventHandler <DatabaseTargetEventArgs>(BackupStart); task.CompressComplete += new EventHandler <DatabaseTargetEventArgs>(BackupCompressComplete); task.CompressStart += new EventHandler <DatabaseTargetEventArgs>(BackupCompressStart); task.TransferComplete += new EventHandler <DatabaseTargetEventArgs>(BackupTransferComplete); task.TransferProgress += new EventHandler <DatabaseTargetEventArgs>(BackupTransferProgress); task.TransferStart += new EventHandler <DatabaseTargetEventArgs>(BackupTransferStart); var result = task.Execute(); if (!result.Success) { WriteError(result.Exception); } } catch (Exception ex) { WriteError(ex); } }
public override void SetOptionsToUi(object settings) { _task = (BackupTask)settings; foreach (StorageBase storage in _task.Storages) { StorageEnum kind; switch (storage.GetType().Name) { case "HddStorage": kind = StorageEnum.Hdd; break; case "FtpStorage": kind = StorageEnum.Ftp; break; case "NetworkStorage": kind = StorageEnum.Network; break; default: throw new NotImplementedException(storage.GetType().Name); } AddStorageToListView(storage, kind); } }
/// <summary> /// The constructor /// </summary> /// <param name="task">backup task to schedule</param> public Scheduler(BackupTask task) { //TODO: task must be replced with h, m, days _task = task; _actionTimer.Elapsed += new ElapsedEventHandler(onTimedEvent); }
public override void SetOptionsToUi(object settings) { _task = (BackupTask)settings; _itemsToBackup = new CompressionItemsKeeper(compressionItemsListView, _task.FilesFoldersList); _itemsToBackup.ApplyNewDegreesOfCompression(); _itemsToBackup.InitWith(); }
public override void SetOptionsToUi(object settings) { object[] objects = (object[])settings; _profileOptions = (ProgramOptions)objects[0]; _task = (BackupTask)objects[1]; passwordTextBox.Text = _task.SecretPassword; passwordConfirmationTextBox.Text = _task.SecretPassword; }
void AddTask(BackupTask task) { var item = new ListViewItem(task.Name, 0) { Tag = task }; _tasksListView.Items.Add(item); }
public BackupTaskEditForm(ProgramOptions profileOptions, BackupTask task) { InitializeComponent(); _task = task; _profileOptions = profileOptions; _views = new Dictionary <BackupTaskViewsEnum, BackUserControl>(); SetupUiComponents(); ApplyLocalization(); }
private void TimerProc(object state) { var task = GetBackupTask(); if (task != CurrentBackupTask) { CurrentBackupTask = task; SaveBackupTaskToDisk(); OnBackupTaskChange?.Invoke(this, new EventArgs()); } }
private async void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(ViewModel.BackupTask)) { BackupTask backupTask = viewModel.BackupTask; if (backupTask != null) { await ShowNotifyIcon(backupTask); } } }
public override void SetOptionsToUi(object settings) { _task = (BackupTask)settings; foreach (DayOfWeek enumItem in DayOfWeek.GetValues(typeof(DayOfWeek))) { scheduledDaysCheckedListBox.SetItemChecked((int)enumItem, _task.IsThisDayOfWeekScheduled(enumItem)); } hourComboBox.SelectedIndex = _task.Hours; minuteComboBox.SelectedIndex = _task.Minutes; }
private async Task ShowNotifyIcon(BackupTask task) { int itemsCount = task.Items.Length; if (viewModel.IsHidden) { string balloonTipTextBegin = itemsCount + (itemsCount == 1 ? " Directory" : " Directories"); notifyIcon.ShowBalloonTip(5000, "Backup started.", balloonTipTextBegin, ToolTipIcon.Info); } BackupTaskResult result = await task; if (!viewModel.IsHidden) { return; } TimeSpan backupTimeSpan = DateTime.Now - task.Started; string balloonTipTextEnd = itemsCount + (itemsCount == 1 ? " Directory\n" : " Directories\n") + ConvertTimeSpanToStringLong(backupTimeSpan); switch (result) { case BackupTaskResult.Successful: notifyIcon.ShowBalloonTip(5000, "Backup finished.", balloonTipTextEnd, ToolTipIcon.Info); break; case BackupTaskResult.DestinationFolderNotFound: notifyIcon.ShowBalloonTip(5000, "Destination folder not found.", balloonTipTextEnd, ToolTipIcon.Warning); break; case BackupTaskResult.NoItemsToBackup: notifyIcon.ShowBalloonTip(5000, "No items to backup.", balloonTipTextEnd, ToolTipIcon.Warning); break; case BackupTaskResult.Exception: notifyIcon.ShowBalloonTip(5000, "Backup failed.", task.FailedException.Message, ToolTipIcon.Error); break; case BackupTaskResult.ValidationError: notifyIcon.ShowBalloonTip(5000, "Validation of backup failed.", balloonTipTextEnd, ToolTipIcon.Warning); break; case BackupTaskResult.Canceled: notifyIcon.ShowBalloonTip(5000, "Backup got canceled.", balloonTipTextEnd, ToolTipIcon.Warning); break; } }
private void LoadNewTask() { backupTask = _backupTaskService.CurrentBackupTask; if (backupTask != null && backupTask.VirtualMachines != null && backupTask.VirtualMachines.Count > 0) { _progressReporter.SendReportsFor(backupTask.VirtualMachines); } LoadSchedulesFromBackupTask(); _logger.LogInformation("New backup task was loaded."); }
public void StartBackup(string[] directories) { foreach (string dir in directories) { if (Directory.Exists(dir)) { BackupTask bt = new BackupTask(dir, Node.GetTemporaryDirectory(), 123, 0); //if (storageThread == null) Logger.Log("shit"); storageThread.EnqueueStorageTask(bt); } else { Logger.Warn("EchoBackupService:StartBackup Directory '" + dir + "' does not exist."); } } }
public OlapDocumentTransformer(Transformation transformation, DocumentDatabase database, DocumentsOperationContext context, OlapEtlConfiguration config) : base(database, context, new PatchRequest(transformation.Script, PatchRequestType.OlapEtl), null) { _config = config; _tables = new Dictionary <string, OlapTransformedItems>(); var localSettings = BackupTask.GetBackupConfigurationFromScript(_config.Connection.LocalSettings, x => JsonDeserializationServer.LocalSettings(x), database, updateServerWideSettingsFunc: null, serverWide: false); _localFilePath = localSettings?.FolderPath ?? (database.Configuration.Storage.TempPath ?? database.Configuration.Core.DataDirectory).FullPath; _fileNameSuffix = ParquetTransformedItems.GetSafeNameForRemoteDestination($"{database.Name}-{_config.Name}-{transformation.Name}"); LoadToDestinations = transformation.GetCollectionsFromScript(); }
public AddBackupTaskWizardView(ProgramOptions options) { _options = options; Task = ProgramOptionsManager.GetDefaultBackupTask(Translation.Current[622]); _steps.Add(new PageInfo(Translation.Current[623], Translation.Current[624], RegisterControl(BackupTaskViewsEnum.Name, new TaskNameUserControl()), Icons.BackupTask48x48)); _steps.Add(new PageInfo(Translation.Current[72], Translation.Current[625], RegisterControl(BackupTaskViewsEnum.SourceItems, new SourceItemsUserControl()), Icons.SourceItems48x48)); _steps.Add(new PageInfo(Translation.Current[79], Translation.Current[626], RegisterControl(BackupTaskViewsEnum.Storages, new StoragesUserControl()), Icons.Storages48x48)); if (Program.SchedulerInstalled && !options.DontNeedScheduler) { _steps.Add(new PageInfo(Translation.Current[123], Translation.Current[627], RegisterControl(BackupTaskViewsEnum.Scheduler, new SchedulerUserControl()), Icons.Schedule48x48)); } _steps.Add(new PageInfo(Translation.Current[83], Translation.Current[628], RegisterControl(BackupTaskViewsEnum.Encryption, new EncryptionUserControl()), Icons.Password48x48)); _steps.Add(new PageInfo(Translation.Current[96], Translation.Current[629], RegisterControl(BackupTaskViewsEnum.OtherOptions, new TaskOtherOptionsUserControl()), Icons.OtherSettings48x48)); _step = 0; }
public BackupResult CreateBackup(int tenantID, Guid userID) { lock (tasks.SynchRoot) { var task = tasks.GetItems().OfType <BackupTask>().FirstOrDefault(t => t.Tenant == tenantID); if (task != null && task.IsCompleted) { tasks.Remove(task); task = null; } if (task == null) { task = new BackupTask(tenantID, userID); tasks.Add(task); } return(ToResult(task)); } }
private void CreateNewBackupTaskFile(string path) { var localVMs = Util.GetLocalVirtualMachines(); if (localVMs.Count == 0) { throw new Exception("Could not find any virtual machines. Cannot continue."); } var bt = new BackupTask(); bt.ParallelBackups = 1; bt.VirtualMachines = CreateDefaultVMs(localVMs); string json = JsonConvert.SerializeObject(bt, Formatting.Indented); File.WriteAllText(path, json); }
public BackupTaskService(ILogger <BackupTaskService> logger , IConfiguration config , ICentralServer centralServer) { timer = new Timer(new TimerCallback(TimerProc), null, Timeout.Infinite, Timeout.Infinite); _logger = logger; _config = config; _centralServer = centralServer; CurrentBackupTask = GetBackupTask(); // task was downloaded from central server if (_centralServer.PingSuccess) { SaveBackupTaskToDisk(); } }
private async Task CheckForBackup() { DebugEvent.SaveText("CheckForBackup", "NextBackup: " + viewModel.Config.NextScheduledBackup); BackupConfig config = viewModel.Config; if (config == null || config.NextScheduledBackup > DateTime.Now) { return; } BackupTask backupTask = viewModel.BackupTask; if (config.IsBackupEnabled && (backupTask == null || backupTask.Result.HasValue)) { await BackupAsync(); } }
private void Backup(Database database, Dao dao) { if (database == SourceDatabase) { BackupTask = Task.Run(() => { object dtoInstance = Dto.Copy(dao); object existing = BackupRepository.Retrieve(dtoInstance.GetType(), dtoInstance.Property <string>("Uuid")); if (existing != null) { BackupRepository.Save(dtoInstance); } else { BackupRepository.Create(dtoInstance); } }); BackupTask.ConfigureAwait(false); } }
/// <summary> /// tests the basic Tar and GZip functionality. /// </summary> static void testTarGZip() { Console.WriteLine("starting testTarBzip2"); byte[] b = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; Guid guid = new Guid(b); string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\temp\\scratch"; string tempPath2 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\temp\\scratch 2"; StorageThread st = new StorageThread(tempPath, guid); BackupTask task = new BackupTask(tempPath, tempPath2, 123, 0); st.EnqueueStorageTask(task); Console.WriteLine("queued task"); int x = 0; while (st.IsWorking()) { x++; Console.WriteLine("waiting for thread to finish." + x); Thread.Sleep(1000); } Console.WriteLine("thread finished."); st.RequestStop(); Console.WriteLine("requested thread terminate."); while (st.IsAlive()) { x++; Console.WriteLine("waiting for thread to die. " + x); Thread.Sleep(1000); } Console.WriteLine("thread is dead."); Console.WriteLine("number of chunks: " + st.NumChunks()); while (st.NumChunks() > 0) { Chunk c = st.DequeueChunk(); Console.WriteLine(c); } Console.WriteLine("press a key to continue"); Console.ReadKey(); }
public ActionResult Edit([Bind(Include = "Id,Name,Memo,DbName,ConnectionId,CloudDriveId,CopyOnly,Compression,UseZip,AddCurrentDateTime")] ModelBackupTaskViewEdit item) { if (ModelState.IsValid) { var v = item.Id.Equals(Guid.Empty.ToString())? null: DbContext.Current.GetBackupTasks().Find(s => s.Id == item.Id); if (v != null) { v.Name = item.Name; v.Memo = item.Memo; v.DbName = item.DbName; v.ConnectionId = item.ConnectionId; v.CloudDriveId = item.CloudDriveId; v.CopyOnly = item.CopyOnly; v.Compression = item.Compression; v.UseZip = item.UseZip; v.AddCurrentDateTime = item.AddCurrentDateTime; } else { v = new BackupTask(); v.Id = item.Id; v.Name = item.Name; v.Memo = item.Memo; v.DbName = item.DbName; v.ConnectionId = item.ConnectionId; v.CloudDriveId = item.CloudDriveId; v.CopyOnly = item.CopyOnly; v.Compression = item.Compression; v.UseZip = item.UseZip; v.AddCurrentDateTime = item.AddCurrentDateTime; if (item.Id.Equals(Guid.Empty.ToString())) { v.NewId(); } } DbContext.Current.Save(v); return(RedirectToAction("Index")); } return(View(item)); }
private static void ExecuteBackup(DatabaseTargetConfigurationElement target) { try { BackupTask task = new BackupTask(target); task.BackupComplete += new EventHandler<DatabaseTargetEventArgs>(BackupComplete); task.BackupStart += new EventHandler<DatabaseTargetEventArgs>(BackupStart); task.CompressComplete += new EventHandler<DatabaseTargetEventArgs>(BackupCompressComplete); task.CompressStart += new EventHandler<DatabaseTargetEventArgs>(BackupCompressStart); task.TransferComplete += new EventHandler<DatabaseTargetEventArgs>(BackupTransferComplete); task.TransferProgress += new EventHandler<DatabaseTargetEventArgs>(BackupTransferProgress); task.TransferStart += new EventHandler<DatabaseTargetEventArgs>(BackupTransferStart); var result = task.Execute(); if (!result.Success) { WriteError(result.Exception); } } catch (Exception ex) { WriteError(ex); } }
public BackupResult CreateBackup(int tenantID, Guid userID) { lock (tasks.SynchRoot) { var task = tasks.GetItems().OfType<BackupTask>().FirstOrDefault(t => t.Tenant == tenantID); if (task != null && task.IsCompleted) { tasks.Remove(task); task = null; } if (task == null) { task = new BackupTask(tenantID, userID); tasks.Add(task); } return ToResult(task); } }