extract config and encryption modules

This commit is contained in:
timeshifter
2026-05-05 18:02:59 +02:00
parent 0f8de87abd
commit 8c55028574
4 changed files with 78 additions and 68 deletions
+45
View File
@@ -0,0 +1,45 @@
use std::path::PathBuf;
use anyhow::{Result, bail};
use crate::cmd::cryptsetup;
use crate::config;
pub fn decrypt_backup(pools: &config::BackupPools) -> Result<(String, String)> {
let mut pathbuf = PathBuf::new();
let mut found = false;
let mut the_name = String::new();
let mut the_crypt_device = String::new();
for (device, name) in [&pools.backup1, &pools.backup2]
.iter()
.zip(["backup1", "backup2"])
{
pathbuf.push("/dev/disk/by-uuid/");
pathbuf.push(device);
if pathbuf.exists() {
found = true;
the_name = name.to_string();
the_crypt_device.push_str("crypt-");
the_crypt_device.push_str(name); // content is then e.g. "crypt-backup1"
println!("found backup disk {name}, will decrypt to {the_crypt_device}");
break;
}
}
if found {
cryptsetup::open(&pathbuf, &the_crypt_device)?;
Ok((the_name, the_crypt_device))
} else {
bail!("no backup disk found")
}
}
pub fn encrypt_backup(crypt_device: String) -> Result<()> {
println!("encrypting {crypt_device}");
cryptsetup::close(&crypt_device)
}