Skip to content

Commit 6662481

Browse files
committed
update dependencies, refactor some backup code, increase default pid
limit
1 parent 474c423 commit 6662481

File tree

9 files changed

+201
-231
lines changed

9 files changed

+201
-231
lines changed

Cargo.lock

Lines changed: 125 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

application/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "wings-rs"
33
rust-version = { workspace = true }
4-
version = "0.24.8"
4+
version = "0.24.9"
55
edition = "2024"
66

77
[dependencies]
@@ -31,7 +31,7 @@ tokio-util = { workspace = true }
3131
uuid = { workspace = true }
3232
rand = { workspace = true }
3333
tar = "0.4.44"
34-
zip = { version = "7.0.0", default-features = false, features = ["bzip2", "deflate", "time", "zstd", "lzma", "xz"] }
34+
zip = { version = "8.0.0", default-features = false, features = ["bzip2", "deflate", "time", "zstd", "lzma", "xz"] }
3535
sevenz-rust2 = { version = "0.20.0", features = ["deflate", "compress", "brotli", "zstd", "bzip2", "ppmd", "lz4"] }
3636
flate2 = { version = "1.1.1", default-features = false, features = ["zlib-rs"] }
3737
jwt = "0.16.0"
@@ -62,7 +62,7 @@ async-trait = "0.1.88"
6262
cron = { version = "0.15.0", features = ["serde"] }
6363
chrono-tz = "0.10.4"
6464
gzp = "2.0.0"
65-
lzma-rust2 = { version = "0.15.4", features = ["optimization"] }
65+
lzma-rust2 = { version = "0.16.1", features = ["optimization"] }
6666
bzip2 = "0.6.0"
6767
zstd = { version = "0.13.3", features = ["zstdmt"] }
6868
base64 = "0.22.1"
@@ -83,7 +83,7 @@ positioned-io = "0.3.5"
8383
rmp-serde = "1.3.1"
8484
accept-header = "0.2.3"
8585
mime = "0.3.17"
86-
toml = { version = "0.9.11", features = ["preserve_order"] }
86+
toml = { version = "1.0.1", features = ["preserve_order"] }
8787
sntpc-net-tokio = "1.0.1"
8888
sntpc = { version = "0.8.1", features = ["std"] }
8989

application/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ fn docker_tmpfs_size() -> u64 {
338338
100
339339
}
340340
fn docker_container_pid_limit() -> u64 {
341-
512
341+
5120
342342
}
343343

344344
fn docker_installer_limits_timeout() -> u64 {

application/src/io/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use std::{
33
os::fd::AsFd,
44
};
55

6-
use crate::io::abort::AbortListener;
7-
86
pub mod abort;
97
pub mod compression;
108
pub mod counting_reader;
@@ -46,7 +44,7 @@ pub fn copy_file_progress(
4644
reader: &mut (impl AsFd + std::io::Read + ?Sized),
4745
writer: &mut (impl AsFd + std::io::Write + ?Sized),
4846
mut progress: impl FnMut(usize) -> Result<(), std::io::Error>,
49-
listener: AbortListener,
47+
listener: abort::AbortListener,
5048
) -> Result<u64, std::io::Error> {
5149
let mut total_copied = 0;
5250

application/src/server/backup/adapters/btrfs.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::{
1010
},
1111
},
1212
};
13-
use axum::http::HeaderMap;
1413
use std::{
1514
path::{Path, PathBuf},
1615
sync::{
@@ -310,19 +309,16 @@ impl BackupExt for BtrfsBackup {
310309
}
311310
});
312311

313-
let mut headers = HeaderMap::with_capacity(2);
314-
headers.insert(
315-
"Content-Disposition",
316-
format!(
317-
"attachment; filename={}.{}",
318-
self.uuid,
319-
archive_format.extension()
312+
Ok(ApiResponse::new_stream(reader)
313+
.with_header(
314+
"Content-Disposition",
315+
&format!(
316+
"attachment; filename={}.{}",
317+
self.uuid,
318+
archive_format.extension()
319+
),
320320
)
321-
.parse()?,
322-
);
323-
headers.insert("Content-Type", archive_format.mime_type().parse()?);
324-
325-
Ok(ApiResponse::new_stream(reader).with_headers(headers))
321+
.with_header("Content-Type", archive_format.mime_type()))
326322
}
327323

328324
async fn restore(

application/src/server/backup/adapters/ddup_bak.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::{
1616
},
1717
},
1818
};
19-
use axum::http::HeaderMap;
2019
use cap_std::fs::Permissions;
2120
use chrono::{Datelike, Timelike};
2221
use ddup_bak::archive::entries::Entry;
@@ -457,19 +456,16 @@ impl BackupExt for DdupBakBackup {
457456
}
458457
}
459458

