From 3eac45f9cc246fb93c5b28798a90d919d62db28d Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Sat, 2 Nov 2024 15:59:15 +0100 Subject: [PATCH 1/6] (feature): contributing text fix --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c22755e..4c85386 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,11 +38,11 @@ If the issue is specific to a particular LTO version that you cannot test, pleas 3. **Documentation**: Ensure any new methods, classes, or configurations are fully documented. 4. **Testing**: Test your changes thoroughly and add relevant tests where possible. +Thank you for considering contributing, and feel free to reach out if you have questions! Your support helps make MaksIT.LTO.Backup better for everyone. + ## Contact If you have any questions or need further assistance, feel free to reach out: - **Email**: [maksym.sadovnychyy@gmail.com](mailto:maksym.sadovnychyy@gmail.com) - **Reddit**: [MaksIT.LTO.Backup: A Simplified CLI Tool for Windows LTO Tape Backups](https://www.reddit.com/r/MaksIT/comments/1ghgbx5/maksitltobackup_a_simplified_cli_tool_for_windows/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button) - -Thank you for considering contributing, and feel free to reach out if you have questions! Your support helps make MaksIT.LTO.Backup better for everyone. From 3d5e1f38f13b1e28c94b0396e41bb22985be857f Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Sat, 2 Nov 2024 19:27:55 +0100 Subject: [PATCH 2/6] (feature): readme update --- README.md | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fd61b77..c591289 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,25 @@ # MaksIT.LTO.Backup +**⚠️ Warning: This program is currently under fine-tuning and some features are still being added. Extensive real-world testing is still in progress. Use it at your own risk until a stable version is released.** + A C# application designed to facilitate backup and restore operations to an LTO tape drive. This application enables seamless management of backups by handling file organization, descriptor creation, and efficient tape handling processes for loading, writing, and restoring data. +## Version History + +**v0.0.1 - Initial Release (01/11/2024)** +- Initial implementation of backup and restore operations. +- Support for loading and ejecting tape. +- Basic file descriptor management. +- Customizable block sizes for different LTO generations. +- File checksum verification during restore + ## Features - **Load and Eject Tape**: Safely loads and unloads the tape using `TapeDeviceHandler`. - **Backup Operation**: Allows users to create a descriptor file for organizing file metadata and backs up files to the LTO tape in structured blocks. -- **Restore Operation**: Reads data from the tape and restores files to a specified directory, reconstructing original file structure. +- **File Descriptor Management**: Metadata is organized for each file, including file paths, sizes, creation, modification times and checksum. +- **Restore Operation**: Reads data from the tape and restores files to a specified directory, reconstructing original file structure with checksum verifications. - **Customizable Block Sizes**: Supports multiple LTO generations, allowing customization of block sizes based on the tape generation (e.g., LTO-6). -- **File Descriptor Management**: Metadata is organized for each file, including file paths, sizes, creation, and modification times. -- **Zero-Filled End Blocks**: Marks the end of a backup with zero-filled blocks to assist with reading and integrity checks. ## Requirements @@ -76,7 +86,7 @@ A C# application designed to facilitate backup and restore operations to an LTO Execute the application by navigating to the project directory and running: ```bash -dotnet run +dotnet build && dotnet run ``` ### Application Menu @@ -86,12 +96,11 @@ Upon running, the following options will be presented: 1. **Load Tape**: Loads the tape into the drive. 2. **Backup**: Prompts the user to select a backup task from the configured list and initiates the backup process. 3. **Restore**: Restores a previously backed-up directory from the tape. -4. **Eject Tape**: Ejects the tape from the drive safely. +4. **Eject Tape**: Ejects the tape from the drive. 5. **Get device status**: Mostly used for debugging to understand if device is able to write -6. **Tape Erase (Short)**: -7. **Reload configurations** -6. **Exit**: Exits the application. - +6. **Tape Erase (Short)**: Short tape erase +7. **Reload configurations**: Works outside development evironment, used to reload configurations in case of `configuration.json` is changed +8. **Exit**: Exits the application. ### Code Overview @@ -149,7 +158,7 @@ Below is an example configuration setup for an LTO-6 tape generation backup oper ### Error Handling -Errors during backup or restore are caught and logged to the console. Ensure that your `TapeDeviceHandler` is correctly configured and that the tape drive is accessible. +Errors during backup or restore are caught and logged for the moment only to the console. Ensure that your `TapeDeviceHandler` is correctly configured and that the tape drive is accessible. ## Contact From a2ee8d1b93230f9f40da58924ec804a6d7e5a899 Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Sat, 2 Nov 2024 19:50:38 +0100 Subject: [PATCH 3/6] (featue): build scripts imlementation and readme improvement --- .gitignore | 2 ++ README.md | 4 +++- src/dotnet_build_script.ps1 | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7fa7210..53a91ee 100644 --- a/.gitignore +++ b/.gitignore @@ -260,3 +260,5 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ *.pyc + +**/build_outputs diff --git a/README.md b/README.md index c591289..05127c7 100644 --- a/README.md +++ b/README.md @@ -84,11 +84,13 @@ A C# application designed to facilitate backup and restore operations to an LTO ### Running the Application -Execute the application by navigating to the project directory and running: +Execute the application by navigating to the project directory `src\MaksIT.LTO.Backup` and running: ```bash dotnet build && dotnet run ``` +or use `dotnet_build_script.bat` to generate executables in `src\build_outputs` + ### Application Menu Upon running, the following options will be presented: diff --git a/src/dotnet_build_script.ps1 b/src/dotnet_build_script.ps1 index 92e95d0..08fbd59 100644 --- a/src/dotnet_build_script.ps1 +++ b/src/dotnet_build_script.ps1 @@ -1,5 +1,5 @@ # Define project path -$projectPath = "./YourProject.csproj" +$projectPath = "./MaksIT.LTO.Backup/MaksIT.LTO.Backup.csproj" # List of runtime identifiers for self-contained deployments $runtimes = @( From a9efa075cbd490a4a9c9dda7a95bcfd465e672ab Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Sun, 3 Nov 2024 17:10:56 +0100 Subject: [PATCH 4/6] (feature): readme update --- README.md | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 05127c7..f5c317a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MaksIT.LTO.Backup -**⚠️ Warning: This program is currently under fine-tuning and some features are still being added. Extensive real-world testing is still in progress. Use it at your own risk until a stable version is released.** +**⚠️ Warning: This program is currently under fine-tuning and some features are still being added. Extensive real-world testing is still in progress. Use it at your own risk.** A C# application designed to facilitate backup and restore operations to an LTO tape drive. This application enables seamless management of backups by handling file organization, descriptor creation, and efficient tape handling processes for loading, writing, and restoring data. @@ -13,13 +13,10 @@ A C# application designed to facilitate backup and restore operations to an LTO - Customizable block sizes for different LTO generations. - File checksum verification during restore -## Features - -- **Load and Eject Tape**: Safely loads and unloads the tape using `TapeDeviceHandler`. -- **Backup Operation**: Allows users to create a descriptor file for organizing file metadata and backs up files to the LTO tape in structured blocks. -- **File Descriptor Management**: Metadata is organized for each file, including file paths, sizes, creation, modification times and checksum. -- **Restore Operation**: Reads data from the tape and restores files to a specified directory, reconstructing original file structure with checksum verifications. -- **Customizable Block Sizes**: Supports multiple LTO generations, allowing customization of block sizes based on the tape generation (e.g., LTO-6). +**v0.0.2 - (03/11/2024)** +- Use of Crc32 for restored data checksums +- Improved descriptor handling with AESGCM signature and integrity check +- Code review, DI, File logger ## Requirements @@ -85,11 +82,22 @@ A C# application designed to facilitate backup and restore operations to an LTO ### Running the Application Execute the application by navigating to the project directory `src\MaksIT.LTO.Backup` and running: -```bash + +```powershell dotnet build && dotnet run ``` -or use `dotnet_build_script.bat` to generate executables in `src\build_outputs` +or use `dotnet_build_script.bat` to generate executables in `src\build_outputs`. From version `v0.0.2` I started to provide already compiled binaries in [Releases](https://github.com/MAKS-IT-COM/maksit-lto-backup/releases). You have to execute `MaksIT.LTO.Backup.exe` with administrative privileges. + +> ⚠️ **Warning**: When the application is started for the first time, a special secret.txt will be generated in the program root folder. This secret is used to sign descriptor and used during restore to decrypt it and perform integrity check. Please keep its copy safe somwhere. +> In case if in your scenario `secret.txt` is a seurity risk, then create system environment variable `LTO_BACKUP_SECRET` and use content from `secret.txt` as a value, after you can delete `secret.txt` from the application folder. + +Here is a powershell snippet to create system environment variable: + +```powershel +[System.Environment]::SetEnvironmentVariable("LTO_BACKUP_SECRET", "", [System.EnvironmentVariableTarget]::Machine) +``` + ### Application Menu @@ -101,14 +109,7 @@ Upon running, the following options will be presented: 4. **Eject Tape**: Ejects the tape from the drive. 5. **Get device status**: Mostly used for debugging to understand if device is able to write 6. **Tape Erase (Short)**: Short tape erase -7. **Reload configurations**: Works outside development evironment, used to reload configurations in case of `configuration.json` is changed -8. **Exit**: Exits the application. - -### Code Overview - -- **Application Class**: Main class handling backup and restore functionalities. Provides methods like `LoadTape`, `EjectTape`, `Backup`, `Restore`, `CreateDescriptor`, `WriteFilesToTape`, and `FindDescriptor`. -- **TapeDeviceHandler**: Controls tape device operations such as setting positions, writing data, and reading data. -- **BackupDescriptor**: Organizes metadata for backed-up files. Used to log details about each file block on tape. +7. **Exit**: Exits the application. ### Sample Configuration @@ -160,7 +161,7 @@ Below is an example configuration setup for an LTO-6 tape generation backup oper ### Error Handling -Errors during backup or restore are caught and logged for the moment only to the console. Ensure that your `TapeDeviceHandler` is correctly configured and that the tape drive is accessible. +Errors during backup or restore are caught and logged to the console and to `log.txt` in the program root folder. ## Contact From 52945d50005bbf7d3d0c7629cee5057d8dc4db80 Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Mon, 4 Nov 2024 14:21:02 -0800 Subject: [PATCH 5/6] (feature): implementing barcode generator --- src/MaksIT.LTO.Backup/Application.cs | 2 +- src/MaksIT.LTO.Backup/configuration.json | 4 +-- .../MassStorage/TapeDeviceHandlerNtdtape.cs | 25 +++++++++++++++--- .../Utilities/LtoBarcodeGenerator.cs | 26 +++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 src/MaksIT.LTO.Core/Utilities/LtoBarcodeGenerator.cs diff --git a/src/MaksIT.LTO.Backup/Application.cs b/src/MaksIT.LTO.Backup/Application.cs index 50f523e..33c5bc4 100644 --- a/src/MaksIT.LTO.Backup/Application.cs +++ b/src/MaksIT.LTO.Backup/Application.cs @@ -68,7 +68,7 @@ public class Application { Console.OutputEncoding = Encoding.UTF8; while (true) { - Console.WriteLine("MaksIT.LTO.Backup v0.0.1"); + Console.WriteLine("MaksIT.LTO.Backup v0.0.3"); Console.WriteLine("© Maksym Sadovnychyy (MAKS-IT) 2024"); Console.WriteLine("\nSelect an action:"); diff --git a/src/MaksIT.LTO.Backup/configuration.json b/src/MaksIT.LTO.Backup/configuration.json index d7e4f7e..ad2ec6f 100644 --- a/src/MaksIT.LTO.Backup/configuration.json +++ b/src/MaksIT.LTO.Backup/configuration.json @@ -13,7 +13,7 @@ "Backups": [ { "Name": "Normal test", - "Barcode": "", + "Barcode": "L51000000", "LTOGen": "LTO5", "Source": { "LocalPath": { @@ -28,7 +28,7 @@ }, { "Name": "Network test", - "Barcode": "", + "Barcode": "L51000001", "LTOGen": "LTO5", "Source": { "RemotePath": { diff --git a/src/MaksIT.LTO.Core/MassStorage/TapeDeviceHandlerNtdtape.cs b/src/MaksIT.LTO.Core/MassStorage/TapeDeviceHandlerNtdtape.cs index 62e847d..2125c56 100644 --- a/src/MaksIT.LTO.Core/MassStorage/TapeDeviceHandlerNtdtape.cs +++ b/src/MaksIT.LTO.Core/MassStorage/TapeDeviceHandlerNtdtape.cs @@ -1,6 +1,4 @@ -using System; using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; namespace MaksIT.LTO.Core; @@ -82,9 +80,24 @@ public partial class TapeDeviceHandler : IDisposable { // IOCTL_TAPE_WRITE_MARKS definitions // + /// + /// This type of mark is typically used to denote the end of a set or collection of files rather than individual files. Its commonly used in situations where data blocks are grouped logically as sets. This can be useful when you want to denote larger logical separations within the tape, but its less commonly used for simple end-of-file markers. + /// public const uint TAPE_SETMARKS = 0; + + /// + /// This is the standard mark used to indicate the end of a file on the tape. When you have multiple files in a backup, `TAPE_FILEMARKS` is often used between each file or at the end of the backup to signal the end of a logical set of data. For most cases, especially when working with a series of files, this is the most appropriate mark to use to separate or end file data. + /// public const uint TAPE_FILEMARKS = 1; + + /// + /// This is a shorter version of a standard file mark. Its primarily used when you want to conserve tape space but still need a delimiter between sections. However, not all drives support `TAPE_SHORT_FILEMARKS`, and they may not be as reliable for indicating the end of a data sequence in critical backup scenarios. + /// public const uint TAPE_SHORT_FILEMARKS = 2; + + /// + /// This type of mark takes up more tape space and is a longer version of the file mark, used in situations where a highly visible or robust delimiter is required. This is generally not necessary for most backups but may be useful if you want a very strong physical marker on the tape. + /// public const uint TAPE_LONG_FILEMARKS = 3; [StructLayout(LayoutKind.Sequential)] @@ -383,10 +396,12 @@ public partial class TapeDeviceHandler : IDisposable { } /// - /// Write tape marks + /// Write tape marks. + /// For marking the end of a backup of multiple files, **`TAPE_FILEMARKS`** is generally the most appropriate choice. It is the standard file delimiter used for distinguishing individual files or logical breaks on the tape. + /// If you need a more significant delimiter, such as at the end of an entire backup set, you might consider adding a **`TAPE_SETMARKS`** after the `TAPE_FILEMARKS`, but typically, `TAPE_FILEMARKS` alone is sufficient for marking the end of file sequences in backups. /// The type of marks to write. Valid values are , , and . /// The number of marks to write. - public void WriteMarks(uint type, uint count) { + public int WriteMarks(uint type, uint count) { TAPE_WRITE_MARKS marks = new TAPE_WRITE_MARKS { Type = type, Count = count, @@ -401,10 +416,12 @@ public partial class TapeDeviceHandler : IDisposable { if (result) { Console.WriteLine("Write Marks: Success"); + return 0; } else { int error = Marshal.GetLastWin32Error(); Console.WriteLine($"Write Marks: Failed with error code {error}"); + return error; } } finally { diff --git a/src/MaksIT.LTO.Core/Utilities/LtoBarcodeGenerator.cs b/src/MaksIT.LTO.Core/Utilities/LtoBarcodeGenerator.cs new file mode 100644 index 0000000..9b4a427 --- /dev/null +++ b/src/MaksIT.LTO.Core/Utilities/LtoBarcodeGenerator.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MaksIT.LTO.Core.Utilities; +public static class LtoBarcodeGenerator +{ + public static string GenerateLTOBarcode(string volumeIdentifier, int ltoGeneration) + { + if (volumeIdentifier.Length != 6) + { + throw new ArgumentException("Volume identifier must be exactly 6 characters."); + } + + // Append LTO generation code as the 7th character (e.g., "L6" for LTO-6) + string generationCode = $"L{ltoGeneration}"; + + // Combine the volume identifier with the generation code + string barcodeContent = volumeIdentifier + generationCode; + + // Return the full barcode content as a string + return barcodeContent; + } +} From 1fad267ab75981f6510bb9df4ed225e7ac033638 Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Wed, 6 Nov 2024 05:54:21 -0800 Subject: [PATCH 6/6] (refactor): sponsoring update --- CONTRIBUTING.md | 2 +- README.md | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c85386..89c712e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,7 +27,7 @@ If the issue is specific to a particular LTO version that you cannot test, pleas Buy Me A Coffee -- **Sponsoring Hardware**: If you're facing compatibility issues with a specific LTO generation, you can sponsor by directly purchasing the relevant LTO drive and tapes for testing. Contact me for shipping details if you're interested in sponsoring hardware. +- **Sponsoring Hardware**: If you're facing compatibility issues with a specific LTO generation, you can [gofundme](https://gofund.me/6ef96254) by directly purchasing the relevant LTO drive and tapes for testing. Contact me for shipping details if you're interested in sponsoring hardware. ## Code Contribution diff --git a/README.md b/README.md index f5c317a..3fd2fe8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,13 @@ A C# application designed to facilitate backup and restore operations to an LTO tape drive. This application enables seamless management of backups by handling file organization, descriptor creation, and efficient tape handling processes for loading, writing, and restoring data. +**🚀 Support MaksIT.LTO.Backup** +Help me bring reliable and affordable data backup solutions to everyone! With your support, I can test across multiple LTO generations, enhance this software, and ensure compatibility and performance for all users. + +[Contribute to MaksIT.LTO.Backup’s development here!](https://gofund.me/6ef96254) + +Every donation brings us closer to providing a robust, free backup tool that prioritizes data security and accessibility. Thank you for being part of this journey! + ## Version History **v0.0.1 - Initial Release (01/11/2024)**