public void StartTransaction() { if (!IsEditing) { _editBackup = new BackupState(); } }
public void Rollback() { if (IsEditing) { _editBackup = null; } }
public void CancelEdit() { if (IsEditing) { _editBackup = null; } }
private void Bf_backupProgressChanged(BackupState state, float progressFloat) { bwBackup.ReportProgress(60 + (int)Math.Ceiling(progressFloat / 100.0 * 40), new ProgressUpdate() { action = "Compression in progress...", progressStyle = ProgressBarStyle.Blocks }); }
private async Task WriteHistoryAsync(VirtualMachine vm, BackupState bs) { var history = await _context.History.FirstOrDefaultAsync(h => h.VirtualMachine == vm && h.BackupDateStart == bs.BackupStartDate); if (history == null) { history = new BackupHistory(); _context.History.Add(history); } history.VirtualMachine = vm; history.LastKnownStatus = bs.Status.ToString(); history.ExportedToFolder = bs.ExportedToFolder; history.ArchivedToFile = bs.ArchivedToFile; if (bs.Status == BackupJobStatus.Completed) { history.Success = true; } else { history.Success = false; } if (bs.BackupStartDate.HasValue) { history.BackupDateStart = bs.BackupStartDate.Value; } history.BackupDateEnd = bs.BackupEndDate; }
public static void LoadBackupStatus(MyBackup backup) { var MyIni = new IniFile("BackupStatus.ini"); var StrIndexes = MyIni.ReadString("Configuration", "Indexes#" + backup.MyIndex, ""); int[] Indexes = StrIndexes.Split(',').Select(x => int.TryParse(x, out var i) ? i : 0).ToArray(); foreach (var i in Indexes) { string Section = "Status#" + backup.MyIndex + "#" + i.ToString(); int MyIndex = MyIni.ReadInt32(Section, "MyIndex", 0); if (MyIndex > 0) { var state = new BackupState() { StateIndex = MyIndex, backup = backup, FullPath = MyIni.ReadString(Section, "FullPath"), BackupDateTime = MyIni.ReadInt64(Section, "BackupDateTime"), DefaultBackupDateTime = MyIni.ReadInt64(Section, "DefaultBackupDateTime"), Warning = MyIni.ReadBoolean(Section, "Warning"), WarningMessage = MyIni.ReadString(Section, "WarningMessage"), FullWarning = MyIni.ReadString(Section, "FullWarning"), Read = MyIni.ReadBoolean(Section, "Read"), }; backup.BackupStatus.Add(state); } } }
public void BeginEdit() { if (!IsEditing) { _editBackup = new BackupState(); } }
private void InitiateBackup(string savegame, bool force = false, bool delayed = true) { // Always run backups in cleanup state, this will ensure to do a backup when Timber and Stone was closed // In any other case we will check if the last backup for this savegame was to recent to do a new one if (!force) { // Check if it's about time to backup this savegame if (BackupRecentlyPerformed(savegame)) { // nope, wait for the next attempt return; } } // init backup and start timer _backupState = BackupState.Running; _backupSavegame = savegame; if (delayed) { _backupTimer.Start(); } else { RunBackup(); } }
private void WriteCurrentStateToDB(VirtualMachine vm, BackupState bs) { vm.Status = bs.Status.ToString(); vm.PercentComplete = bs.PercentComplete; vm.StatusUpdated = DateTime.Now; vm.LastBackup = bs.LastBackup; }
protected override void OnRaiseSuccess(IEventBase <K> @event, byte[] bytes) { using (var dms = new MemoryStream(bytes)) { Apply(BackupState, (IEventBase <K>)Serializer.Deserialize(@event.GetType(), dms)); } BackupState.FullUpdateVersion(@event, GrainType);//更新处理完成的Version }
// Constructor. public BackupEventArgs(double progress, BackupState state, string message, string message2, List <ArchiverError> log) { Progress = progress; State = state; Message = message; Message2 = message2; Log = log; }
private BackupResponse CreateBackupResponse(BackupState state, bool withHistory) { return(new BackupResponse { State = state, Current = _backupManager?.BackupInfo.Clone(), History = withHistory ? _backupHistory.ToArray() : null, }); }
public void EndEdit() { if (IsEditing) { var editObject = _editBackup; _editBackup = null; foreach (var item in editObject.NewValues) SetMember(item.Key, item.Value); } }
protected override void OnRaiseSuccess(IEventBase <K> @event, byte[] bytes) { if (MessageTypeMapper.EventTypeDict.TryGetValue(@event.TypeCode, out var type)) { using (var dms = new MemoryStream(bytes)) { Apply(BackupState, (IEventBase <K>)GetSerializer().Deserialize(type, dms)); } BackupState.FullUpdateVersion(@event);//更新处理完成的Version } }
public void Commit() { if (IsEditing) { var editObject = _editBackup; _editBackup = null; foreach (var item in editObject.NewValues) { SetMember(item.Key, item.Value); } } }
public static void DeleteBackupState(BackupState state) { var backupIndex = state.backup.MyIndex.ToString(); IniFile MyIni = new IniFile("BackupStatus.ini"); MyIni.DeleteSection("Status#" + backupIndex + "#" + state.StateIndex); string[] Indexes = state.backup.BackupStatus.Select(x => x.StateIndex == state.StateIndex ? string.Empty : (x.StateIndex.ToString() + ",")).ToArray(); string NewIndexes = string.Join(string.Empty, Indexes.Where(x => x.Length > 0)); MyIni.Write("Configuration", "Indexes#" + backupIndex, NewIndexes); state.backup.BackupStatus.Remove(state); }
protected async ValueTask RollbackTransaction() { if (transactionPending) { if (BackupState.Version == transactionStartVersion) { State = BackupState.DeepCopy(); } else { await RecoveryState(); } transactionEventList.Clear(); transactionPending = false; } }
private void ReportToCentralServer() { var states = new List <BackupState>(); foreach (var vm in monitoredVMs) { int percent = 0; switch (vm.Status) { case BackupJobStatus.Exporting: percent = vm.ExportPercentComplete; break; case BackupJobStatus.Archiving: percent = vm.ArchivePercentComplete; break; } var state = new BackupState() { VmName = vm.Name, BackupStartDate = vm.BackupStartDate, BackupEndDate = vm.BackupEndDate, Status = vm.Status, PercentComplete = percent, ExportedToFolder = vm.ExportPath, ArchivedToFile = vm.ArchivePath, LastBackup = vm.LastBackup }; states.Add(state); } var progress = new HttpPostBackupProgress(); progress.Hypervisor = Util.GetCurrentServerFQDN(); progress.BackupStates = states; var result = _centralServer.SendBackupProgress(progress).Result; if (!result.Success) { _logger.LogError("Error occurred while send backup progress to central server. Error was: {err}", result.Message); } }
public void AddBackupCompressCompletedEntries( BackupType backupType, DateTime compressStarted, DateTime compressEnded, BackupState backupState, ICollection<string> backedupFilePaths, ICollection<string> storagePendingFilesPaths) { if (backedupFilePaths.Count <= 0) throw new ArgumentOutOfRangeException( "backedupFilePaths", backedupFilePaths.Count, "Should be more than zero."); if (storagePendingFilesPaths.Count <= 0) throw new ArgumentOutOfRangeException( "storagePendingFilesPaths", storagePendingFilesPaths.Count, "Should be more than zero."); if (backupState == BackupState.FileCompressSuccess) UpdateBackupLog( backedupFilePaths, backupType == BackupType.Full); lock (_backupHistoryFileLock) { var document = _backupHistoryDocument.Value; if (document.Root == null) throw new Exception("Root element is missing."); document.Root.Add( new BackupHistoryEntry { Id = GetLastBackupHistoryEntryId() + 1, BackupState = backupState, BackupType = backupType, CompressStarted = compressStarted, CompressEnded = compressEnded, NumberOfBackedupFiles = backedupFilePaths.Count, StoragePendingFilesPaths = storagePendingFilesPaths.ToArray() }.ToXElement()); document.Save(_backupHistoryFilePath); InitializeBackupHistoryCache(); } }
private void backgroundWorkerTnS_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { Work work = e.Result as Work; if (work == null) { labelStatus.Text = "Monotoring Timber and Stone..."; _backupState = BackupState.Idle; _cleanupState = CleanupState.None; } else if ((work.Job & JobType.Cleanup) == JobType.Cleanup) { labelStatus.Text = "Closing..."; _cleanupState = CleanupState.Finished; this.Close(); } else // if (work.Job == JobType.Backup) { _backupState = BackupState.Idle; } }
public static void SaveBackupState(BackupState state) { var MyIni = new IniFile("BackupStatus.ini"); var backupIndex = state.backup.MyIndex.ToString(); var Section = "Status#" + backupIndex + "#"; if (state.StateIndex == 0) { var Indexes = MyIni.ReadString("Configuration", "Indexes#" + backupIndex, 0); var MaxIndex = Indexes.Split(',').Max(x => int.TryParse(x, out var i) ? i : 0) + 1; state.StateIndex = MaxIndex; Section += MaxIndex.ToString(); string[] IndexesArr = state.backup.BackupStatus.Select(x => x.StateIndex.ToString() + ",").ToArray(); string NewIndexes = string.Join(string.Empty, IndexesArr) + MaxIndex.ToString(); MyIni.Write("Configuration", "Indexes#" + backupIndex, NewIndexes); } else { Section += state.StateIndex.ToString(); } MyIni.Write(Section, "MyIndex", state.StateIndex); MyIni.Write(Section, "FullPath", state.FullPath); MyIni.Write(Section, "BackupDateTime", state.BackupDateTime); MyIni.Write(Section, "DefaultBackupDateTime", state.DefaultBackupDateTime); MyIni.Write(Section, "Warning", state.Warning); MyIni.Write(Section, "WarningMessage", state.WarningMessage); MyIni.Write(Section, "FullWarning", state.FullWarning); MyIni.Write(Section, "Read", state.Read); if (!state.backup.BackupStatus.Contains(state)) { state.backup.BackupStatus.Add(state); } }
public void CreateArchiev(string destinationPath, string fileNameFormat = "{name}_{date}") { if (CurrentBaseType != BaseType.File) { return; } var sourceFileName = System.IO.Path.Combine(BaseName, "1Cv8.1CD"); KickAllUsers(); var fileNamesStruct = new FileNamesStruct(fileNameFormat, destinationPath, this, "zip"); var backupFileName = fileNamesStruct.BackupFileName; var compressResult = CompressFileConsole(sourceFileName, backupFileName); var testResult = TestArchieveConsole(backupFileName); if (string.IsNullOrEmpty(compressResult) || string.IsNullOrEmpty(testResult)) { CurrentBackUpState = BackupState.Success; return; } ; LogResult = $"{compressResult}\n{testResult}"; CurrentBackUpState = BackupState.Error; }
public override async Task OnActivateAsync(Guid key) { appId = key; persistence = store.WithSnapshots <BackupState, Guid>(GetType(), key, s => state = s); await ReadAsync(); RecoverAfterRestart(); }
internal Builder WithState(BackupState value) { partitionStatus.BackupPartitionStatusState = value; return(this); }
private void RunBackup() { _backupState = BackupState.Running; labelStatus.Text = "Running backup: " + _backupSavegame; backgroundWorkerTnS.RunWorkerAsync(new Work(JobType.Backup, _backupSavegame)); }
public void BeginEdit() { if (!IsEditing) _editBackup = new BackupState(); }
public async Task OnActivateAsync(Guid appId) { this.appId = appId; persistence = store.WithSnapshots <BackupState, Guid>(GetType(), appId, s => state = s); await ReadAsync(); await CleanupAsync(); }
public void CreateBackup(string enterprisePath, bool useArchiev, string destinationPath, string fileNameFormat = "{name}_{date}", int whaitForBackUp = 1000 * 60 * 60 * 4) { if (CurrentBackUpState != BackupState.Queued) { return; } LogResult = $"Starting backup process for base {BaseName}"; if (CurrentBaseType == BaseType.File && useArchiev) { CreateArchiev(destinationPath, fileNameFormat); return; } var startInfo = new ProcessStartInfo(); string backupFileName; string dumpResultFileName; string logFileName; try { var fileNamesStruct = new FileNamesStruct(fileNameFormat, destinationPath, this); var fileName = fileNamesStruct.FileName; var logDirectory = fileNamesStruct.LogDirectory; if (!Directory.Exists(logDirectory)) { Directory.CreateDirectory(logDirectory); } backupFileName = fileNamesStruct.BackupFileName; logFileName = fileNamesStruct.LogFileName; dumpResultFileName = fileNamesStruct.DumpResultFileName; var commandArgs = $"DESIGNER /IBConnectionString{Path} /DumpIB \"{backupFileName}\" /DumpResult \"{dumpResultFileName}\" /Out \"{logFileName}\""; startInfo.WindowStyle = ProcessWindowStyle.Normal; startInfo.FileName = System.IO.Path.Combine(enterprisePath, "1cv8.exe"); startInfo.RedirectStandardOutput = false; startInfo.RedirectStandardError = false; startInfo.UseShellExecute = true; startInfo.Arguments = commandArgs; } catch (Exception e) { LogResult = "Process ended whith error"; LogResult = e.Message; CurrentBackUpState = BackupState.Error; return; } try { if (CurrentBaseType == BaseType.Server) { SetSheduledJobsStatus(true); } KickAllUsers(); } catch (Exception e) { LogResult = "Error while disconnecting sessions"; LogResult = e.Message; } using (var backupProcess = Process.Start(startInfo)) { if (backupProcess == null) { return; } LogResult = $"Process started, PID: {backupProcess.Id}"; CurrentBackUpState = BackupState.InProgress; while (!backupProcess.HasExited) { try { if (backupProcess.MainWindowHandle != IntPtr.Zero && GetWindowText(backupProcess.MainWindowHandle) != string.Empty) { backupProcess.Kill(); LogResult = "Auth failed"; break; } System.Threading.Thread.Sleep(1000); } catch (Exception e) { // ignored } } //exeProcess.WaitForExit(whaitForBackUp); var exitCode = backupProcess.ExitCode; int dumpResult; try { dumpResult = int.TryParse(File.ReadAllText(dumpResultFileName), out dumpResult) ? dumpResult : -1; } catch (Exception e) { LogResult = e.Message; dumpResult = -2; } if (CurrentBaseType == BaseType.Server) { SetSheduledJobsStatus(false); } if (!File.Exists(backupFileName) || dumpResult != 0 || exitCode != 0) { CurrentBackUpState = BackupState.Error; LogResult = "Process ended whith error"; if (dumpResult != -2) { LogFileName = logFileName; } } else { CurrentBackUpState = BackupState.Success; } } }
/// <summary> /// Helper method to invoke the event /// </summary> /// <param name="state">The state the backup is in</param> internal void InvokeStateChangeEvent(BackupState state) { if (BackupStateChanged != null) BackupStateChanged(state); }
private void MyBackupTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (this.TimerInUse) { return; } this.TimerInUse = true; for (int i = 0; i < MyBackup.MyBackups.Count; i++) { var backup = MyBackup.MyBackups[i]; if (backup.IsEnabled) { var Remaining = GetRemainingTime(backup, out long At); if (Remaining.TotalSeconds <= 0) { string FileName = backup.BackupName + "_" + backup.Database + "_" + DateTime.Now.ToString() + ".bak"; Vars.GiveEveryoneAccessControl(backup.BackupPath); FileName = Vars.RemoveInvalidFileNameChars(FileName); var path = Path.Combine(backup.BackupPath, FileName); var ConnectionString = SQLFunctions.GetConnectionString(backup.Host, backup.Database, backup.Authentication, backup.Username, backup.Password); var backupResult = SQLFunctions.BackupNow(path, ConnectionString); var backupState = new BackupState() { backup = backup, BackupDateTime = DateTime.Now.Ticks, DefaultBackupDateTime = At, FullPath = path, Warning = backupResult != null, }; if (backupResult != null) { backupState.WarningMessage = backupResult.Message; backupState.FullWarning = backupResult.ToString(); } MyBackup.SaveBackupState(backupState); backup.LastBackup = DateTime.Now.Ticks; MyBackup.SaveBackup(backup); } } if (this.MyTreeView.InvokeRequired) { this.MyTreeView.BeginInvoke((MethodInvoker) delegate() { this.RefreshMyTreeView(backup); }); } else { this.RefreshMyTreeView(backup); } } this.TimerInUse = false; }