public bool RunBackup() { if (!BackupCanBePerformed()) { return(false); } var details = new BackupDetails { Name = "Full Backup", BackupDate = DateTime.Now }; var directory = Path.Combine(_settings.TempDirectory, Guid.NewGuid().ToString()); PerformBackup(directory); var archive = Path.Combine(_settings.TempDirectory, string.Format("{0}.7z", DateTime.Now.Ticks)); _logger.Information(string.Format("Compressing and Encrypting Archive into {0}..", archive)); _compressor.CompressDataInToFile(directory, _settings.Password, archive); MoveArchiveIntoStorage(details, archive); RemoveArchive(archive); RemoveExpiredBackups(); Directory.Delete(_settings.TempDirectory, true); return(true); }
/// <summary> /// The get backup clients. /// </summary> /// <param name="serverId"> /// The server id. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <IEnumerable <BackupClientDetailsType> > GetBackupClients(string serverId) { BackupDetails details = await _apiClient.GetAsync <BackupDetails>(ApiUris.GetBackupDetails(_apiClient.OrganizationId, serverId)); return(details.backupClient); }
private IEnumerable <BackupDetails> GetAll() { // Common Prefix == Directory var files = _service.ListAllObjects(_settings.Bucket, string.Format("{0}/", _settings.Prefix)).Where(s => s as CommonPrefix == null && !string.IsNullOrWhiteSpace(s.Name)).ToList(); return(files.Select(f => BackupDetails.ParseFromBackupFile(f.Name)).ToList()); }
/// <summary> /// The get backup clients. /// </summary> /// <param name="serverId"> /// The server id. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <IEnumerable <BackupClientDetailsType> > GetBackupClients(string serverId) { Contract.Requires(!string.IsNullOrWhiteSpace(serverId), "Server id must not be null or empty"); BackupDetails details = await _apiClient.GetAsync <BackupDetails>(ApiUris.GetBackupDetails(_apiClient.OrganizationId, serverId)); return(details.backupClient); }
public IActionResult Index() { var model = new SearchViewModel(); model.BackupDetails = BackupDetails.List(); return(View(model)); }
public IActionResult Delete(string id) { var storedBackupDetails = BackupDetails.StoredBackupDetails().Exclude(id); storedBackupDetails.Save(); return(RedirectToAction("Index")); }
public void ArchiveBackup(BackupDetails details, string fileName) { if (!Directory.Exists(_settings.BackupDirectory)) { Directory.CreateDirectory(_settings.BackupDirectory); } var path = Path.Combine(_settings.BackupDirectory, details.GenerateFileName()); File.Copy(fileName, path, true); }
public void SaveTest() { var testList = backupDetailsTestList; var fileName = "backup_details_test.json"; testList.Save(fileName); var savedList = BackupDetails.StoredBackupDetails(fileName); Assert.Equal(testList, savedList); }
public void Validate_SourceFoldersAndDestFolderAreEmpty_ReturnsFalse() { // Arrange var backupDetails = new BackupDetails(); // Act var result = backupDetails.Validate(new WindowsDialogService()); // Assert Assert.IsFalse(result); }
protected override IActionResult DoAPIAction() { string result = APICall(); result = JsonConvert.DeserializeObject(result).ToString(); var vm = SetMessage(result); var model = new SearchViewModel(); model.BackupDetails = BackupDetails.List(); model.MessageViewModel = vm; return(View("Index", model)); }
public void Validate_SourceFoldersIsEmpty_ReturnsFalse() { // Arrange var backupDetails = new BackupDetails { DestFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; // Act var result = backupDetails.Validate(new WindowsDialogService()); // Assert Assert.IsFalse(result); }
private object[] BackupDetailsArgs(string id) { var backupDetailsList = new List <BackupDetail>(); if (string.IsNullOrEmpty(id)) { backupDetailsList = BackupDetails.StoredBackupDetails(); } else { backupDetailsList.Add(BackupDetails.StoredBackupDetails().Get(id)); } return(new object[] { backupDetailsList }); }
public void Validate_DestFolderIsEmpty_ReturnsFalse() { // Arrange var backupDetails = new BackupDetails { SourceFolders = new ObservableCollection <SourceFolder> { new SourceFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) } }; // Act var result = backupDetails.Validate(new WindowsDialogService()); // Assert Assert.IsFalse(result); }
private void MoveArchiveIntoStorage(BackupDetails details, string archive) { _logger.Information("Moving Archive into Storage."); foreach (var storageSource in _storageSource) { if (!storageSource.Enabled) { _logger.Information(string.Format("Storage Source '{0}' is disabled.. skipping..", storageSource.Name)); continue; } _logger.Information(string.Format("Uploading to {0}", storageSource.Name)); storageSource.ArchiveBackup(details, archive); } _logger.Information("Completed Uploading Data."); }
public BackupDetails GetDetails() { if (!File.Exists(DATA_PATH)) { File.Create(DATA_PATH).Close(); } string serializedDetails = File.ReadAllText(DATA_PATH); BackupDetails details = JsonConvert.DeserializeObject <BackupDetails>(serializedDetails); if (details == null) { return(new BackupDetails()); } return(details); }
public IEnumerable <BackupDetails> RemoveOldBackups() { var files = Directory.EnumerateFiles(_settings.BackupDirectory, "*.backup"); var details = files.Select(f => BackupDetails.ParseFromBackupFile(f.Replace(_settings.BackupDirectory, string.Empty))).Where(f => f != null).OrderBy(f => f.BackupDate).ToList(); if (_settings.NumberOfBackupsToKeep >= details.Count) { return(null); } var filesToDelete = details.Take(details.Count - _settings.NumberOfBackupsToKeep).ToList(); foreach (var fileToDelete in filesToDelete) { File.Delete(Path.Combine(_settings.BackupDirectory, fileToDelete.GenerateFileName())); } return(filesToDelete); }
public bool RunBackup() { if (!BackupCanBePerformed()) return false; var details = new BackupDetails { Name = "Full Backup", BackupDate = DateTime.Now }; var directory = Path.Combine(_settings.TempDirectory, Guid.NewGuid().ToString()); PerformBackup(directory); var archive = Path.Combine(_settings.TempDirectory, string.Format("{0}.7z", DateTime.Now.Ticks)); _logger.Information(string.Format("Compressing and Encrypting Archive into {0}..", archive)); _compressor.CompressDataInToFile(directory, _settings.Password, archive); MoveArchiveIntoStorage(details, archive); RemoveArchive(archive); RemoveExpiredBackups(); Directory.Delete(_settings.TempDirectory, true); return true; }
public IActionResult NewEdit(string id, string fileSystemType, string backupDirectory, string actualName) { var backupDetail = BackupDetails.StoredBackupDetails().Get(id); if (backupDetail != null) { ViewBag.PageType = "Edit"; return(View("NewEdit", backupDetail)); } else { backupDetail = new BackupDetail(); backupDetail.FileSystemType = BackupDetails.FileSystemType_TryParse(fileSystemType); backupDetail.BackupDirectory = BackupDetails.BackupDirectory_TryParse(backupDirectory); backupDetail.ActualName = actualName; } ViewBag.PageType = "New"; return(View("NewEdit", backupDetail)); }
public IActionResult Diff(string id) { string result = APICall(); result = JsonConvert.DeserializeObject(result).ToString(); if (result.Equals("Success", StringComparison.OrdinalIgnoreCase)) { ViewBag.Diff = BackupDetails.StoredBackupDetails().GetHTMLDiff(id); Console.WriteLine(ViewBag.Diff); return(View("DiffDisplay")); } var vm = SetMessage(result); var model = new SearchViewModel(); model.BackupDetails = BackupDetails.List(); model.MessageViewModel = vm; return(View("Index", model)); }
public IActionResult NewEditPost(BackupDetail model) { if (ModelState.IsValid) { var backupDetail = BackupDetails.StoredBackupDetails().Get(model.ID); List <BackupDetail> storedBackupDetails; var newBackupDetail = false; if (backupDetail != null) { storedBackupDetails = BackupDetails.StoredBackupDetails().Exclude(model.ID); } else { newBackupDetail = true; storedBackupDetails = BackupDetails.StoredBackupDetails(); } // Check if file/folder is already recorded if (storedBackupDetails.Where(sbd => sbd.BaseDirectory == model.BaseDirectory && sbd.BackupDirectory == model.BackupDirectory && sbd.ActualName == model.ActualName && sbd.FileSystemType == model.FileSystemType).Count() == 0) { model.BackedUp = false; if (newBackupDetail) { string name = ""; if (model.FileSystemType == FileSystemType.File) { if (!storedBackupDetails.Exists(sbd => sbd.SavedName == model.ActualName && sbd.FileSystemType == model.FileSystemType && sbd.BackupDirectory == model.BackupDirectory)) { name = model.ActualName; } else { var counter = 2; name = counter + "-" + model.ActualName; while (model.FileSystemType == FileSystemType.File && (System.IO.File.Exists(Path.Combine(BackupDetails.ServerDir(), model.BackupDirectory.ToString(), name)) || storedBackupDetails.Exists(sbd => sbd.SavedName == name && sbd.FileSystemType == model.FileSystemType))) { counter++; name = counter + "-" + model.ActualName; } } } else { if (!storedBackupDetails.Exists(sbd => sbd.SavedName == model.ActualName && sbd.FileSystemType == model.FileSystemType && sbd.BackupDirectory == model.BackupDirectory)) { name = model.ActualName; } else { var counter = 2; name = counter + "-" + model.ActualName; while (model.FileSystemType == FileSystemType.Directory && (System.IO.Directory.Exists(Path.Combine(BackupDetails.ServerDir(), model.BackupDirectory.ToString(), name)) || storedBackupDetails.Exists(sbd => sbd.SavedName == name && sbd.FileSystemType == model.FileSystemType))) { counter++; name = counter + "-" + model.ActualName; } } } if (string.IsNullOrEmpty(name)) { throw new Exception("Saved name is empty or null."); } else { model.SavedName = name; model.ID = Guid.NewGuid(); storedBackupDetails.Add(model); } } else { storedBackupDetails.Add(model); } storedBackupDetails.Save(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", $"This {model.FileSystemType.ToString().ToLower()} is already recorded, search for and edit the {model.FileSystemType.ToString().ToLower()}."); } } return(View("NewEdit", model)); }
public IActionResult Index(SearchViewModel model) { model.BackupDetails = BackupDetails.List(model); return(View("Index", model)); }
public void Save(BackupDetails details) { string serializedDetails = JsonConvert.SerializeObject(details); File.WriteAllText(DATA_PATH, serializedDetails); }
public void ArchiveBackup(BackupDetails details, string inputFile) { _service.AddObject(inputFile, _settings.Bucket, GenerateFileName(details)); }
private string GenerateFileName(BackupDetails details) { return(string.Concat(_settings.Prefix, "/", details.GenerateFileName())); }