add consistent path option
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-01-22 22:20:42 +01:00
parent 215f40d38b
commit 906e344d75
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 40 additions and 7 deletions

View file

@ -65,6 +65,9 @@
# Make a CephFS snapshot before backup
# cephfs_snap = true
# Ensure the file paths stay the same between backups
# same_path = true
# Borg Check Operation
# [[borg_check]]
# Repository to check

View file

@ -10,6 +10,14 @@ pub fn init_repo(path: &str) {
run_command(&["borg", "init", "--encryption=repokey-blake2", path], None);
}
pub fn bind_mount(src: &str, dst: &str) {
run_command(&["mount", "--bind", src, dst], None);
}
pub fn umount(mount: &str) {
run_command(&["umount", mount], None);
}
pub fn create_archive(conf: &BorgConfig) {
let archive_name = format!(
"BK_{}_{}_{}",
@ -87,14 +95,28 @@ pub fn create_archive(conf: &BorgConfig) {
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);
let mut dirs = if snaps.is_empty() {
conf.src.clone()
} else {
snaps.iter().map(|x| x.0.clone()).collect::<Vec<_>>()
};
let mut mounts = Vec::new();
if conf.same_path.unwrap_or_default() {
for path in &dirs {
let name = path.replace("/", "_");
println!("--> Creating consistent path /bk/{}", name);
std::fs::create_dir_all(&format!("/bk/{name}")).unwrap();
bind_mount(path, &format!("/bk/{name}"));
mounts.push(format!["/bk/{name}"]);
}
dirs = mounts.clone();
}
cmd.extend(dirs.iter().map(|x| x.as_str()));
run_command(&cmd, conf.passphrase.clone());
@ -102,6 +124,11 @@ pub fn create_archive(conf: &BorgConfig) {
cephfs_snap_remove_dir(&cleanup.0);
println!("--> Cleaning up snap {}", cleanup.0);
}
for cleanup in &mounts {
println!("--> Cleaning up mount {}", cleanup);
umount(&cleanup);
}
}
pub fn prune_archive(conf: &BorgPruneConfig) {

View file

@ -84,7 +84,10 @@ pub struct BorgConfig {
pub ensure_exists: Option<String>,
/// Create CephFS snapshots before the backup.
pub cephfs_snap: Option<bool>
pub cephfs_snap: Option<bool>,
/// Bind mount to consistent path
pub same_path: Option<bool>,
}
/// Configuration for a Borg repository integrity check job.