0

I'm trying to find a way to specify a file name in a compressed .zip archive while compressing it from standard input to standard output. I want to achieve it without creating a temporal file during a process.

Currently I have an example script which creates mysqldump, passes the result as input to a zip command and outputs the stream to aws s3 command to save a result to S3.

Here is the example:

mysqldump ... | zip | aws s3 cp - s3://[bucket_name]/output.sql.zip

The problem is zip by default saves a file inside zip archive with name "-".

Maybe there is a way how to pass specific file name inside an archive using zip command or any other zip library?

  • Your question has already been answered [on StackOverflow](https://stackoverflow.com/q/2019603/1673776). From what I can see through the answers, the answer would be _no, it's not possible, and your best bet is to use a named FIFO_. Check out the answers to the question I linked please. – Victor Dec 12 '22 at 09:23
  • Thanks for the link with a same problem. But I asked maybe there are alternative libs which could help this problem if zip cannot do that. – Aurimas Skaburskas Dec 12 '22 at 09:47
  • Just curious - what is the problem with a named FIFO? You can still have it as a one-line command. Are there any blockers in using that? – Victor Dec 12 '22 at 12:19

1 Answers1

0

Recent Linux distributions have a streamzip script which I wrote to handle this usecase. In the example below the -member commandline option sets the member within the streamed zipfile to data.sql

mysqldump ... | streamzip -member data.sql | aws s3 cp - s3://[bucket_name]/output.sql.zip

If the mysqldump is larger than 4G, include the -zip64 option with streamzip.

If you don't have streamzip available download from https://github.com/pmqs/IO-Compress/blob/master/bin/streamzip

pmqs
  • 3,066
  • 2
  • 13
  • 22
  • _Recent Linux distributions have a streamzip script which I wrote_ What do you mean by this? Is your script included in some Linux distributions? If so, why does the OP need to clone it from GitHub? – Victor Dec 12 '22 at 12:18
  • Yes, it is included in some Linux distributions. -- I 'm running Ubuntu 22.04 and `streamzip` is present. I don't know which version of Linux have it, so providing a fall-back option to fetch the script. – pmqs Dec 12 '22 at 12:26