(feature): local backup and restore tested
This commit is contained in:
parent
b518360409
commit
95bf055a1c
@ -42,7 +42,7 @@ public class Application {
|
||||
|
||||
public void LoadTape(TapeDeviceHandler handler) {
|
||||
handler.Prepare(TapeDeviceHandler.TAPE_LOAD);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
Console.WriteLine("Tape loaded.");
|
||||
}
|
||||
@ -54,11 +54,36 @@ public class Application {
|
||||
|
||||
public void EjectTape(TapeDeviceHandler handler) {
|
||||
handler.Prepare(TapeDeviceHandler.TAPE_UNLOAD);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
Console.WriteLine("Tape ejected.");
|
||||
}
|
||||
|
||||
public void TapeErase() {
|
||||
using var handler = new TapeDeviceHandler(_tapePath);
|
||||
LoadTape(handler);
|
||||
|
||||
handler.SetMediaParams(LTOBlockSizes.LTO5);
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.Prepare(TapeDeviceHandler.TAPE_TENSION);
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.Prepare(TapeDeviceHandler.TAPE_LOCK);
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.Erase(TapeDeviceHandler.TAPE_ERASE_SHORT);
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
|
||||
Thread.Sleep(2000);
|
||||
|
||||
Console.WriteLine("Tape erased.");
|
||||
}
|
||||
|
||||
|
||||
public void GetDeviceStatus() {
|
||||
using var handler = new TapeDeviceHandler(_tapePath);
|
||||
handler.GetStatus();
|
||||
@ -176,13 +201,13 @@ public class Application {
|
||||
handler.SetMediaParams(blockSize);
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.Prepare(TapeDeviceHandler.TAPE_TENSION);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.Prepare(TapeDeviceHandler.TAPE_LOCK);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.WaitForTapeReady();
|
||||
|
||||
@ -214,8 +239,10 @@ public class Application {
|
||||
}
|
||||
|
||||
writeError = handler.WriteData(buffer);
|
||||
if (writeError != 0)
|
||||
if (writeError != 0) {
|
||||
Console.WriteLine($"Failed to write file: {filePath}");
|
||||
return;
|
||||
}
|
||||
|
||||
currentTapeBlock++;
|
||||
Thread.Sleep(_configuration.WriteDelay); // Small delay between blocks
|
||||
@ -248,9 +275,10 @@ public class Application {
|
||||
ZeroFillBlocks(handler, 3, blockSize);
|
||||
|
||||
handler.Prepare(TapeDeviceHandler.TAPE_UNLOCK);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
});
|
||||
}
|
||||
@ -266,10 +294,10 @@ public class Application {
|
||||
handler.SetMediaParams(blockSize);
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_SPACE_FILEMARKS, 0, 1);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.WaitForTapeReady();
|
||||
|
||||
@ -313,9 +341,10 @@ public class Application {
|
||||
|
||||
|
||||
handler.Prepare(TapeDeviceHandler.TAPE_UNLOCK);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -333,14 +362,12 @@ public class Application {
|
||||
handler.SetMediaParams(descriptor.BlockSize);
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
|
||||
handler.WaitForTapeReady();
|
||||
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
foreach (var file in descriptor.Files) {
|
||||
// Set position to the start block of the file
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_ABSOLUTE_BLOCK, 0, file.StartBlock);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
|
||||
var filePath = Path.Combine(restoreDirectoryPath, file.FilePath);
|
||||
var directoryPath = Path.GetDirectoryName(filePath);
|
||||
@ -380,7 +407,7 @@ public class Application {
|
||||
}
|
||||
|
||||
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
|
||||
handler.WaitForTapeReady();
|
||||
Thread.Sleep(2000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -19,8 +19,9 @@ class Program {
|
||||
Console.WriteLine("3. Restore");
|
||||
Console.WriteLine("4. Eject tape");
|
||||
Console.WriteLine("5. Get device status");
|
||||
Console.WriteLine("6. Reload configurations");
|
||||
Console.WriteLine("7. Exit");
|
||||
Console.WriteLine("6. Tape Erase (Short)");
|
||||
Console.WriteLine("7. Reload configurations");
|
||||
Console.WriteLine("8. Exit");
|
||||
Console.Write("Enter your choice: ");
|
||||
|
||||
var choice = Console.ReadLine();
|
||||
@ -43,9 +44,12 @@ class Program {
|
||||
app.GetDeviceStatus();
|
||||
break;
|
||||
case "6":
|
||||
app.LoadConfiguration();
|
||||
app.TapeErase();
|
||||
break;
|
||||
case "7":
|
||||
app.LoadConfiguration();
|
||||
break;
|
||||
case "8":
|
||||
Console.WriteLine("Exiting...");
|
||||
return;
|
||||
default:
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"TapePath": "\\\\.\\Tape0",
|
||||
"WriteDelay": 100,
|
||||
"WriteDelay": 1000,
|
||||
"Backups": [
|
||||
{
|
||||
"Name": "Normal test",
|
||||
@ -8,7 +8,7 @@
|
||||
"LTOGen": "LTO5",
|
||||
"Source": {
|
||||
"LocalPath": {
|
||||
"Path": "F:\\LTO\\Backup"
|
||||
"Path": "D:\\Program Files"
|
||||
}
|
||||
},
|
||||
"Destination": {
|
||||
|
||||
@ -325,7 +325,7 @@ public partial class TapeDeviceHandler : IDisposable {
|
||||
/// Erase the tape
|
||||
/// </summary>
|
||||
/// <param name="type">The type of erase operation. Valid values are <see cref="TAPE_ERASE_SHORT"/> and <see cref="TAPE_ERASE_LONG"/>.</param>
|
||||
public void Erase(uint type) {
|
||||
public int Erase(uint type) {
|
||||
TAPE_ERASE erase = new TAPE_ERASE {
|
||||
Type = type,
|
||||
Immediate = 0
|
||||
@ -343,11 +343,14 @@ public partial class TapeDeviceHandler : IDisposable {
|
||||
else {
|
||||
int error = Marshal.GetLastWin32Error();
|
||||
Console.WriteLine($"Erase Tape: Failed with error code {error}");
|
||||
return error;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Marshal.FreeHGlobal(inBuffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user