public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/3] api: admin/datastore: add tar support for pxar_file_download
Date: Tue, 12 Apr 2022 13:04:17 +0200	[thread overview]
Message-ID: <20220412110418.3360746-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20220412110418.3360746-1-d.csapak@proxmox.com>

by using the newly added 'create_tar' and the 'ZstdEncoder'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 Cargo.toml                  |  1 +
 src/api2/admin/datastore.rs | 33 ++++++++++++++++++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index bd21117a..c7677c33 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -105,6 +105,7 @@ proxmox-uuid = "1"
 proxmox-serde = "0.1"
 proxmox-shared-memory = "0.2"
 proxmox-sys = { version = "0.2", features = [ "sortable-macro" ] }
+proxmox-compression = "0.1"
 
 
 proxmox-acme-rs = "0.4"
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index ef82b426..02e92640 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -12,6 +12,7 @@ use hyper::{header, Body, Response, StatusCode};
 use serde_json::{json, Value};
 use tokio_stream::wrappers::ReceiverStream;
 
+use proxmox_compression::zstd::ZstdEncoder;
 use proxmox_sys::sortable;
 use proxmox_sys::fs::{
     file_read_firstline, file_read_optional_string, replace_file, CreateOptions,
@@ -40,7 +41,7 @@ use pbs_api_types::{ Authid, BackupContent, Counts, CryptMode,
     PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_VERIFY,
 
 };
-use pbs_client::pxar::create_zip;
+use pbs_client::pxar::{create_tar, create_zip};
 use pbs_datastore::{
     check_backup_owner, DataStore, BackupDir, BackupGroup, StoreProgress, LocalChunkReader,
     CATALOG_NAME,
@@ -1432,6 +1433,7 @@ pub const API_METHOD_PXAR_FILE_DOWNLOAD: ApiMethod = ApiMethod::new(
             ("backup-id", false,  &BACKUP_ID_SCHEMA),
             ("backup-time", false, &BACKUP_TIME_SCHEMA),
             ("filepath", false, &StringSchema::new("Base64 encoded path").schema()),
+            ("tar", true, &BooleanSchema::new("Download as .tar.zst").schema()),
         ]),
     )
 ).access(None, &Permission::Privilege(
@@ -1460,6 +1462,8 @@ pub fn pxar_file_download(
         let backup_id = required_string_param(&param, "backup-id")?;
         let backup_time = required_integer_param(&param, "backup-time")?;
 
+        let tar = param["tar"].as_bool().unwrap_or(false);
+
         let backup_dir = BackupDir::new(backup_type, backup_id, backup_time)?;
 
         check_priv_or_backup_owner(&datastore, backup_dir.group(), &auth_id, PRIV_DATASTORE_READ)?;
@@ -1519,15 +1523,26 @@ pub fn pxar_file_download(
                     }),
             ),
             EntryKind::Directory => {
-                let (sender, receiver) = tokio::sync::mpsc::channel(100);
+                let (sender, receiver) = tokio::sync::mpsc::channel::<Result<_, Error>>(100);
                 let channelwriter = AsyncChannelWriter::new(sender, 1024 * 1024);
-                proxmox_rest_server::spawn_internal_task(
-                    create_zip(channelwriter, decoder, path.clone(), false)
-                );
-                Body::wrap_stream(ReceiverStream::new(receiver).map_err(move |err| {
-                    eprintln!("error during streaming of zip '{:?}' - {}", path, err);
-                    err
-                }))
+                if tar {
+                    proxmox_rest_server::spawn_internal_task(
+                        create_tar(channelwriter, decoder, path.clone(), false)
+                    );
+                    let zstdstream = ZstdEncoder::new(ReceiverStream::new(receiver))?;
+                    Body::wrap_stream(zstdstream.map_err(move |err| {
+                        eprintln!("error during streaming of tar.zst '{:?}' - {}", path, err);
+                        err
+                    }))
+                } else {
+                    proxmox_rest_server::spawn_internal_task(
+                        create_zip(channelwriter, decoder, path.clone(), false)
+                    );
+                    Body::wrap_stream(ReceiverStream::new(receiver).map_err(move |err| {
+                        eprintln!("error during streaming of zip '{:?}' - {}", path, err);
+                        err
+                    }))
+                }
             }
             other => bail!("cannot download file of type {:?}", other),
         };
-- 
2.30.2





  parent reply	other threads:[~2022-04-12 11:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12 11:04 [pbs-devel] [PATCH proxmox/widget-toolkit/proxmox-backup] add tar.zst support for file download Dominik Csapak
2022-04-12 11:04 ` [pbs-devel] [PATCH proxmox 1/2] proxmox-compression: add async tar builder Dominik Csapak
2022-04-13  7:36   ` [pbs-devel] applied-series: " Wolfgang Bumiller
2022-04-12 11:04 ` [pbs-devel] [PATCH proxmox 2/2] proxmox-compression: add streaming zstd encoder Dominik Csapak
2022-04-12 11:04 ` [pbs-devel] [PATCH widget-toolkit 1/1] window/FileBrowser: add optional 'tar.zst' button Dominik Csapak
2022-04-13  8:37   ` [pbs-devel] applied: " Wolfgang Bumiller
2022-04-12 11:04 ` [pbs-devel] [PATCH proxmox-backup 1/3] pbs-client: add 'create_tar' helper function Dominik Csapak
2022-04-13  8:34   ` [pbs-devel] applied-series: " Wolfgang Bumiller
2022-04-12 11:04 ` Dominik Csapak [this message]
2022-04-12 11:04 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: datastore/Content: enable tar download in ui Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220412110418.3360746-6-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal