src/bin/proxmox-backup-client.rs: implement upload_config
This commit is contained in:
parent
39d6846e1e
commit
ec8a9bb953
@ -28,7 +28,7 @@ use futures::*;
|
|||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref BACKUPSPEC_REGEX: Regex = Regex::new(r"^([a-zA-Z0-9_-]+\.(?:pxar|img)):(.+)$").unwrap();
|
static ref BACKUPSPEC_REGEX: Regex = Regex::new(r"^([a-zA-Z0-9_-]+\.(?:pxar|img|conf)):(.+)$").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ fn create_backup(
|
|||||||
|
|
||||||
let mut upload_list = vec![];
|
let mut upload_list = vec![];
|
||||||
|
|
||||||
enum BackupType { PXAR, IMAGE };
|
enum BackupType { PXAR, IMAGE, CONFIG };
|
||||||
|
|
||||||
for backupspec in backupspec_list {
|
for backupspec in backupspec_list {
|
||||||
let (target, filename) = parse_backupspec(backupspec.as_str().unwrap())?;
|
let (target, filename) = parse_backupspec(backupspec.as_str().unwrap())?;
|
||||||
@ -414,20 +414,36 @@ fn create_backup(
|
|||||||
};
|
};
|
||||||
let file_type = metadata.file_type();
|
let file_type = metadata.file_type();
|
||||||
|
|
||||||
if file_type.is_dir() {
|
let extension = Path::new(target).extension().map(|s| s.to_str().unwrap()).unwrap();
|
||||||
|
|
||||||
upload_list.push((BackupType::PXAR, filename.to_owned(), target.to_owned(), 0));
|
match extension {
|
||||||
|
"pxar" => {
|
||||||
|
if !file_type.is_dir() {
|
||||||
|
bail!("got unexpected file type (expected directory)");
|
||||||
|
}
|
||||||
|
upload_list.push((BackupType::PXAR, filename.to_owned(), target.to_owned(), 0));
|
||||||
|
}
|
||||||
|
"img" => {
|
||||||
|
|
||||||
} else if file_type.is_file() || file_type.is_block_device() {
|
if !(file_type.is_file() || file_type.is_block_device()) {
|
||||||
|
bail!("got unexpected file type (expected file or block device)");
|
||||||
|
}
|
||||||
|
|
||||||
let size = tools::image_size(&PathBuf::from(filename))?;
|
let size = tools::image_size(&PathBuf::from(filename))?;
|
||||||
|
|
||||||
if size == 0 { bail!("got zero-sized file '{}'", filename); }
|
if size == 0 { bail!("got zero-sized file '{}'", filename); }
|
||||||
|
|
||||||
upload_list.push((BackupType::IMAGE, filename.to_owned(), target.to_owned(), size));
|
upload_list.push((BackupType::IMAGE, filename.to_owned(), target.to_owned(), size));
|
||||||
|
}
|
||||||
} else {
|
"conf" => {
|
||||||
bail!("unsupported file type (expected a directory, file or block device)");
|
if !file_type.is_file() {
|
||||||
|
bail!("got unexpected file type (expected regular file)");
|
||||||
|
}
|
||||||
|
upload_list.push((BackupType::CONFIG, filename.to_owned(), target.to_owned(), metadata.len()));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
bail!("got unknown archive extension '{}'", extension);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,6 +460,10 @@ fn create_backup(
|
|||||||
|
|
||||||
for (backup_type, filename, target, size) in upload_list {
|
for (backup_type, filename, target, size) in upload_list {
|
||||||
match backup_type {
|
match backup_type {
|
||||||
|
BackupType::CONFIG => {
|
||||||
|
println!("Upload config file '{}' to '{:?}' as {}", filename, repo, target);
|
||||||
|
client.upload_config(&filename, &target).wait()?;
|
||||||
|
}
|
||||||
BackupType::PXAR => {
|
BackupType::PXAR => {
|
||||||
println!("Upload directory '{}' to '{:?}' as {}", filename, repo, target);
|
println!("Upload directory '{}' to '{:?}' as {}", filename, repo, target);
|
||||||
backup_directory(&client, &filename, &target, chunk_size_opt, all_file_systems, verbose)?;
|
backup_directory(&client, &filename, &target, chunk_size_opt, all_file_systems, verbose)?;
|
||||||
|
@ -431,14 +431,15 @@ impl BackupClient {
|
|||||||
self.h2.clone().post("finish", None).map(|_| ())
|
self.h2.clone().post("finish", None).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upload_config(
|
pub fn upload_config<P: AsRef<std::path::Path>>(
|
||||||
&self,
|
&self,
|
||||||
|
src_path: P,
|
||||||
file_name: &str,
|
file_name: &str,
|
||||||
src_path: std::path::PathBuf,
|
) -> impl Future<Item=(), Error=Error> {
|
||||||
) -> impl Future<Item=(), Error=Error> {
|
|
||||||
|
|
||||||
let h2 = self.h2.clone();
|
let h2 = self.h2.clone();
|
||||||
let file_name = file_name.to_owned();
|
let file_name = file_name.to_owned();
|
||||||
|
let src_path = src_path.as_ref().to_owned();
|
||||||
|
|
||||||
let task = tokio::fs::File::open(src_path)
|
let task = tokio::fs::File::open(src_path)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
|
Loading…
Reference in New Issue
Block a user