Skip to content

Commit dd3295d

Browse files
committed
feat: ✨ add exclude in config
1 parent 8878066 commit dd3295d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ where
6565
return Err(anyhow::anyhow!("deplicated backup name in config"));
6666
}
6767

68+
// check if name contens `-`
69+
if config.backup.iter().any(|b| b.name.contains('-')) {
70+
return Err(anyhow::anyhow!("backup name can not contain `-`"));
71+
}
72+
6873
Ok(config)
6974
}
7075

src/main.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,24 @@ async fn backup(b: &Backup, s3_oprator: &Operator) -> Result<()> {
9898

9999
// Compress with subprocess
100100
let mut cmd = Command::new("tar");
101-
cmd.args([
102-
"--zstd",
103-
"-cf",
101+
102+
let mut args = vec![
103+
"--zstd".to_string(),
104+
"-cf".to_string(),
104105
temp_dest
105106
.to_str()
106-
.ok_or(anyhow!("failed to convert path to string"))?,
107+
.ok_or(anyhow!("failed to convert path to string"))?
108+
.to_string(),
109+
];
110+
args.extend(b.exclude.iter().map(|e| format!("--exclude={}", e)));
111+
args.push(
107112
backup_source
108113
.to_str()
109-
.ok_or(anyhow!("failed to convert path to string"))?,
110-
])
114+
.ok_or(anyhow!("failed to convert path to string"))?
115+
.to_string(),
116+
);
117+
118+
cmd.args(args)
111119
.kill_on_drop(true);
112120

113121
cmd.stdin(Stdio::piped());

0 commit comments

Comments
 (0)