mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-05-01 00:47:24 +00:00
proxmox-file-restore: replace print with log macro
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
4a2e446767
commit
095b3c1c18
@ -10,6 +10,7 @@ base64 = "0.13"
|
|||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
nix = "0.24"
|
nix = "0.24"
|
||||||
|
log = "0.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
tokio = { version = "1.6", features = [ "io-std", "rt", "rt-multi-thread", "time" ] }
|
tokio = { version = "1.6", features = [ "io-std", "rt", "rt-multi-thread", "time" ] }
|
||||||
|
@ -98,7 +98,7 @@ async fn cleanup_map(map: &mut HashMap<String, VMState>) -> bool {
|
|||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
// VM is not reachable, remove from map and inform user
|
// VM is not reachable, remove from map and inform user
|
||||||
to_remove.push(name.clone());
|
to_remove.push(name.clone());
|
||||||
eprintln!(
|
log::warn!(
|
||||||
"VM '{}' (pid: {}, cid: {}) was not reachable, removing from map",
|
"VM '{}' (pid: {}, cid: {}) was not reachable, removing from map",
|
||||||
name, state.pid, state.cid
|
name, state.pid, state.cid
|
||||||
);
|
);
|
||||||
@ -134,7 +134,7 @@ async fn ensure_running(details: &SnapRestoreDetails) -> Result<VsockClient, Err
|
|||||||
return Ok(client);
|
return Ok(client);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("stale VM detected, restarting ({})", err);
|
log::warn!("stale VM detected, restarting ({})", err);
|
||||||
// VM is dead, restart
|
// VM is dead, restart
|
||||||
let _ = super::qemu_helper::try_kill_vm(vm.pid);
|
let _ = super::qemu_helper::try_kill_vm(vm.pid);
|
||||||
let vms = start_vm(vm.cid, details).await?;
|
let vms = start_vm(vm.cid, details).await?;
|
||||||
@ -233,7 +233,7 @@ impl BlockRestoreDriver for QemuBlockDriver {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
eprintln!("reading file extraction stream failed - {}", err);
|
log::error!("reading file extraction stream failed - {}", err);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -261,7 +261,7 @@ async fn list(
|
|||||||
Some(ref key) => {
|
Some(ref key) => {
|
||||||
let (key, _, _) =
|
let (key, _, _) =
|
||||||
decrypt_key(&key.key, &get_encryption_key_password).map_err(|err| {
|
decrypt_key(&key.key, &get_encryption_key_password).map_err(|err| {
|
||||||
eprintln!("{}", format_key_source(&key.source, "encryption"));
|
log::error!("{}", format_key_source(&key.source, "encryption"));
|
||||||
err
|
err
|
||||||
})?;
|
})?;
|
||||||
Some(Arc::new(CryptConfig::new(key)?))
|
Some(Arc::new(CryptConfig::new(key)?))
|
||||||
@ -392,7 +392,6 @@ async fn extract(
|
|||||||
path: String,
|
path: String,
|
||||||
base64: bool,
|
base64: bool,
|
||||||
target: Option<String>,
|
target: Option<String>,
|
||||||
verbose: bool,
|
|
||||||
param: Value,
|
param: Value,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let repo = extract_repository_from_value(¶m)?;
|
let repo = extract_repository_from_value(¶m)?;
|
||||||
@ -414,7 +413,7 @@ async fn extract(
|
|||||||
Some(ref key) => {
|
Some(ref key) => {
|
||||||
let (key, _, _) =
|
let (key, _, _) =
|
||||||
decrypt_key(&key.key, &get_encryption_key_password).map_err(|err| {
|
decrypt_key(&key.key, &get_encryption_key_password).map_err(|err| {
|
||||||
eprintln!("{}", format_key_source(&key.source, "encryption"));
|
log::error!("{}", format_key_source(&key.source, "encryption"));
|
||||||
err
|
err
|
||||||
})?;
|
})?;
|
||||||
Some(Arc::new(CryptConfig::new(key)?))
|
Some(Arc::new(CryptConfig::new(key)?))
|
||||||
@ -451,7 +450,7 @@ async fn extract(
|
|||||||
let archive_size = reader.archive_size();
|
let archive_size = reader.archive_size();
|
||||||
let reader = LocalDynamicReadAt::new(reader);
|
let reader = LocalDynamicReadAt::new(reader);
|
||||||
let decoder = Accessor::new(reader, archive_size).await?;
|
let decoder = Accessor::new(reader, archive_size).await?;
|
||||||
extract_to_target(decoder, &path, target, verbose).await?;
|
extract_to_target(decoder, &path, target).await?;
|
||||||
}
|
}
|
||||||
ExtractPath::VM(file, path) => {
|
ExtractPath::VM(file, path) => {
|
||||||
let details = SnapRestoreDetails {
|
let details = SnapRestoreDetails {
|
||||||
@ -469,7 +468,7 @@ async fn extract(
|
|||||||
if let Some(mut target) = target {
|
if let Some(mut target) = target {
|
||||||
let reader = data_extract(driver, details, file, path.clone(), true).await?;
|
let reader = data_extract(driver, details, file, path.clone(), true).await?;
|
||||||
let decoder = Decoder::from_tokio(reader).await?;
|
let decoder = Decoder::from_tokio(reader).await?;
|
||||||
extract_sub_dir_seq(&target, decoder, verbose).await?;
|
extract_sub_dir_seq(&target, decoder).await?;
|
||||||
|
|
||||||
// we extracted a .pxarexclude-cli file auto-generated by the VM when encoding the
|
// we extracted a .pxarexclude-cli file auto-generated by the VM when encoding the
|
||||||
// archive, this file is of no use for the user, so try to remove it
|
// archive, this file is of no use for the user, so try to remove it
|
||||||
@ -494,7 +493,6 @@ async fn extract_to_target<T>(
|
|||||||
decoder: Accessor<T>,
|
decoder: Accessor<T>,
|
||||||
path: &[u8],
|
path: &[u8],
|
||||||
target: Option<PathBuf>,
|
target: Option<PathBuf>,
|
||||||
verbose: bool,
|
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
T: pxar::accessor::ReadAt + Clone + Send + Sync + Unpin + 'static,
|
T: pxar::accessor::ReadAt + Clone + Send + Sync + Unpin + 'static,
|
||||||
@ -508,20 +506,14 @@ where
|
|||||||
.ok_or_else(|| format_err!("error opening '{:?}'", path))?;
|
.ok_or_else(|| format_err!("error opening '{:?}'", path))?;
|
||||||
|
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
extract_sub_dir(target, decoder, OsStr::from_bytes(path), verbose).await?;
|
extract_sub_dir(target, decoder, OsStr::from_bytes(path)).await?;
|
||||||
} else {
|
} else {
|
||||||
match file.kind() {
|
match file.kind() {
|
||||||
pxar::EntryKind::File { .. } => {
|
pxar::EntryKind::File { .. } => {
|
||||||
tokio::io::copy(&mut file.contents().await?, &mut tokio::io::stdout()).await?;
|
tokio::io::copy(&mut file.contents().await?, &mut tokio::io::stdout()).await?;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
create_zip(
|
create_zip(tokio::io::stdout(), decoder, OsStr::from_bytes(path)).await?;
|
||||||
tokio::io::stdout(),
|
|
||||||
decoder,
|
|
||||||
OsStr::from_bytes(path),
|
|
||||||
verbose,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ pub async fn start_vm(
|
|||||||
let mut logrotate = LogRotate::new(logfile, false, Some(16), None)?;
|
let mut logrotate = LogRotate::new(logfile, false, Some(16), None)?;
|
||||||
|
|
||||||
if let Err(err) = logrotate.do_rotate() {
|
if let Err(err) = logrotate.do_rotate() {
|
||||||
eprintln!("warning: logrotate for QEMU log file failed - {}", err);
|
log::warn!("warning: logrotate for QEMU log file failed - {}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut logfd = OpenOptions::new()
|
let mut logfd = OpenOptions::new()
|
||||||
@ -297,11 +297,11 @@ pub async fn start_vm(
|
|||||||
bail!("CID '{}' in use, but max attempts reached, aborting", cid);
|
bail!("CID '{}' in use, but max attempts reached, aborting", cid);
|
||||||
}
|
}
|
||||||
// CID in use, try next higher one
|
// CID in use, try next higher one
|
||||||
eprintln!("CID '{}' in use by other VM, attempting next one", cid);
|
log::info!("CID '{}' in use by other VM, attempting next one", cid);
|
||||||
// skip special-meaning low values
|
// skip special-meaning low values
|
||||||
cid = cid.wrapping_add(1).max(10);
|
cid = cid.wrapping_add(1).max(10);
|
||||||
} else {
|
} else {
|
||||||
eprint!("{}", out);
|
log::error!("{}", out);
|
||||||
bail!("Starting VM failed. See output above for more information.");
|
bail!("Starting VM failed. See output above for more information.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,12 +317,10 @@ pub async fn start_vm(
|
|||||||
if let Ok(Ok(_)) =
|
if let Ok(Ok(_)) =
|
||||||
time::timeout(Duration::from_secs(2), client.get("api2/json/status", None)).await
|
time::timeout(Duration::from_secs(2), client.get("api2/json/status", None)).await
|
||||||
{
|
{
|
||||||
if debug {
|
log::debug!(
|
||||||
eprintln!(
|
|
||||||
"Connect to '/run/proxmox-backup/file-restore-serial-{}.sock' for shell access",
|
"Connect to '/run/proxmox-backup/file-restore-serial-{}.sock' for shell access",
|
||||||
cid
|
cid
|
||||||
)
|
);
|
||||||
}
|
|
||||||
return Ok((pid, cid as i32));
|
return Ok((pid, cid as i32));
|
||||||
}
|
}
|
||||||
if kill(pid_t, None).is_err() {
|
if kill(pid_t, None).is_err() {
|
||||||
@ -338,7 +336,7 @@ pub async fn start_vm(
|
|||||||
|
|
||||||
// start failed
|
// start failed
|
||||||
if let Err(err) = try_kill_vm(pid) {
|
if let Err(err) = try_kill_vm(pid) {
|
||||||
eprintln!("killing failed VM failed: {}", err);
|
log::error!("killing failed VM failed: {}", err);
|
||||||
}
|
}
|
||||||
bail!("starting VM timed out");
|
bail!("starting VM timed out");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user