✨ add consistent path option
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
215f40d38b
commit
906e344d75
3 changed files with 40 additions and 7 deletions
|
@ -65,6 +65,9 @@
|
||||||
# Make a CephFS snapshot before backup
|
# Make a CephFS snapshot before backup
|
||||||
# cephfs_snap = true
|
# cephfs_snap = true
|
||||||
|
|
||||||
|
# Ensure the file paths stay the same between backups
|
||||||
|
# same_path = true
|
||||||
|
|
||||||
# Borg Check Operation
|
# Borg Check Operation
|
||||||
# [[borg_check]]
|
# [[borg_check]]
|
||||||
# Repository to check
|
# Repository to check
|
||||||
|
|
39
src/borg.rs
39
src/borg.rs
|
@ -10,6 +10,14 @@ pub fn init_repo(path: &str) {
|
||||||
run_command(&["borg", "init", "--encryption=repokey-blake2", path], None);
|
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) {
|
pub fn create_archive(conf: &BorgConfig) {
|
||||||
let archive_name = format!(
|
let archive_name = format!(
|
||||||
"BK_{}_{}_{}",
|
"BK_{}_{}_{}",
|
||||||
|
@ -87,14 +95,28 @@ pub fn create_archive(conf: &BorgConfig) {
|
||||||
let snap = cephfs_snap_create(&path);
|
let snap = cephfs_snap_create(&path);
|
||||||
snaps.push(snap);
|
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<_>>();
|
let mut dirs = if snaps.is_empty() {
|
||||||
cmd.extend(snap_dirs);
|
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());
|
run_command(&cmd, conf.passphrase.clone());
|
||||||
|
|
||||||
|
@ -102,6 +124,11 @@ pub fn create_archive(conf: &BorgConfig) {
|
||||||
cephfs_snap_remove_dir(&cleanup.0);
|
cephfs_snap_remove_dir(&cleanup.0);
|
||||||
println!("--> Cleaning up snap {}", 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) {
|
pub fn prune_archive(conf: &BorgPruneConfig) {
|
||||||
|
|
|
@ -84,7 +84,10 @@ pub struct BorgConfig {
|
||||||
pub ensure_exists: Option<String>,
|
pub ensure_exists: Option<String>,
|
||||||
|
|
||||||
/// Create CephFS snapshots before the backup.
|
/// 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.
|
/// Configuration for a Borg repository integrity check job.
|
||||||
|
|
Loading…
Add table
Reference in a new issue