Skip to content

Commit b3fcc1f

Browse files
committed
fix: 🐛 tar exitcode 1
1 parent c9ad64a commit b3fcc1f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/main.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ async fn period_backup(b: &Backup, s3_oprator: &Operator) -> Result<()> {
9090

9191
let next_run_date = chrono::Utc::now() + chrono::Duration::seconds(b.interval as i64);
9292
tracing::info!(
93-
"The next backup will be run at {}",
93+
"[{}] The next backup will be run at {}",
94+
b.name,
9495
next_run_date.to_rfc2822()
9596
);
9697

@@ -137,13 +138,26 @@ async fn backup(b: &Backup, s3_oprator: &Operator) -> Result<()> {
137138

138139
let mut child = cmd.spawn().expect("failed to spawn command");
139140
let stderr = child.stderr.take().expect("failed to get child's stderr");
140-
let mut reader = BufReader::new(stderr).lines();
141-
while let Some(line) = reader.next_line().await? {
141+
let mut stderr_reader = BufReader::new(stderr).lines();
142+
while let Some(line) = stderr_reader.next_line().await? {
142143
tracing::warn!("{}", line);
143144
}
144-
if !child.wait().await?.success() {
145-
return Err(anyhow!("failed to compress"));
146-
};
145+
146+
let exit_code = child
147+
.wait()
148+
.await?
149+
.code()
150+
.ok_or(anyhow!("tar is terminated by signal"))
151+
.map_err(|e| {
152+
tracing::error!("failed to get exit code: {}", e);
153+
e
154+
})?;
155+
156+
match exit_code {
157+
// ignore exitcode 1, to fix `tar: file changed as we read it`
158+
0 | 1 => {}
159+
_ => return Err(anyhow!("failed to compress")),
160+
}
147161

148162
// Calculate blake3 hash
149163
let temp_dest_clone = temp_dest.clone();

0 commit comments

Comments
 (0)