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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.