public static void CreateDemoRequiredFiles() { BackupFiles objBackupFiles; BackupFile objBackupFile; FilesToBackup objFilesToBackup; FileToBackUp objFileToBackup; SingleFileToBackUp objSingleFileToBackup; //Procedure for reading file from tape; Backup files must have a Size, NewFileName, FilePath and StartTapeLocation to be restored objBackupFiles = new BackupFiles(); objBackupFile = new BackupFile { StartTapeLocation = 0, EndTapeLocation = 84673, FilePath = Directory.GetCurrentDirectory() + "\\", FileName = "Test1.txt", Size = 5549095658 }; objBackupFiles.Add(objBackupFile); objBackupFile = new BackupFile { StartTapeLocation = 84673, EndTapeLocation = 84990, FilePath = Directory.GetCurrentDirectory() + "\\", FileName = "Test2.txt", Size = 20764304 }; objBackupFiles.Add(objBackupFile); objBackupFiles.SaveToXMLFile(Directory.GetCurrentDirectory() + "\\", "BackedUpFilesExample.xml"); //Backup files must have a FilePath and FileName in order to be written to the tape; StartTapeLocation is required when writing a single file, //otherwise the app assigns locations as it's backing up multiple files objFilesToBackup = new FilesToBackup(); objFileToBackup = new FileToBackUp { FilePath = Directory.GetCurrentDirectory() + "\\", FileName = "Test1.txt" }; objFilesToBackup.Add(objFileToBackup); objFileToBackup = new FileToBackUp { FilePath = Directory.GetCurrentDirectory() + "\\", FileName = "Test2.txt" }; objFilesToBackup.Add(objFileToBackup); objFilesToBackup.SaveToXMLFile(Directory.GetCurrentDirectory() + "\\", "FilesToBackupExample.xml"); objSingleFileToBackup = new SingleFileToBackUp { StartTapeLocation = 84673, FilePath = Directory.GetCurrentDirectory() + "\\", FileName = "Test2.txt" }; objSingleFileToBackup.Serialize(Directory.GetCurrentDirectory() + "\\FileToBackupExample.xml"); }
private void BindGridView() { string backupDirectory = HostingEnvironment.MapPath(this.server.DatabaseBackupDirectory); if (backupDirectory != null) { if (Directory.Exists(backupDirectory)) { DirectoryInfo directory = new DirectoryInfo(backupDirectory); Collection<BackupFile> files = new Collection<BackupFile>(); foreach (FileInfo fileInfo in directory.GetFiles("*.zip")) { if (fileInfo != null) { BackupFile file = new BackupFile(); string downloadPath = this.ResolveUrl(Path.Combine(this.server.DatabaseBackupDirectory, fileInfo.Name)); file.Name = string.Format(CultureInfo.InvariantCulture, "<a href='{0}' target='_blank'>{1}</a>", downloadPath, fileInfo.Name); file.CreatedOn = fileInfo.CreationTime; file.LastWrittenOn = fileInfo.LastWriteTime; file.LastAccessedOn = fileInfo.LastAccessTime; files.Add(file); } } this.grid.RowDataBound += this.Grid_RowDataBound; this.grid.DataSource = files; this.grid.DataBind(); } } }
private void ButtonEdit_Click(object sender, EventArgs e) { int backupFileIndex = GridViewBackupFiles.FocusedRowHandle; BackupFile backupFile = MainWindow.BackupFiles.BackupFiles[backupFileIndex]; BackupFile newBackupFile = DialogExtensions.ShowBackupFileDetails(this, backupFile); if (newBackupFile != null) { MainWindow.BackupFiles.UpdateBackupFile(backupFileIndex, newBackupFile); } LoadBackupFiles(); }
public void CanRenameGenericWhenIllegalName() { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings, nameof(DummySerializable)); file.CreateFileOnDisk(); if (repository.Settings.BackupSettings != null) { BackupFile.CreateFor(file, repository.Settings.BackupSettings).CreateFileOnDisk(); } var exception = Assert.Throws <ArgumentException>(() => repository.CanRename <DummySerializable>("NewName<>")); Assert.AreEqual("Illegal characters in path.", exception !.Message); }
public void CreateBackup() { string fn = Path.GetTempFileName(); string backupDir = Path.GetRandomFileName(); Directory.CreateDirectory(backupDir); DateTime dt = new DateTime(2015, 11, 23, 9, 31, 00); File.SetLastWriteTime(fn, dt); BackupFile bf = BackupFile.CreateBackup(fn, backupDir); Assert.IsNotNull(bf); Assert.AreEqual(dt, bf.TimeStamp.DateTime); Directory.Delete(backupDir, true); File.Delete(fn); }
protected void btnUpload_Click(object sender, EventArgs e) { DeletePreviouslyUploadedFile(); string filePath = SaveFileToTempDirectory(fuRestoreFile); IBackupFile backupFile = new BackupFile(filePath); ValidateRestoreFile(backupFile); ConfigureBackupFileInfo(backupFile); if (!backupFile.IsValid && File.Exists(filePath)) { File.Delete(filePath); } }
public static async Task <int> ExecuteAsync( BackupFile backupFile, IBackupFileService backupFileService, string filePath, int[] tagIds) { if (backupFile == null) { return(0); } var tagIdsHash = tagIds.ToHashSet(); var result = await Task.Run(() => { var tagMapIdsToRemove = new HashSet <int>(); var noteIdsToRemove = new HashSet <int>(); var userMarksToRemove = new HashSet <int>(); foreach (var tagMap in backupFile.Database.TagMaps) { if (tagIdsHash.Contains(tagMap.TagId) && tagMap.NoteId != null && tagMap.NoteId > 0) { tagMapIdsToRemove.Add(tagMap.TagMapId); noteIdsToRemove.Add(tagMap.NoteId.Value); var note = backupFile.Database.FindNote(tagMap.NoteId.Value); if (note?.UserMarkId != null) { userMarksToRemove.Add(note.UserMarkId.Value); } } } backupFile.Database.TagMaps.RemoveAll(x => tagMapIdsToRemove.Contains(x.TagMapId)); backupFile.Database.Notes.RemoveAll(x => noteIdsToRemove.Contains(x.NoteId)); backupFile.Database.UserMarks.RemoveAll(x => userMarksToRemove.Contains(x.UserMarkId)); // Note that redundant block ranges are cleaned automatically by Cleaner. if (noteIdsToRemove.Count > 0 || tagMapIdsToRemove.Count > 0) { backupFileService.WriteNewDatabaseWithClean(backupFile, filePath, filePath); } return(noteIdsToRemove.Count); }); return(result); }
public async Task GetRemoteFileTest() { var serverCommunicator = new Communicator(); var server = new RemoteFileServer(serverCommunicator, PathToStorage, PathToServerTempStorage); // Path.GetTempPath()); server.StartServer(); var clientCommunicator = new Communicator(); var client = new RemoteStorageLocation(clientCommunicator, "192.168.1.6", PathToClientTempStorage); await client.Connect(); var file = new BackupFile(FileToStorePath); var hash = Hasher.GetFileHash(file); await client.StoreFile(file, hash); var filePath = await client.GetFile(hash); }
protected void uploadButton_Click(object sender, EventArgs e) { DeletePreviouslyUploadedFile(); FileUpload uploadedFile = (FileUpload)phUpload.FindControl("fuUpload1"); string filePath = SaveFileToTempDirectory(uploadedFile); IBackupFile backupFile = new BackupFile(filePath); ValidateRestoreFile(backupFile); ConfigureBackupFileInfo(backupFile); if (!backupFile.IsValid) { File.Delete(filePath); } }
/// <inheritdoc /> public BackupFile ImportBibleNotes( BackupFile originalBackupFile, IEnumerable <BibleNote> notes, string bibleKeySymbol, int mepsLanguageId) { ProgressMessage("Importing Bible notes"); var newManifest = UpdateManifest(originalBackupFile.Manifest); var notesImporter = new NotesImporter(originalBackupFile.Database, bibleKeySymbol, mepsLanguageId); notesImporter.Import(notes); return(new BackupFile { Manifest = newManifest, Database = originalBackupFile.Database }); }
/// <summary> /// </summary> /// <param name="backupFile"></param> public void BackupGameFile(BackupFile backupFile) { try { FtpExtensions.DownloadFile(backupFile.LocalPath, backupFile.InstallPath); _ = DarkMessageBox.Show(this, $"Successfully backed up file {backupFile.FileName} from {backupFile.InstallPath}.", "Success", MessageBoxIcon.Information); } catch (Exception ex) { Program.Log.Error($"Unable to backup game file. Error: {ex.Message}", ex); _ = DarkMessageBox.Show(this, "There was a problem downloading the file. Make sure the file exists on your console.", "Error", MessageBoxIcon.Error); } }
public void RenameGenericOverwrite(bool overWrite) { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings, nameof(DummySerializable)); var softDelete = file.SoftDeleteFile(); file.CreateFileOnDisk("file"); softDelete.CreateFileOnDisk("file soft delete"); file.WithNewName("NewName", repository.Settings).CreateFileOnDisk("existing new name"); file.WithNewName("NewName", repository.Settings).SoftDeleteFile().CreateFileOnDisk("existing soft delete new name"); if (repository.Settings.BackupSettings != null) { BackupFile.CreateFor(file, repository.Settings.BackupSettings).CreateFileOnDisk("backup"); BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings).CreateFileOnDisk("existing backup new name"); } if (overWrite) { repository.Rename <DummySerializable>("NewName", true); AssertFile.Exists(false, file); AssertFile.Exists(false, softDelete); Assert.AreEqual("file", file.WithNewName("NewName", repository.Settings).ReadAllText()); Assert.AreEqual("file soft delete", file.WithNewName("NewName", repository.Settings).SoftDeleteFile().ReadAllText()); if (repository.Settings.BackupSettings != null) { AssertFile.Exists(false, BackupFile.CreateFor(file, repository.Settings.BackupSettings)); Assert.AreEqual("backup", BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings).ReadAllText()); } } else { _ = Assert.Throws <InvalidOperationException>(() => repository.Rename <DummySerializable>("NewName", false)); Assert.AreEqual("file", file.ReadAllText()); Assert.AreEqual("file soft delete", softDelete.ReadAllText()); Assert.AreEqual("existing new name", file.WithNewName("NewName", repository.Settings).ReadAllText()); Assert.AreEqual("existing soft delete new name", file.WithNewName("NewName", repository.Settings).SoftDeleteFile().ReadAllText()); if (repository.Settings.BackupSettings != null) { Assert.AreEqual("backup", BackupFile.CreateFor(file, repository.Settings.BackupSettings).ReadAllText()); Assert.AreEqual("existing backup new name", BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings).ReadAllText()); } } }
internal override IEnumerable <BackupFile> Load(string directory) { var files = new List <BackupFile>(); // an oracle server will only have one database // the backup of this database will contain 3 files // to get all 3 files into one zip, we create a seperate directory var file = new BackupFile(Path.Combine(directory, Guid.NewGuid().ToString())); file.Name = _host; Directory.CreateDirectory(file.Path); // save script file for rman var filePathCmd = Path.Combine(directory, file.Identifier + "_cmd"); File.WriteAllLines(filePathCmd, this.GetCmdContent(file.Path, file.Name)); // format args for rman var args = new List <KeyValuePair <string, string> >(); args.Add(new KeyValuePair <string, string>("target", string.Format("{0}/{1}@{2}", _user, _password != null && _password.Length > 0 ? _password : "******", _host))); args.Add(new KeyValuePair <string, string>("cmdfile", filePathCmd)); var argsString = string.Empty; foreach (var arg in args) { argsString += " " + arg.Key + " " + arg.Value; } // execute rman var didSucceed = this.DumpExecute(argsString, file.Path, false); if (didSucceed && Directory.GetFiles(file.Path).Length == 3) { file.CreatedOn = DateTime.UtcNow; files.Add(file); } _logger.Log(_config.Name, LoggerPriorities.Info, "Created {0} backup{1:'s';'s';''}.", files.Count, files.Count - 1); return(files); }
/// <summary> /// Deletes a single file revision from the Azure cloud storage provider. /// </summary> /// <param name="file"><c>BackupFile</c></param> /// <param name="sourceLocation"><c>SourceLocation</c></param> /// <param name="directory"><c>DirectoryMapItem</c></param> /// <param name="cancelToken">The canellation token.</param> public async Task DeleteFileRevisionAsync(BackupFile file, SourceLocation sourceLocation, DirectoryMapItem directory, CancellationToken cancelToken) { int maxAttempts = 3; var sasBlobUri = ProviderUtilities.GetFileUri(AzureStorage.Credentials.AccountName, directory.GetRemoteContainerName(StorageProviderTypes.Azure), file.GetRemoteFileName(StorageProviderTypes.Azure)); for (int currentAttempt = 1; currentAttempt <= maxAttempts; currentAttempt++) { cancelToken.ThrowIfCancellationRequested(); try { CloudBlockBlob blob = new CloudBlockBlob(new Uri(sasBlobUri), AzureStorage.Credentials); await blob.DeleteIfExistsAsync(cancelToken).ConfigureAwait(false); Logger.WriteTraceMessage("File revision successfully cleaned up."); break; } catch (StorageException ex) { if (ex.InnerException != null && ex.InnerException is TimeoutException) { if (currentAttempt == maxAttempts) { // retries exhausted throw; } // special case handling: // a windows azure storage timeout has occurred. give it a minute and try again. Logger.WriteTraceMessage("An Azure storage timeout exception has occurred while trying to check (or delete) the blob. Waiting a minute before trying again."); await Task.Delay(TimeSpan.FromSeconds(60), cancelToken).ConfigureAwait(false); } else { throw; } } } }
private void GridViewBackupFiles_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) { switch (GridViewBackupFiles.SelectedRowsCount) { case > 0: try { BackupFile backupFile = MainWindow.BackupFiles.BackupFiles[GridViewBackupFiles.FocusedRowHandle]; Category category = MainWindow.Database.CategoriesData.GetCategoryById(backupFile.CategoryId); long fileSize = File.Exists(backupFile.LocalPath) ? new FileInfo(backupFile.LocalPath).Length : 0; LabelGameTitle.Text = category.Title; LabelFileName.Text = backupFile.FileName; LabelFileSize.Text = File.Exists(backupFile.LocalPath) ? MainWindow.Settings.UseFormattedFileSizes ? fileSize.Bytes().Humanize() : fileSize.ToString("{0:n}") + " bytes" : "No File Exists"; LabelCreatedOn.Text = backupFile.CreatedDate.ToLocalTime().ToString(); LabelLocalPath.Text = backupFile.LocalPath; LabelInstallPath.Text = backupFile.InstallPath; if (!File.Exists(backupFile.LocalPath)) { XtraMessageBox.Show( $"Local file: {backupFile.FileName} for game: {category.Title} can't be found at path: {backupFile.LocalPath}.\n\nIf you have moved this file then edit the backup and choose the locate the file, otherwise re-install your game update and backup the orginal game file again.", "No Local File"); } } catch { // Will throw index out of range if deleting the last item } break; } ButtonEdit.Enabled = GridViewBackupFiles.SelectedRowsCount > 0; ButtonDelete.Enabled = GridViewBackupFiles.SelectedRowsCount > 0; ButtonDeleteAll.Enabled = GridViewBackupFiles.SelectedRowsCount > 0; ButtonBackupFile.Enabled = GridViewBackupFiles.SelectedRowsCount > 0 && MainWindow.IsConsoleConnected; ButtonRestoreFile.Enabled = GridViewBackupFiles.SelectedRowsCount > 0 && MainWindow.IsConsoleConnected; }
public async Task StoreRemoteFileTest() { var serverCommunicator = new Communicator(); var server = new RemoteFileServer(serverCommunicator, PathToStorage, PathToServerTempStorage); // Path.GetTempPath()); server.StartServer(); var clientCommunicator = new Communicator(13001, new NetworkClient("Test", new TcpClient()), new NetworkListener()); var client = new RemoteStorageLocation(clientCommunicator, "192.168.1.6", PathToClientTempStorage); await client.Connect(); var file = new BackupFile(FileToStorePath); var hash = Hasher.GetFileHash(file); var storeReslts = await client.StoreFile(file, hash); Assert.IsTrue(storeReslts); }
public void CloseBackupFile(string name, RecoveryFileState state) { //M_TODO: // Add timeout interval for file writing, incase the data is not being consumed and timeout span has been reached, break the loop and DIE!!! try { // TimeSpan timeSpan BackupFile file = _activeContext.GetBackupFile(name); file.FileHeader.State = state; int elapsed = 0; // if file not already flushed if (!file.HeaderFlushed) { while (!_activeContext.SharedQueue.Consumed) { // wait till all data has been consumed and written } if (_activeContext.SharedQueue.Consumed) { if (file.SaveHeader()) { if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsInfoEnabled) { LoggerManager.Instance.RecoveryLogger.Info("RecoveryPersistenceManager.CloseBackupFile()", file.Name + " closing"); } file.Close(); } else { throw new Exception("Unable to write data"); } } } } catch (Exception exp) { if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled) { LoggerManager.Instance.RecoveryLogger.Error("RecoveryPersistenceManager.CloseBackupFile()", exp.ToString()); } } }
public static void GetRestoreFileFor() { var settings = new BackupSettings(Directory.FullName, BackupSettings.DefaultExtension, BackupSettings.DefaultTimeStampFormat, 1, 1); var file = CreateFile(); var backup = CreateBackupFile(); file.CreateFileOnDisk(); var backupOneMinuteOld = backup.WithTimeStamp(DateTime.Now.AddMinutes(-1), settings); backupOneMinuteOld.CreateFileOnDisk(); backup.WithTimeStamp(DateTime.Now.AddHours(-1), settings).CreateFileOnDisk(); backup.WithTimeStamp(DateTime.Now.AddDays(-1), settings).CreateFileOnDisk(); backup.WithTimeStamp(DateTime.Now.AddMonths(-1), settings).CreateFileOnDisk(); backup.WithTimeStamp(DateTime.Now.AddYears(-1), settings).CreateFileOnDisk(); var restore = BackupFile.GetRestoreFileFor(file, settings); Assert.AreEqual(backupOneMinuteOld.FullName, restore !.FullName); }
public void Test2() { var file50A = new BackupFile("/Users/egorius/Desktop/Homework/OOP/Labs/Lab4/Lab4/File50A.txt"); var file50B = new BackupFile("/Users/egorius/Desktop/Homework/OOP/Labs/Lab4/Lab4/File50B.txt"); var backup = new Backup(new List <BackupFile>() { file50A, file50B }); backup.MakeFullRestorePoint(); Assert.AreEqual(2, backup.RestorePoints.Count); Assert.AreEqual(200, backup.Size); backup.AddLimit(new MemoryLimit(150)); backup.PushItToTheLimit(); Assert.AreEqual(1, backup.RestorePoints.Count); }
public ActionResult Index() { var dir = new DirectoryInfo(backupFolder); FileInfo[] files = dir.GetFiles("*.bak"); List <BackupFile> items = new List <BackupFile>(); foreach (var file in files) { BackupFile backupFile = new BackupFile { FileName = file.Name, CreatedTime = file.CreationTime }; items.Add(backupFile); } ViewBag.Message = TempData["Message"]?.ToString(); return(View(items)); }
/// <summary> /// Sends the transfer payload to the target providers. /// </summary> /// <param name="file"></param> /// <param name="source"></param> /// <param name="payload"></param> /// <param name="cancelToken"></param> /// <returns></returns> private async Task SendTransferPayloadToFileTargetsAsync(BackupFile file, SourceLocation source, TransferPayload payload, CancellationToken cancelToken) { var directory = await Database.GetDirectoryMapItemAsync(file.Directory).ConfigureAwait(false); foreach (var providerName in payload.DestinationProviders) { var destination = Providers[providerName]; try { // upload this chunk to the destination cloud provider. // note: the provider implementation will automatically handle retries of transient issues. await destination.UploadFileBlockAsync(file, source, directory, payload.Data, (int)payload.CurrentBlockNumber, (int)payload.TotalBlocks, cancelToken).ConfigureAwait(false); // flag the chunk as sent in the file status. file.SetBlockAsSent((int)payload.CurrentBlockNumber, providerName); } catch (OperationCanceledException) { // cancellation was requested. // bubble up to the next level. throw; } catch (Exception ex) { Logger.WriteTraceError("An error occurred during a file transfer.", ex, Logger.GenerateFullContextStackTrace(), InstanceID); file.SetProviderToFailed(providerName); // sets the error message/stack trace await Database.SetBackupFileAsFailedAsync(file, ex.ToString()).ConfigureAwait(false); await Database.RemoveFileFromBackupQueueAsync(file).ConfigureAwait(false); } finally { // commit the status changes to the local state database. await Database.UpdateBackupFileCopyStateAsync(file).ConfigureAwait(false); } } }
internal override IEnumerable <BackupFile> Load(string directory) { if (_included == null || _included.Count == 0) { _logger.Log(_config.Name, LoggerPriorities.Error, "No includes are configured. This provider will not work without includes."); return(null); } var environmentVars = this.GetEnvironmentVars(); if (environmentVars == null) { _logger.Log(_config.Name, LoggerPriorities.Error, "Could not initialize backup environment."); return(null); } var files = new List <BackupFile>(); foreach (var database in _included) { var file = new BackupFile(directory, database + ".backup"); // db2.exe needs a directory Directory.CreateDirectory(file.Path); var argsForDatabase = string.Format("BACKUP DATABASE {0} to {1} WITHOUT PROMPTING", database, file.Path); var didSucceed = this.DumpExecute(argsForDatabase, file.Path, false, environmentVars); if (didSucceed && Directory.Exists(file.Path)) { file.CreatedOn = DateTime.UtcNow; files.Add(file); } } _logger.Log(_config.Name, LoggerPriorities.Info, "Created {0} backup{1:'s';'s';''}.", files.Count, files.Count - 1); return(files); }
/// <summary> /// Uploads a file block with retry logic. /// </summary> /// <param name="file">The backup file information.</param> /// <param name="blob">The cloud block blob reference.</param> /// <param name="data">The block of data to upload.</param> /// <param name="currentBlockIndex">The block number to upload.</param> /// <param name="cancelToken">The cancellation token.</param> /// <returns></returns> private async Task UploadFileBlockWithRetryAsync(BackupFile file, CloudBlockBlob blob, byte[] data, int currentBlockIndex, CancellationToken cancelToken) { using (var stream = new MemoryStream(data)) { var encodedBlockIdString = ProviderUtilities.GenerateBlockIdentifierBase64String(file.FileID, currentBlockIndex); int maxAttempts = 3; for (int currentAttempt = 1; currentAttempt <= maxAttempts; currentAttempt++) { cancelToken.ThrowIfCancellationRequested(); try { await blob.PutBlockAsync(encodedBlockIdString, stream, null, null, WriteBlockRequestOptions, null, cancelToken).ConfigureAwait(false); break; } catch (StorageException ex) { if (ex.InnerException != null && ex.InnerException is TimeoutException) { if (currentAttempt == maxAttempts) { // retries exhausted throw; } // common scenario: // a windows azure storage timeout has occurred. give it a minute and try again. Logger.WriteTraceMessage("An Azure storage timeout exception has occurred while trying to upload the file block. Waiting a minute before trying again."); await Task.Delay(TimeSpan.FromSeconds(60), cancelToken).ConfigureAwait(false); } else { throw; } } } } }
/// <summary> /// Commits a list of committed and uncommitted blocks to a block blob. /// </summary> /// <param name="file"></param> /// <param name="currentBlockIndex"></param> /// <param name="blob"></param> /// <param name="cancelToken"></param> /// <returns></returns> private async Task CommitBlocksWithRetryAsync(BackupFile file, int currentBlockIndex, CloudBlockBlob blob, CancellationToken cancelToken) { int maxAttempts = 3; for (int currentAttempt = 1; currentAttempt <= maxAttempts; currentAttempt++) { cancelToken.ThrowIfCancellationRequested(); try { // after the block has been uploaded it is in an uncommitted state. // commit this block (plus any previously committed blocks). var blockListToCommit = ProviderUtilities.GenerateListOfBlocksToCommit(file.FileID, currentBlockIndex); await blob.PutBlockListAsync(blockListToCommit, null, WriteBlockListRequestOptions, null).ConfigureAwait(false); break; } catch (StorageException ex) { if (ex.InnerException != null && ex.InnerException is TimeoutException) { if (currentAttempt == maxAttempts) { // retries exhausted throw; } // special case handling: // a windows azure storage timeout has occurred. give it a minute and try again. Logger.WriteTraceMessage("An Azure storage timeout exception has occurred while trying to commit the block list. Waiting a minute before trying again."); await Task.Delay(TimeSpan.FromSeconds(60), cancelToken).ConfigureAwait(false); } else { throw; } } } }
/// <summary> /// Do a backup revert /// </summary> /// <param name="game"></param> public void ExecuteBackup(HandlerData game) { // we didnt backup anything if (backupFiles == null) { return; } string appData = GameManager.GetAppDataPath(); string gamePath = Path.Combine(appData, game.GameID); for (int i = 0; i < backupFiles.Count; i++) { BackupFile bkp = backupFiles[i]; if (File.Exists(bkp.BackupPath)) { File.Delete(bkp.Source); File.Move(bkp.BackupPath, bkp.Source); } } }
public void Test3() { var fileA = new BackupFile("/Users/egorius/Desktop/Homework/OOP/Labs/Lab4/Lab4/FileB.txt"); var fileB = new BackupFile("/Users/egorius/Desktop/Homework/OOP/Labs/Lab4/Lab4/FileA.txt"); var fileC = new BackupFile("/Users/egorius/Desktop/Homework/OOP/Labs/Lab4/Lab4/FileA.txt"); var backup = new Backup(new List <BackupFile>() { fileA, fileB }); // 2 files, 1 RestorePoint backup.Add(fileC); backup.MakeDeltaRestorePoint(); // 3 files, 2 RestorePoint Assert.AreEqual(2, backup.RestorePoints.Count); backup.AddLimit(new TimeLimit(DateTime.Now)); backup.MakeFullRestorePoint();// 3 files, 1 RestorePoint Assert.AreEqual(1, backup.RestorePoints.Count); }
public void Test1() { var fileA = new BackupFile("/Users/egorius/Desktop/Homework/OOP/Labs/Lab4/Lab4/FileB.txt"); var fileB = new BackupFile("/Users/egorius/Desktop/Homework/OOP/Labs/Lab4/Lab4/FileA.txt"); var backup = new Backup(); backup.Add(fileA); backup.Add(fileB); backup.MakeFullRestorePoint(); // 2 BackupFiles, 1 RestorePoint Assert.AreEqual(2, backup.RestorePoints[0].FilesCount); backup.MakeFullRestorePoint(); backup.AddLimit(new NumberLimit(1)); backup.PushItToTheLimit(); Assert.AreEqual(1, backup.RestorePoints.Count); }
public static async Task ExecuteAsync( BackupFile backupFile, IBackupFileService backupFileService, string backupFilePath, string importFilePath, ImportBibleNotesParams options) { await Task.Run(() => { var file = new BibleNotesFile(importFilePath); backupFileService.ImportBibleNotes( backupFile, file.GetNotes(), file.GetBibleKeySymbol(), file.GetMepsLanguageId(), options); backupFileService.WriteNewDatabase(backupFile, backupFilePath, backupFilePath); }); }
public void CanRenameGenericWouldOverwrite(bool fileNewNameExists, bool backupNewNameExists) { var repository = this.CreateRepository(); var file = CreateTestFile(repository.Settings, nameof(DummySerializable)); file.CreateFileOnDisk(); if (fileNewNameExists) { file.WithNewName("NewName", repository.Settings).CreateFileOnDisk(); Assert.AreEqual(false, repository.CanRename <DummySerializable>("NewName")); } if (backupNewNameExists && repository.Settings.BackupSettings != null) { var backup = BackupFile.CreateFor(file, repository.Settings.BackupSettings); backup.CreateFileOnDisk(); BackupFile.CreateFor(file.WithNewName("NewName", repository.Settings), repository.Settings.BackupSettings).CreateFileOnDisk(); Assert.AreEqual(false, repository.CanRename <DummySerializable>("NewName")); } }
public static Task ExecuteAsync( List<Note> notes, IRedactService redactService, BackupFile backupFile, IBackupFileService backupFileService, string filePath) { return Task.Run(() => { foreach (var note in notes) { if (!string.IsNullOrEmpty(note.Title)) { note.Title = redactService.GetNoteTitle(note.Title.Length); } if (!string.IsNullOrEmpty(note.Content)) { note.Content = redactService.GenerateNoteContent(note.Content.Length); } } backupFileService.WriteNewDatabase(backupFile, filePath, filePath); }); }
protected void Upload1_Uploaded(object sender, UploadUploadedEventArgs e) { //string[] importOptions = Upload1.CallbackParameter.Split(new char[] { '|' }); //bool importMembership = Convert.ToBoolean(importOptions[0]); //bool importGalleryData = Convert.ToBoolean(importOptions[1]); DeletePreviouslyUploadedFile(); string filePath = SaveFileToTempDirectory(e.UploadedFiles[0]); IBackupFile backupFile = new BackupFile(filePath); ValidateRestoreFile(backupFile); ConfigureBackupFileInfo(backupFile); if (!backupFile.IsValid) { File.Delete(filePath); } }
/// <inheritdoc /> public int RemoveUnderliningByColour(BackupFile backup, int[]?colorIndexes, bool removeAssociatedNotes) { if (backup == null) { throw new ArgumentNullException(nameof(backup)); } colorIndexes ??= Array.Empty <int>(); var userMarkIdsToRemove = new HashSet <int>(); foreach (var mark in backup.Database.UserMarks) { if (colorIndexes.Contains(mark.ColorIndex)) { userMarkIdsToRemove.Add(mark.UserMarkId); } } return(RemoveUnderlining(backup.Database, userMarkIdsToRemove, removeAssociatedNotes)); }
private void Restore() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = Files.BackupFileFilter; dialog.CheckFileExists = true; dialog.Multiselect = false; dialog.Title = Resources.RestoreBackupDialogTitle; if (dialog.ShowDialog() == DialogResult.OK) { try { BackupFile backup = new BackupFile(this.controller.Status.DataPath, dialog.FileName); backup.BeginExtract(); BackupProgressDialog backupDialog = new BackupProgressDialog(); backupDialog.SetProgress(backup.FileName, backup.Progress); backupDialog.Show(); while (!backup.Complete) { backupDialog.SetProgress(backup.FileName, backup.Progress); Application.DoEvents(); Thread.Sleep(1); } backupDialog.Close(); Status.TextStatusDialog.ShowInfo(this.controller, this); this.controller.LoadCertificates(); Status.TextStatusDialog.HideInfo(); LoadCertificates(); MessageForm.Show(Resources.RestoreBackupDone, Resources.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exception) { Error.ErrorDialog.ShowError(exception); } } }
private void Backup() { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = Files.BackupFileFilter; dialog.CheckPathExists = true; dialog.Title = Resources.SaveBackupDialogTitle; if (dialog.ShowDialog() == DialogResult.OK) { try { BackupFile backup = new BackupFile(this.controller.Status.DataPath, dialog.FileName); backup.BeginCreate(); BackupProgressDialog backupDialog = new BackupProgressDialog(); backupDialog.SetProgress(backup.FileName, backup.Progress); backupDialog.Show(); while (!backup.Complete) { backupDialog.SetProgress(backup.FileName, backup.Progress); Application.DoEvents(); Thread.Sleep(1); } backupDialog.Close(); MessageForm.Show(Resources.SaveBackupDone, Resources.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exception) { Error.ErrorDialog.ShowError(exception); } } }
private void Restore() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = Resources.ChooseCertificateRestoreDialog; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dialog.CheckPathExists = true; dialog.CheckFileExists = true; dialog.Filter = Files.BackupFileFilter; if (dialog.ShowDialog() == DialogResult.OK) { BackupFile backup = new BackupFile(Status.DataPath, dialog.FileName); backup.BeginExtract(); while (!backup.Complete) { Status.SetProgress(Resources.ChooseCertificateRestoreRunning, backup.Progress); Thread.Sleep(10); } if (backup.Exception == null) { Status.SetMessage(Resources.ChooseCertificateRestoreSuccess, MessageType.Success); Begin(); } else { Status.SetMessage(Resources.ChooseCertificateRestoreFailed + backup.Exception.Message, MessageType.Error); } } }
public void ReadFileFromTape(BackupFile objBackupFile) { BackupFiles objBackupFiles; objBackupFiles = new BackupFiles(); objBackupFiles.Add(objBackupFile); ReadFilesFromTape(objBackupFiles); }
public void WriteFileToTape(BackupFile objBackupFile) { BackupFiles objBackupFiles = new BackupFiles(); objBackupFiles.Add(objBackupFile); WriteFilesToTape(objBackupFiles, true); }
private static void BackupSingleFile(string strFileToBackupFilePathAndName) { SingleFileToBackUp objSingleFileToBackup; //BackupFiles objBackupFiles; BackupFile objBackupFile; try { using (StreamWriter w = File.CreateText("log.txt")) { Log(string.Format("Backup Operation Started at {0}", DateTime.Now), w); // Close the writer and underlying file. w.Close(); } BackupFileList = new BackupFiles(); objSingleFileToBackup = SingleFileToBackUp.DeSerialize(strFileToBackupFilePathAndName); objBackupFile = new BackupFile { FileName = objSingleFileToBackup.FileName, FilePath = objSingleFileToBackup.FilePath, StartTapeLocation = objSingleFileToBackup.StartTapeLocation }; Backup.WriteFileToTape(objBackupFile); BackupFileList.Add(objBackupFile); BackupFileList.SaveToXMLFile(Directory.GetCurrentDirectory() + "\\", "BackedUpFile.xml"); using (StreamWriter w = File.AppendText("log.txt")) { Log(string.Format("Backup Operation Ended at {0}", DateTime.Now), w); // Close the writer and underlying file. w.Close(); } } catch (Exception objEx) { using (StreamWriter w = File.AppendText("log.txt")) { Log(string.Format("Error {0}", objEx.ToString()), w); // Close the writer and underlying file. w.Close(); } } }