zip command skip errors - linux

zip -r file.zip folder/
This is the typical command I use to zip a directory, however it is on an active site so images are constantly deleted/updated. Leading to the command failing due to a file being there when it started the process but not there when it gets to actually compressing it (at least from what I can see).
I have no option to stop the editing of the files in this case so my only hope is to just skip them, the amount of images getting edited compared to the sheer size of the directory is insigificant. so 2-3 files changing out of 100,000 is nothing, but the error stops the compression altogether.
I tried to look for a way around this, but have had no luck, could be just looking in the wrong direction but I feel that there is no way this is impossible.
Here is an example error:
zip I/O error: No such file or directory
zip error: Input file read failure (was zipping uploads/2010/03/file.jpg)
Is there some way to use the zip command or something similar to zip a folder, but if it runs into an error when it hits a file, it just skips it?

tar is always a good option to compress in Linux. Beware that zip may also have file size limit issue.
tar vcfz file.tar.gz folder

Related

how to extract files from a large (30Gb+) zip file on linux server

1) extract from large zip file
I want to extract files from a large zip file (30Gb+) on the linux server. There is enough free disk space.
I've tried jar xf dataset.zip. However, there's an error that push button is full, and it failed to extract all of the files.
I tried unzip, but zipfile corrupt.
Archive: dataset.zip
warning [dataset.zip]: 35141564204 extra bytes at beginning or within zipfile
(attempting to process anyway)
error [dataset.zip]: start of central directory not found;
zipfile corrupt.
(please check that you have transferred or created the zipfile in the
appropriate BINARY mode and that you have compiled UnZip properly)
I tried zip -FF dataset.zip --out data.zip, and there's an error that entry too big:
zip error: Entry too big to split, read, or write (Poor compression resulted in unexpectedly large entry - try -fz)
Is there anyway I can efficiently extract files from really large zip file?
2) extract certain files from a large zip file
If I only want some certain files from this large zip file, is there anyway I can extract only these files? For example, data1.txt from dataset.zip? It seems that I can't use any zip or unzip command (always have the zipfile corrupt problem).
Thanks!
I've solved the problem. It turns out to be a zip corruption problem. I first fixed the file with:
zip -FF filename1.zip --out filename2.zip -fz
then unzip the fixed zipfile:
unzip filename2.zip
and have successfully extracted all the files!
Many thanks to Fattaneh Talebi for the help!
you can extract specific file from zip
$ unzip -j "zipedfile.zip" "file.txt"
file.txt is the file you want to extract from zipedfile.zip
I had the similar kind of problem and it got solved by unar command.
unar file.zip
try extracting directories to retain control and know where you left off.
eg:
tar tv --wildcards -f siteRF.tar './Movies/*'
I tried all the steps mentioned above to unzip the file, but failed miserably.
My last resort was to copy my zip file (11.1GB) into a hard drive and unzip it using 7 zip on Windows 8 OS.
Worked like a charm :D
I also solved it in similar manner like Irene W did. It was a corrupted zip. I first fixed the file with:
zip -FF original_corrupted.zip --out fixed_file.zip -fz
then unzip the fixed zip file:
unzip fixed_file.zip

Recover a text file in linux

My project c source code file is corrupted while making the tgz of the file. I wanted to make *.tgz of 4 files. The file names are common.c common.h myfile.c and myfile.h. I mistyped the tar command. I used the following tar command by mistake
tar -cvf common.* myfile.* project.tgz
This has corrupted the common.c file. Is there any way to overcome this error?
If the file is really important, than umount the related block device, and you can look into it with the strings command. If the file contains something relatively unique, you can grep it, and if you have a little chance you can save the most of the file.
This can work with mounted block devices, but the chance of loosing the data is higher. But it works only under system's where you can access the block device directly.

How to zip folder that contains more than 12GB data

I have a requirement to zip a folder which contains large number of files.
When I tried to zip in command line, it is showing zip error: Input file read failure
I searched net and found "The .ZIP file format, only handles file lengths that can be
contained in a 32-bit integer." If so, then it must be the cause of the error I got, because my folder size is more than 12GB. Is there any way to extend the file size to be zipped.
Or is there another way to solve this?
I am using CENTOS 5.
Thanks.
You can use tar for that.
Just try:
$tar -cvzf compress.tgz /path/to/your/data
and to extract it:
$tar -xvzf compress.tgz
GZip can handle any size that your file system can handle. You might want to first "tar" the content to one file, unsing the GnuTar you can use the z option to do the compression in one go.
7Zip is also a good alternative to ZIP. It is ported to many platforms and the size limits are much higher.

Zip function junk directory paths

I'm creating a zip file by relatively specifying file locations. Here is an example of the command I'm running:
zip priv/purchases/test.zip priv/audio/5001.mp3 priv/audio/5002.mp3
When the file compresses it maintains the relative paths of the files. Thus I get a file hierarchy of:
/priv
/audio
/5001.mp3
/5002.mp3
I've read the man page and I guess I should be using the -j flag. Instead I'd like the files to be extracted at the root of the uncompressed file.
-j seems to work but it ALSO includes the file structure. Why?
Well don't I feel silly. Apparetly if you don't remove the previous directory it seems to append the files. Shoot! Haha.

Can you use tar to apply a patch to an existing web application?

Patches are frequently released for my CMS system. I want to be able to extract the tar file containing the patched files for the latest version directly over the full version on my development system. When I extract a tar file it puts it into a folder with the name of the tar file. That leaves me to manually copy each file over to the main directory. Is there a way to force the tar to extract the files into the current directory and overwrite any files that have the same filenames? Any directories that already exist should not be overwritten, but merged...
Is this possible? If so, what is the command?
Check out the --strip-components (or --strippath) argument to tar, might be what you're looking for.
EDIT: you might want to throw --keep-newer into the mix, so any locally modified files aren't overwritten. And I would suggest testing new releases on a development server, then using rsync or subversion to carry over the changes.
I tried getting --strip-components to work and, while I didn't try that hard, I didn't get it working. It kept flattening the directory structure. In searching, I came across the following command that seems to do exactly what I want:
pax -r -f patch.tar -s'/patch///'
It's not tar, but hey, it works... Replace the words "patch" with whatever your tar file name is.
The option '--strip-components' allows you to trim parts of the embedded filenames. With that it is possible to do what you want.
For more help check out http://www.gnu.org/software/tar/manual/html_section/transform.html
I have just done:
tar -xzf patch.tar.gz
And it overwrites all the files that the patch contains.
I.e., if the patch was created for the contents of the app folder, I would extract it there. Results would be like this:
tar.gz contains: oldfolder/someoldfile.txt, oldfolder/newfolder/newfile.txt
before app looks like:
app/oldfolder/someoldfile.txt
Afterwards, app looks like
app/oldfolder/someoldfile.txt
oldfolder/newfolder/newfile.txt
And the "someoldfile.txt" is actually updated to what was in the tar.gz
Maybe this doesn't work with regular tar, only tar.gz. But I doubt it. I think it should work for everything, as long as user has write permissions.

Resources