| Crates.io | luks-header-backup |
| lib.rs | luks-header-backup |
| version | 0.1.2 |
| created_at | 2025-08-07 07:03:00.934538+00 |
| updated_at | 2025-08-07 07:09:23.352721+00 |
| description | A luks header backup tool. |
| homepage | |
| repository | https://github.com/mason-larobina/luks-header-backup |
| max_upload_size | |
| id | 1784766 |
| size | 35,153 |
This is a command-line tool written in Rust that automates the backup of LUKS (Linux Unified Key Setup) headers from encrypted devices on your system. It detects LUKS devices using blkid, backs up their headers with cryptsetup luksHeaderBackup, generates a textual dump with cryptsetup luksDump, computes a SHA256 hash of the header for verification, and names the files incorporating the hostname, device UUID, and a short hash. The backups are then copied to one or more remote destinations via SCP or saved to local directories.
The tool requires root privileges to access devices and run commands. It logs progress and errors, with configurable log levels via the RUST_LOG environment variable.
Ensure you have Rust and Cargo installed. If not, follow the instructions at rustup.rs.
Clone the repository:
git clone https://github.com/mason-larobina/luks-header-backup
cd luks-header-backup
Build the project:
cargo build --release
# Or
cargo install --path=.
The binary will be available at target/release/luks-header-backup
Install the binary:
$ sudo cp "${PWD}/target/release/luks-header-backup" /usr/local/bin/
# Or
$ sudo cp $(which luks-header-backup) /usr/local/bin/
Run the tool as root, providing one or more remote SCP destinations with --remote-path and/or local backup paths with --backup-path:
sudo luks-header-backup [OPTIONS]
--remote-path <remote_paths>... - Remote SCP destinations (e.g., root@host:/backup/dir/)--backup-path <backup_paths>... - Local paths to backup headers to--help - Print help informationRUST_LOG (e.g., RUST_LOG=debug sudo luks-header-backup ... for verbose output).sudo luks-header-backup \
--backup-path /local/backup/ \
--remote-path root@backup-server-a:/backups/ \
--remote-path root@another-server-b:/storage/
This will backup LUKS headers, save them temporarily with unique names like luks_header_backup.hostname.uuid.shorthash.img and .txt, and copy them to both the local backup path and the specified remote destinations.
cryptsetup luksHeaderRestore in a safe environment.blkid, cryptsetup, and scp. Ensure they are installed and functional.To automate periodic backups, you can use systemd timer and service units. Below is an example configuration to run the backup weekly.
Create /etc/systemd/system/luks-header-backup.service with the following content:
[Unit]
Description=LUKS Header Backup
[Service]
Type=simple
ExecStart=/usr/local/bin/luks-header-backup --backup-path /local/backup/ --remote-path root@backup-server:/backups/
Create /etc/systemd/system/luks-header-backup.timer with the following content:
[Unit]
Description=Run LUKS Header Backup weekly
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
Then, reload systemd, enable, and start the timer:
sudo systemctl daemon-reload
sudo systemctl enable luks-header-backup.timer --now
Customize the ExecStart line with your actual remote destinations and adjust the OnCalendar for your preferred schedule (e.g., daily, monthly).
For issues or contributions, see the repository.