460-
let mut headers = HeaderMap::with_capacity(2);
461-
headers.insert(
462-
"Content-Disposition",
463-
format!(
464-
"attachment; filename={}.{}",
465-
self.uuid,
466-
archive_format.extension()
459+
Ok(ApiResponse::new_stream(reader)
460+
.with_header(
461+
"Content-Disposition",
462+
&format!(
463+
"attachment; filename={}.{}",
464+
self.uuid,
465+
archive_format.extension()
466+
),
467467
)
468-
.parse()?,
469-
);
470-
headers.insert("Content-Type", archive_format.mime_type().parse()?);
471-
472-
Ok(ApiResponse::new_stream(reader).with_headers(headers))
468+
.with_header("Content-Type", archive_format.mime_type()))
473469
}
474470

475471
async fn restore(
@@ -554,10 +550,6 @@ impl BackupExt for DdupBakBackup {
554550
if let Err(err) = server.filesystem.symlink(&symlink.target, &path) {
555551
tracing::debug!(path = %path.display(), "failed to create symlink from backup: {:?}", err);
556552
} else {
557-
server.filesystem.set_symlink_permissions(
558-
&path,
559-
cap_std::fs::Permissions::from_std(symlink.mode.into()),
560-
)?;
561553
server.filesystem.set_times(&path, symlink.mtime, None)?;
562554
}
563555
}

application/src/server/backup/adapters/restic.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ use crate::{
2121
},
2222
utils::PortableModeExt,
2323
};
24-
use axum::http::HeaderMap;
2524
use chrono::{Datelike, Timelike};
2625
use compact_str::ToCompactString;
27-
use human_bytes::human_bytes;
2826
use serde::Deserialize;
2927
use std::{
3028
collections::HashMap,
@@ -45,8 +43,14 @@ static RESTIC_BACKUP_CACHE: LazyLock<ResticBackupCache> =
4543
#[derive(Debug, Deserialize)]
4644
struct ResticSnapshot {
4745
short_id: String,
48-
tags: Vec<String>,
49-
paths: Vec<String>,
46+
tags: Vec<compact_str::CompactString>,
47+
paths: Vec<compact_str::CompactString>,
48+
summary: ResticSnapshotSummary,
49+
}
50+
51+
#[derive(Debug, Deserialize)]
52+
struct ResticSnapshotSummary {
53+
total_bytes_processed: u64,
5054
}
5155

5256
#[derive(Deserialize)]
@@ -69,6 +73,7 @@ pub struct ResticDirectoryEntry {
6973
pub struct ResticBackup {
7074
uuid: uuid::Uuid,
7175
short_id: String,
76+
total_bytes_processed: u64,
7277

7378
config: Arc<crate::config::Config>,
7479
server_path: PathBuf,
@@ -217,6 +222,7 @@ impl BackupFindExt for ResticBackup {
217222
return Ok(Some(Backup::Restic(ResticBackup {
218223
uuid,
219224
short_id: snapshot.short_id.clone(),
225+
total_bytes_processed: snapshot.summary.total_bytes_processed,
220226
config: Arc::clone(config),
221227
server_path: match snapshot.paths.first() {
222228
Some(path) => PathBuf::from(path),
@@ -280,6 +286,7 @@ impl BackupFindExt for ResticBackup {
280286
backup = Some(ResticBackup {
281287
uuid,
282288
short_id: snapshot.short_id.clone(),
289+
total_bytes_processed: snapshot.summary.total_bytes_processed,
283290
config: Arc::clone(config),
284291
server_path: match snapshot.paths.first() {
285292
Some(path) => PathBuf::from(path),
@@ -343,6 +350,7 @@ impl BackupFindExt for ResticBackup {
343350
backup = Some(ResticBackup {
344351
uuid,
345352
short_id: snapshot.short_id.clone(),
353+
total_bytes_processed: snapshot.summary.total_bytes_processed,
346354
config: Arc::clone(config),
347355
server_path: match snapshot.paths.first() {
348356
Some(path) => PathBuf::from(path),
@@ -562,8 +570,11 @@ impl BackupCreateExt for ResticBackup {
562570
(
563571
ResticSnapshot {
564572
short_id: snapshot_id.clone(),
565-
tags: vec![uuid.to_string()],
566-
paths: vec![server.filesystem.base_path.to_string_lossy().to_string()],
573+
tags: vec![uuid.to_compact_string()],
574+
paths: vec![server.filesystem.base_path.to_string_lossy().into()],
575+
summary: ResticSnapshotSummary {
576+
total_bytes_processed,
577+
},
567578
},
568579
Arc::new(configuration),
569580
),
@@ -711,19 +722,16 @@ impl BackupExt for ResticBackup {
711722
}
712723
}
713724

714-
let mut headers = HeaderMap::with_capacity(2);
715-
headers.insert(
716-
"Content-Disposition",
717-
format!(
718-
"attachment; filename={}.{}",
719-
self.uuid,
720-
archive_format.extension()
725+
Ok(ApiResponse::new_stream(reader)
726+
.with_header(
727+
"Content-Disposition",
728+
&format!(
729+
"attachment; filename={}.{}",
730+
self.uuid,
731+
archive_format.extension()
732+
),
721733
)
722-
.parse()?,
723-
);
724-
headers.insert("Content-Type", archive_format.mime_type().parse()?);
725-
726-
Ok(ApiResponse::new_stream(reader).with_headers(headers))
734+
.with_header("Content-Type", archive_format.mime_type()))
727735
}
728736

729737
async fn restore(
@@ -733,6 +741,8 @@ impl BackupExt for ResticBackup {
733741
total: Arc<AtomicU64>,
734742
_download_url: Option<compact_str::CompactString>,
735743
) -> Result<(), anyhow::Error> {
744+
total.store(self.total_bytes_processed, Ordering::SeqCst);
745+
736746
let child = Command::new("restic")
737747
.envs(&self.configuration.environment)
738748
.arg("--json")
@@ -748,38 +758,28 @@ impl BackupExt for ResticBackup {
748758
.arg(&server.filesystem.base_path)
749759
.arg("--limit-download")
750760
.arg((server.app_state.config.system.backups.read_limit.as_kib()).to_compact_string())
761+
.arg("-vv")
751762
.stdout(std::process::Stdio::piped())
752763
.spawn()?;
753764

754765
let mut line_reader = tokio::io::BufReader::new(child.stdout.unwrap()).lines();
755766

756767
while let Ok(Some(line)) = line_reader.next_line().await {
757768
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&line)
758-
&& json.get("message_type").and_then(|v| v.as_str()) == Some("status")
769+
&& json.get("message_type").and_then(|v| v.as_str()) == Some("verbose_status")
759770
{
760-
let total_bytes = json
761-
.get("total_bytes")
762-
.and_then(|v| v.as_u64())
763-
.unwrap_or(0);
764-
let bytes_restored = json
765-
.get("bytes_restored")
766-
.and_then(|v| v.as_u64())
767-
.unwrap_or(0);
768-
let percent_done = json
769-
.get("percent_done")
770-
.and_then(|v| v.as_f64())
771-
.unwrap_or(0.0);
772-
let percent_done = (percent_done * 10000.0).round() / 100.0;
773-
774-
progress.store(bytes_restored, Ordering::SeqCst);
775-
total.store(total_bytes, Ordering::SeqCst);
776-
777-
server.log_daemon(compact_str::format_compact!(
778-
"(restoring): {} of {} ({}%)",
779-
human_bytes(bytes_restored as f64),
780-
human_bytes(total_bytes as f64),
781-
percent_done
782-
));
771+
let Some(item) = json.get("item").and_then(|v| v.as_str()) else {
772+
continue;
773+
};
774+
let size = json.get("size").and_then(|v| v.as_u64()).unwrap_or(0);
775+
776+
if size == 0 {
777+
continue;
778+
}
779+
780+
progress.fetch_add(size, Ordering::SeqCst);
781+
782+
server.log_daemon(compact_str::format_compact!("(restoring): {}", item));
783783
}
784784
}
785785

application/src/server/backup/adapters/zfs.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::{
1010
},
1111
},
1212
};
13-
use axum::http::HeaderMap;
1413
use std::{
1514
path::{Path, PathBuf},
1615
sync::{
@@ -297,19 +296,16 @@ impl BackupExt for ZfsBackup {
297296
}
298297
});
299298

300-
let mut headers = HeaderMap::with_capacity(2);
301-
headers.insert(
302-
"Content-Disposition",
303-
format!(
304-
"attachment; filename={}.{}",
305-
self.uuid,
306-
archive_format.extension()
299+
Ok(ApiResponse::new_stream(reader)
300+
.with_header(
301+
"Content-Disposition",
302+
&format!(
303+
"attachment; filename={}.{}",
304+
self.uuid,
305+
archive_format.extension()
306+
),
307307
)
308-
.parse()?,
309-
);
310-
headers.insert("Content-Type", archive_format.mime_type().parse()?);
311-
312-
Ok(ApiResponse::new_stream(reader).with_headers(headers))
308+
.with_header("Content-Type", archive_format.mime_type()))
313309
}
314310

315311
async fn restore(

application/src/server/filesystem/virtualfs/cap.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use tokio::io::AsyncWriteExt;
2-
31
use super::{
42
AsyncFileRead, AsyncReadableFileStream, AsyncWritableSeekableFileStream, ByteRange,
53
DirectoryListing, DirectoryStreamWalk, DirectoryWalk, FileMetadata, FileRead, FileType,
@@ -17,6 +15,7 @@ use std::{
1715
path::{Path, PathBuf},
1816
sync::{Arc, atomic::AtomicU64},
1917
};
18+
use tokio::io::AsyncWriteExt;
2019

2120
pub struct VirtualCapFilesystem {
2221
pub inner: crate::server::filesystem::cap::CapFilesystem,

0 commit comments

Comments
 (0)