async Task VerifyBackup(string backupDirectory, Data.BackupOption backupOption) { var backupName = backupOption == Data.BackupOption.Full ? "full" : "incremental"; var postUrl = Url + "/api/backup/" + backupName; var twoMinuteInSecs = TimeSpan.FromMinutes(2).TotalSeconds; var jsonContent = $@"{{ 'CancellationTokenInSecs' : {twoMinuteInSecs}, 'TimeoutInSecs' : {twoMinuteInSecs}, 'BackupLocation' : {JsonConvert.SerializeObject(backupDirectory, Formatting.None)} }}"; var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); var response = await client.PostAsync(postUrl, content); var resContent = await response.Content.ReadAsStringAsync(); Assert.IsTrue(response.IsSuccessStatusCode, $"{postUrl} backup post with {jsonContent} : call failed : {response} content: {resContent}"); Assert.IsTrue(Directory.Exists(backupDirectory), "Backup folder not created"); var verifyFiles = new List <string>(); if (backupOption == Data.BackupOption.Full) { verifyFiles.AddRange(new string[] { "backup.metadata", "backup.log", "backup.chkpt" }); } else { verifyFiles.AddRange(new string[] { "incremental.metadata", "backup.log" }); } foreach (var file in verifyFiles) { Assert.AreEqual(1, Directory.GetFiles(backupDirectory, file, SearchOption.AllDirectories).Count(), $"{backupName} : {file} is not present in backup folder {backupDirectory}"); } }
private async Task <IActionResult> TakeBackup(BackupRequestBody backupRequest, Data.BackupOption backupOption) { var error = this.ValidateRequest(backupRequest); if (!error.IsValid) { return(BadRequest(error)); } if (!this.backupParserManager.HasParsingFinished()) { Response.StatusCode = 423; // resource locked at this time. return(new JsonResult(new Dictionary <string, string>() { { "status", "inprogress" }, { "reason", "Backup parsing is still going on. " } })); } var timeout = TimeSpan.FromSeconds(backupRequest.TimeoutInSecs); var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(backupRequest.TimeoutInSecs)); var cancellationToken = cancellationTokenSource.Token; this.UserBackupLocation = String.IsNullOrWhiteSpace(backupRequest.BackupLocation) ? Directory.GetCurrentDirectory() : backupRequest.BackupLocation; await this.backupParserManager.BackupParser.BackupAsync(backupOption, timeout, cancellationToken, this.OnBackupCompletionAsync); return(new JsonResult(new Dictionary <string, string>() { { "status", "success" }, { "backPath", this.BackupPath }, })); }