public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup 5/8] api: datastore: add optional archive-name to file-restore
Date: Fri, 07 Jun 2024 12:24:18 +0200	[thread overview]
Message-ID: <1717755817.ebwtwx0x31.astroid@yuna.none> (raw)
In-Reply-To: <20240607094313.178742-6-c.ebner@proxmox.com>

On June 7, 2024 11:43 am, Christian Ebner wrote:
> Allow to pass the archive name as optional api call parameter instead
> of having it as prefix to the path.
> If this parameter is given, instead of splitting of the archive name
> from the path, the parameter itself is used, leaving the path
> untouched.
> 
> This allows to restore single files from the archive, without having
> to artificially construct the path in case of file restores for split
> pxar archives, where the response path of the listing does not
> include the archive, as opposed to the response provided by lookup
> via the catalog.
> 
> Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
> ---
>  src/api2/admin/datastore.rs | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
> index e25a78bca..d33422d13 100644
> --- a/src/api2/admin/datastore.rs
> +++ b/src/api2/admin/datastore.rs
> @@ -1773,6 +1773,7 @@ pub const API_METHOD_PXAR_FILE_DOWNLOAD: ApiMethod = ApiMethod::new(
>              ("backup-time", false, &BACKUP_TIME_SCHEMA),
>              ("filepath", false, &StringSchema::new("Base64 encoded path").schema()),
>              ("tar", true, &BooleanSchema::new("Download as .tar.zst").schema()),
> +            ("archive-name", true, &StringSchema::new("Base64 encoded archive name").schema()),

same question here - this should be safe as regular string with the
appropriate schema?

>          ]),
>      )
>  ).access(
> @@ -1840,9 +1841,17 @@ pub fn pxar_file_download(
>              components.remove(0);
>          }
>  
> -        let mut split = components.splitn(2, |c| *c == b'/');
> -        let pxar_name = std::str::from_utf8(split.next().unwrap())?;
> -        let file_path = split.next().unwrap_or(b"/");
> +        let (pxar_name, file_path) = if let Some(archive_name) = param["archive-name"].as_str() {
> +            let archive_name = base64::decode(archive_name)
> +                .map_err(|err| format_err!("base64 decode of archive-name failed - {err}"))?;
> +            (archive_name, base64::decode(&filepath)?)
> +        } else {
> +            let mut split = components.splitn(2, |c| *c == b'/');
> +            let pxar_name = split.next().unwrap();
> +            let file_path = split.next().unwrap_or(b"/");
> +            (pxar_name.to_owned(), file_path.to_owned())
> +        };
> +        let pxar_name = std::str::from_utf8(&pxar_name)?;
>          let (manifest, files) = read_backup_index(&backup_dir)?;
>          for file in files {
>              if file.filename == pxar_name && file.crypt_mode == Some(CryptMode::Encrypt) {
> @@ -1865,7 +1874,7 @@ pub fn pxar_file_download(
>          let decoder = Accessor::new(reader, archive_size).await?;
>  
>          let root = decoder.open_root().await?;
> -        let path = OsStr::from_bytes(file_path).to_os_string();
> +        let path = OsStr::from_bytes(&file_path).to_os_string();
>          let file = root
>              .lookup(&path)
>              .await?
> -- 
> 2.39.2
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 
> 


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  reply	other threads:[~2024-06-07 10:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-07  9:43 [pbs-devel] [PATCH proxmox-backup 0/8] drop catalog encoding for split pxar archives Christian Ebner
2024-06-07  9:43 ` [pbs-devel] [PATCH proxmox-backup 1/8] api: datastore: factor out path decoding for catalog Christian Ebner
2024-06-07  9:43 ` [pbs-devel] [PATCH proxmox-backup 2/8] api: datastore: move reusable code out of thread Christian Ebner
2024-06-07  9:43 ` [pbs-devel] [PATCH proxmox-backup 3/8] client: tools: add helper to lookup `ArchiveEntry`s via pxar Christian Ebner
2024-06-07  9:43 ` [pbs-devel] [PATCH proxmox-backup 4/8] api: datastore: conditional lookup for catalog endpoint Christian Ebner
2024-06-07 10:23   ` Fabian Grünbichler
2024-06-07 10:34     ` Christian Ebner
2024-06-07  9:43 ` [pbs-devel] [PATCH proxmox-backup 5/8] api: datastore: add optional archive-name to file-restore Christian Ebner
2024-06-07 10:24   ` Fabian Grünbichler [this message]
2024-06-07  9:43 ` [pbs-devel] [PATCH proxmox-backup 6/8] file-restore: fallback to mpxar if catalog not present Christian Ebner
2024-06-07 10:32   ` Fabian Grünbichler
2024-06-07 10:43     ` Christian Ebner
2024-06-07 11:35       ` Fabian Grünbichler
2024-06-07 11:41         ` Christian Ebner
2024-06-07  9:43 ` [pbs-devel] [PATCH proxmox-backup 7/8] www: content: lookup via metadata archive instead of catalog Christian Ebner
2024-06-07  9:43 ` [pbs-devel] [PATCH proxmox-backup 8/8] client: backup: conditionally write catalog for file level backups Christian Ebner
2024-06-07 10:48   ` Fabian Grünbichler

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=1717755817.ebwtwx0x31.astroid@yuna.none \
    --to=f.gruenbichler@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