Reputation: 106
There is a folder with images with the size of 2.4 Gb.
The task is to archive via SSH this folder to multiple separated independent zip-archives.
I have tried:
zip -r -s 512m archive.zip folder
This command creates dependent zip-archives:
archive.z01
archive.z02
archive.z03
archive.z04
archive.zip
But I need to create exactly independent zip-archives for "online web service" which optimizes images. This service requires zip archive and size up to 2Gb.
Could you please suggest a working solution?
OS: Linux
Access via: SSH
Thanks for help.
Upvotes: 1
Views: 354
Reputation: 106
the.Legend, thanks for the script.
Here is few notices:
1. `du -m $ZIP_NAME | cut -f 1`
Returns 1 for files with the size less then 1 Mb.
2. INDEX=`echo "$INDEX + 1" | bc
Does not work in bash in linux.
Here is updated script which was tested in linux:
#!/bin/bash
FILES=`find ./image/`
ZIP_PREFIX='example.com.image'
INDEX='1'
MAX_SIZE='512000' # 512 Mb
for PICT_FILE in $FILES
do
ZIP_NAME=${ZIP_PREFIX}"_"${INDEX}".zip"
ARCH_SIZE=`du -k $ZIP_NAME | cut -f 1`
# echo $ARCH_SIZE
# echo $MAX_SIZE
if [ $ARCH_SIZE -ge $MAX_SIZE ]; then
INDEX=$((INDEX + 1))
fi
ZIP_NAME=${ZIP_PREFIX}"_"${INDEX}".zip"
zip $ZIP_NAME $PICT_FILE
done
The result is:
http://example.com/example.com.image_1.zip [500Mb]
http://example.com/example.com.image_2.zip [500Mb]
http://example.com/example.com.image_3.zip [500Mb]
http://example.com/example.com.image_4.zip [227Mb]
Upvotes: 1
Reputation: 686
Here's a short script in bash that will do the trick:
#!/bin/bash
FILES=`ls *.jpg`
ZIP_PREFIX='archive'
INDEX='1'
MAX_SIZE='512'
for PICT_FILE in $FILES
do
ZIP_NAME=${ZIP_PREFIX}"_"${INDEX}".zip"
ARCH_SIZE=`du -m $ZIP_NAME | cut -f 1`
if [ $ARCH_SIZE -ge $MAX_SIZE ]; then
INDEX=`echo "$INDEX + 1" | bc`
fi
ZIP_NAME=${ZIP_PREFIX}"_"${INDEX}".zip"
zip $ZIP_NAME $PICT_FILE
done
MAX_SIZE is set in Mb
You can replace command in 'FILES' with find
or anything else that will provide you with the list of files
Upvotes: 1