From 5d85847f91ab1829adc91143aea12eebaa5506b9 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 12 Jun 2020 10:04:59 +0200 Subject: [PATCH] client: only start catalog upload if we have one else we start a dynamic writer and never close it, leading to a backup error this fixes an issue with backing up vm templates (and possibly vms without disks) Signed-off-by: Dominik Csapak Signed-off-by: Wolfgang Bumiller --- src/bin/proxmox-backup-client.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 123ab2b5..a90a6a72 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -849,8 +849,6 @@ async fn create_backup( let mut upload_list = vec![]; - let mut upload_catalog = false; - for backupspec in backupspec_list { let spec = parse_backup_specification(backupspec.as_str().unwrap())?; let filename = &spec.config_string; @@ -868,7 +866,6 @@ async fn create_backup( bail!("got unexpected file type (expected directory)"); } upload_list.push((BackupSpecificationType::PXAR, filename.to_owned(), format!("{}.didx", target), 0)); - upload_catalog = true; } BackupSpecificationType::IMAGE => { if !(file_type.is_file() || file_type.is_block_device()) { @@ -940,7 +937,8 @@ async fn create_backup( let snapshot = BackupDir::new(backup_type, backup_id, backup_time.timestamp()); let mut manifest = BackupManifest::new(snapshot); - let (catalog, catalog_result_rx) = spawn_catalog_upload(client.clone(), crypt_config.clone())?; + let mut catalog = None; + let mut catalog_result_tx = None; for (backup_type, filename, target, size) in upload_list { match backup_type { @@ -959,6 +957,14 @@ async fn create_backup( manifest.add_file(target, stats.size, stats.csum)?; } BackupSpecificationType::PXAR => { + // start catalog upload on first use + if catalog.is_none() { + let (cat, res) = spawn_catalog_upload(client.clone(), crypt_config.clone())?; + catalog = Some(cat); + catalog_result_tx = Some(res); + } + let catalog = catalog.as_ref().unwrap(); + println!("Upload directory '{}' to '{:?}' as {}", filename, repo, target); catalog.lock().unwrap().start_directory(std::ffi::CString::new(target.as_str())?.as_c_str())?; let stats = backup_directory( @@ -994,7 +1000,7 @@ async fn create_backup( } // finalize and upload catalog - if upload_catalog { + if let Some(catalog) = catalog { let mutex = Arc::try_unwrap(catalog) .map_err(|_| format_err!("unable to get catalog (still used)"))?; let mut catalog = mutex.into_inner().unwrap(); @@ -1003,9 +1009,10 @@ async fn create_backup( drop(catalog); // close upload stream - let stats = catalog_result_rx.await??; - - manifest.add_file(CATALOG_NAME.to_owned(), stats.size, stats.csum)?; + if let Some(catalog_result_rx) = catalog_result_tx { + let stats = catalog_result_rx.await??; + manifest.add_file(CATALOG_NAME.to_owned(), stats.size, stats.csum)?; + } } if let Some(rsa_encrypted_key) = rsa_encrypted_key {