borg
This commit is contained in:
parent
69d9cd1963
commit
8d0c0a5426
5 changed files with 302 additions and 15 deletions
13
src/main.rs
13
src/main.rs
|
@ -2,12 +2,19 @@ use backup::run_backup;
|
|||
use yansi::{Color, Paint};
|
||||
|
||||
mod backup;
|
||||
mod borg;
|
||||
mod config;
|
||||
|
||||
fn main() {
|
||||
let args = std::env::args().collect::<Vec<_>>();
|
||||
|
||||
if let Some(conf) = args.get(1) {
|
||||
if conf.as_str() == "init" {
|
||||
let repo = args.get(2).unwrap();
|
||||
borg::init_repo(repo);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let conf = toml::from_str(&std::fs::read_to_string(conf).unwrap()).unwrap();
|
||||
run_backup(conf);
|
||||
} else {
|
||||
|
@ -15,7 +22,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run_command(cmd: &[&str]) -> (String, String) {
|
||||
pub fn run_command(cmd: &[&str], borg_passphrase: Option<String>) -> (String, String) {
|
||||
println!("--> {} ", cmd.join(" ").paint(Color::Blue));
|
||||
|
||||
let mut cmd_setup = std::process::Command::new(cmd[0]);
|
||||
|
@ -25,6 +32,10 @@ pub fn run_command(cmd: &[&str]) -> (String, String) {
|
|||
.stdout(std::process::Stdio::inherit())
|
||||
.stdin(std::process::Stdio::inherit());
|
||||
|
||||
if let Some(pw) = borg_passphrase {
|
||||
cmd_setup = cmd_setup.env("BORG_PASSPHRASE", pw);
|
||||
}
|
||||
|
||||
let child = cmd_setup.spawn().unwrap();
|
||||
|
||||
let status = child.wait_with_output().unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue