This commit is contained in:
JMARyA 2025-01-06 06:33:45 +01:00
parent 8413dfa279
commit 2e7d4aa52b
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 39 additions and 3 deletions

View file

@ -59,6 +59,12 @@ comment = "Backup of /home/me/"
# Compression
compression = "zstd,10"
# Ensure directory exists before backup
ensure_exists = "/home/me"
# Make a CephFS snapshot before backup
cephfs_snap = true
# Borg Check Operation
[[borg_check]]
# Repository to check

View file

@ -116,3 +116,10 @@ pub fn cephfs_snap_remove(dir: &str, snap: &str) {
println!("--> Removing snapshot {} on {}", snap, dir);
std::fs::remove_dir(snap_dir).unwrap()
}
pub fn cephfs_snap_remove_dir(dir: &str) {
let path = std::path::Path::new(dir);
println!("--> Removing snapshot {}", path.to_str().unwrap());
std::fs::remove_dir(path).unwrap()
}

View file

@ -1,7 +1,7 @@
use yansi::{Color, Paint};
use crate::{
backup::nowtime,
backup::{cephfs_snap_create, cephfs_snap_remove_dir, ensure_exists, nowtime},
config::{BorgCheckConfig, BorgConfig, BorgPruneConfig},
run_command,
};
@ -24,6 +24,10 @@ pub fn create_archive(conf: &BorgConfig) {
nowtime()
);
if let Some(dir) = &conf.ensure_exists {
ensure_exists(dir);
}
println!(
"--> Running backup for {}",
conf.src.join(",").paint(Color::Yellow),
@ -76,11 +80,28 @@ pub fn create_archive(conf: &BorgConfig) {
cmd.push(&repo);
for path in &conf.src {
cmd.push(path);
let mut snaps = Vec::new();
if conf.cephfs_snap.unwrap_or_default() {
for path in &conf.src {
let snap = cephfs_snap_create(&path);
snaps.push(snap);
}
} else {
for path in &conf.src {
cmd.push(path);
}
}
let snap_dirs = snaps.iter().map(|x| x.0.as_str()).collect::<Vec<_>>();
cmd.extend(snap_dirs);
run_command(&cmd, conf.passphrase.clone());
for cleanup in &snaps {
cephfs_snap_remove_dir(&cleanup.0);
println!("--> Cleaning up snap {}", cleanup.0);
}
}
pub fn prune_archive(conf: &BorgPruneConfig) {

View file

@ -37,6 +37,8 @@ pub struct BorgConfig {
pub no_xattrs: Option<bool>,
pub comment: Option<String>,
pub compression: Option<String>,
pub ensure_exists: Option<String>,
pub cephfs_snap: Option<bool>,
}
#[derive(Debug, Clone, Deserialize)]