src/api2/admin/datastore.rs: extract backup size from index.json
This commit is contained in:
parent
eecb182845
commit
a17a0e7a9f
@ -172,15 +172,28 @@ fn list_snapshots (
|
|||||||
if let Some(backup_type) = backup_type {
|
if let Some(backup_type) = backup_type {
|
||||||
if backup_type != group.backup_type() { continue; }
|
if backup_type != group.backup_type() { continue; }
|
||||||
}
|
}
|
||||||
if let Some(backup_id) = backup_id {
|
if let Some(backup_id) = backup_id {
|
||||||
if backup_id != group.backup_id() { continue; }
|
if backup_id != group.backup_id() { continue; }
|
||||||
}
|
}
|
||||||
snapshots.push(json!({
|
|
||||||
|
let mut result_item = json!({
|
||||||
"backup-type": group.backup_type(),
|
"backup-type": group.backup_type(),
|
||||||
"backup-id": group.backup_id(),
|
"backup-id": group.backup_id(),
|
||||||
"backup-time": info.backup_dir.backup_time().timestamp(),
|
"backup-time": info.backup_dir.backup_time().timestamp(),
|
||||||
"files": info.files,
|
"files": info.files,
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
if let Ok(index) = read_backup_index(&datastore, &info.backup_dir) {
|
||||||
|
let mut backup_size = 0;
|
||||||
|
for item in index.as_array().unwrap().iter() {
|
||||||
|
if let Some(item_size) = item["size"].as_u64() {
|
||||||
|
backup_size += item_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result_item["size"] = backup_size.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshots.push(result_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(json!(snapshots))
|
Ok(json!(snapshots))
|
||||||
|
@ -335,14 +335,23 @@ fn list_snapshots(
|
|||||||
.map(|v| strip_server_file_expenstion(v.as_str().unwrap())).collect();
|
.map(|v| strip_server_file_expenstion(v.as_str().unwrap())).collect();
|
||||||
|
|
||||||
if output_format == "text" {
|
if output_format == "text" {
|
||||||
println!("{} | {}", path, tools::join(&files, ' '));
|
let size_str = if let Some(size) = item["size"].as_u64() {
|
||||||
|
size.to_string()
|
||||||
|
} else {
|
||||||
|
String::from("-")
|
||||||
|
};
|
||||||
|
println!("{} | {} | {}", path, size_str, tools::join(&files, ' '));
|
||||||
} else {
|
} else {
|
||||||
result.push(json!({
|
let mut data = json!({
|
||||||
"backup-type": btype,
|
"backup-type": btype,
|
||||||
"backup-id": id,
|
"backup-id": id,
|
||||||
"backup-time": epoch,
|
"backup-time": epoch,
|
||||||
"files": files,
|
"files": files,
|
||||||
}));
|
});
|
||||||
|
if let Some(size) = item["size"].as_u64() {
|
||||||
|
data["size"] = size.into();
|
||||||
|
}
|
||||||
|
result.push(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user