private void DoFullBackup(long index, long term, ManualResetEventSlim allowFurtherModifications) { var snapshotsToDelete = Directory.GetFiles(_storageEnvironment.Options.BasePath, "*.Snapshot"); var fullBackup = new FullBackup(); fullBackup.ToFile(_storageEnvironment, Path.Combine(_storageEnvironment.Options.BasePath, string.Format("Full-{0:D19}-{1:D19}.Snapshot", index, term)), infoNotify: Console.WriteLine, backupStarted: allowFurtherModifications.Set ); DeleteOldSnapshots(snapshotsToDelete); }
public void BackupLocationTypeCorrect() { // Setup List <string> vhdPaths = new List <string> { "mypath/disk1.vhd" }; Guid vmId = Guid.NewGuid(); string testVmName = "test1"; VirtualMachine vm = VirtualMachine.FromExisting(vmId, testVmName, vhdPaths); IBackupLocationFactoryResolver resolver = new MemoryBackupLocationFactoryResolver(); string backupLocation = "newBackupLocation"; LocationType targetLocationType = LocationType.CIFS; BackupConfiguration backupConfig = new BackupConfiguration() { BackupLocation = backupLocation, TargetLocationType = targetLocationType }; // Run FullBackup backup = FullBackup.CreateNew(vm, backupConfig); }
public async Task DataNotCorrupt() { //throw new NotImplementedException(); // Setup List <string> vhdPaths = new List <string> { "mypath/disk1.vhd" }; Guid vmId = Guid.NewGuid(); string testVmName = "test1"; VirtualMachine vm = VirtualMachine.FromExisting(vmId, testVmName, vhdPaths); IBackupLocationFactoryResolver resolver = new MemoryBackupLocationFactoryResolver(); string backupLocation = "newBackupLocation"; LocationType backupLocationType = LocationType.CIFS; // Run FullBackupService backupService = new FullBackupService(resolver); BackupConfiguration backupConfig = new BackupConfiguration() { BackupLocation = backupLocation, TargetLocationType = backupLocationType }; FullBackup backup = await backupService.BackupAsync(vm, backupConfig); // Test IBackupLocationFactory factory = resolver.Resolve(LocationType.CIFS); // Get the byte[] that was written (our backup) string virtualDiskBackupLocation = $"{backup.Path}/{vm.VirtualDisks[0].FileName}"; Stream savedDataStream = factory.Open(virtualDiskBackupLocation); MemoryStream savedDataMs = new MemoryStream(); savedDataStream.CopyTo(savedDataMs); byte[] savedData = savedDataMs.ToArray(); // Get the byte[] we started with Stream originalDataStream = factory.Open(vm.VirtualDisks[0]); MemoryStream originalDataMs = new MemoryStream(); originalDataStream.CopyTo(originalDataMs); byte[] originalData = originalDataMs.ToArray(); Assert.True(originalData.SequenceEqual(savedData), "Data saved does not match original data"); }
public void BackupPathCorrect() { // Setup List <string> vhdPaths = new List <string> { "mypath/disk1.vhd" }; Guid vmId = Guid.NewGuid(); string testVmName = "test1"; VirtualMachine vm = VirtualMachine.FromExisting(vmId, testVmName, vhdPaths); LocationType locationType = LocationType.CIFS; string backupLocation = "newBackupLocation"; BackupConfiguration backupConfig = new BackupConfiguration { BackupLocation = backupLocation, TargetLocationType = locationType }; // Run FullBackup backup = FullBackup.CreateNew(vm, backupConfig); //FullBackup backup = await FullBackup.CreateNewAsync(vm, resolver, BackupLocationType.CIFS, backupLocation); // Test string expectedPath = $"{backupLocation}"; Assert.True(backup.Path == expectedPath, "Backup.Path does not equal the expected path"); }
public VirtualMachineFullBackupCreated(VirtualMachine virtualMachine, FullBackup backup) { VirtualMachine = virtualMachine; Backup = backup; }
public Task Execute(IJobExecutionContext context) { int ID = (int)context.MergedJobDataMap.Get("ID"); Template Temp = Api_Helper.Temp_Get().Result.First(x => x.id == ID); string Type = Temp.Type_Of_Backup.ToUpper(); if (Type == "FULL") { var FullBackup = new FullBackup(Temp.Source, Temp.Destination, Temp.Save_Options); } else if (Type == "DIFF") { var DiffBackup = new DifferentialBackup(Temp.Source, Temp.Destination, Temp.Save_Options); } else if (Type == "INC") { var IncBackup = new IncrementalBackup(Temp.Source, Temp.Destination, Temp.Save_Options); } else if (Type == "UNCFULL") { using (UNCAccessWithCredentials.UNCAccessWithCredentials unc = new UNCAccessWithCredentials.UNCAccessWithCredentials()) { if (unc.NetUseWithCredentials(@"\\kacenka.litv.sssvt.cz\StudentiPrenosne\PerinaRadek", "perinaradek", "litv", "okmujm987")) { var FullBackup = new FullBackup(Temp.Source, Temp.Destination, Temp.Save_Options); } else { throw new Exception("Neplatné přihlašovací údaje"); } } } else if (Type == "UNCINC") { using (UNCAccessWithCredentials.UNCAccessWithCredentials unc = new UNCAccessWithCredentials.UNCAccessWithCredentials()) { if (unc.NetUseWithCredentials(@"\\kacenka.litv.sssvt.cz\StudentiPrenosne\PerinaRadek", "perinaradek", "litv", "okmujm987")) { var IncBackup = new IncrementalBackup(Temp.Source, Temp.Destination, Temp.Save_Options); } else { throw new Exception("Neplatné přihlašovací údaje"); } } } else if (Type == "UNCDIFF") { using (UNCAccessWithCredentials.UNCAccessWithCredentials unc = new UNCAccessWithCredentials.UNCAccessWithCredentials()) { if (unc.NetUseWithCredentials(@"\\kacenka.litv.sssvt.cz\StudentiPrenosne\PerinaRadek", "perinaradek", "litv", "okmujm987")) { var DiffBackup = new DifferentialBackup(Temp.Source, Temp.Destination, Temp.Save_Options); } else { throw new Exception("Neplatné přihlašovací údaje"); } } } else { Task.WaitAll(Api_Helper.Bac_Post(new Backup { Made = DateTime.Now, Name = Type + " " + DateTime.Now, Job = 30, Size = Temp.Destination, Succesful = false })); throw new Exception("Unexpected type of backup :/"); } Console.WriteLine("BACKUP DONE"); Console.WriteLine("ID: " + Temp.id); Console.WriteLine("Type: " + Temp.Type_Of_Backup); Task.WaitAll(Api_Helper.Bac_Post(new Backup { Made = DateTime.Now, Name = Type + " " + DateTime.Now, Job = 30, Size = Temp.Destination, Succesful = true })); return(Task.CompletedTask); }
public FullBackupCreatedEvent(FullBackup backup) { FullBackup = backup; }