Add some automatic backups of postgresql databases
Some checks failed
/ dev-shell (push) Successful in 4m10s
/ rust-packages (push) Successful in 10m52s
/ check (push) Failing after 11m2s
/ systems (push) Successful in 44m21s
/ terraform-providers (push) Successful in 7m21s

when using zfs volume
This commit is contained in:
Kaare Hoff Skovgaard 2025-08-10 22:56:36 +02:00
parent 457eb3f6b0
commit 1ca3a407f2
Signed by: khs
GPG key ID: C7D890804F01E9F0
5 changed files with 263 additions and 197 deletions

View file

@ -1,6 +1,8 @@
use serde::Deserialize;
use std::{
collections::{BTreeMap, HashMap},
ffi::OsStr,
os::unix::ffi::OsStrExt,
path::{Path, PathBuf},
};
@ -151,13 +153,13 @@ struct ZpoolStatusPool {
vdevs: HashMap<String, ZpoolStatusVdev>,
}
#[derive(Clone, Copy, Deserialize, PartialEq)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
enum ZpoolState {
#[serde(rename = "ONLINE")]
Online,
}
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
#[serde(tag = "vdev_type")]
enum ZpoolStatusVdev {
#[serde(rename = "root")]
@ -177,11 +179,22 @@ impl ZpoolStatusVdev {
}
}
pub fn is_vdev_for_disk(&self, disk_path: &Path) -> bool {
matches!(self, Self::Disk(disk) if disk.path == disk_path)
// Zpool status returns the partition 1 as the path to the device, even if zfs was given the entire disk to work with during pool creation
// Depending on whether we use a device like /dev/vdb or /dev/disk/by-id/XXXX this will be reported as /dev/vdb1 or /dev/disk/by-id/XXXX-part1
matches!(self, Self::Disk(disk) if strip_path_inline_suffix(&disk.path, OsStr::from_bytes(b"-part1")) == disk_path || strip_path_inline_suffix(&disk.path, OsStr::from_bytes(b"1")) == disk_path)
}
}
#[derive(Deserialize)]
fn strip_path_inline_suffix<'a>(path: &'a Path, suffix: &OsStr) -> &'a Path {
Path::new(OsStr::from_bytes(
path.as_os_str()
.as_encoded_bytes()
.strip_suffix(suffix.as_encoded_bytes())
.unwrap_or(path.as_os_str().as_encoded_bytes()),
))
}
#[derive(Deserialize, Debug)]
struct ZpoolStatusVdevRoot {
#[allow(dead_code)]
name: String,
@ -190,7 +203,7 @@ struct ZpoolStatusVdevRoot {
vdevs: HashMap<String, ZpoolStatusVdev>,
}
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
struct ZpoolStatusVdevDisk {
#[allow(dead_code)]
name: String,
@ -199,7 +212,7 @@ struct ZpoolStatusVdevDisk {
path: PathBuf,
}
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
struct ZpoolStatusVdevMirror {
#[allow(dead_code)]
name: String,