Solved

how to use cpio to unzip file

Posted on 2013-01-04
30
528 Views
Last Modified: 2013-01-07
Dear experts here;

I got a request from my coworker to retrieve one lost file from a backup archive.  when i check the archive, it's a big file with 67 GB, and the file ended with .cpio. How could I unzip this file and retrieve a file called Freight Survey Totals.xls (the original path of the file is  /u1/shares/ncshare/Freight Survey Totals.xls) Thank you a lot.

I am waiting for solution online, please help.


[root@triton DACS]# ls -l
total 65681548
-rw-rw-r-- 1 dacs dacs 67257892864 Dec 18 00:06 ncdacs2_20121217223057.cpio
drwxr-xr-x 2 root root        4096 Jan  4 13:23 tmp
0
Comment
Question by:Jason Yu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 19
  • 10
30 Comments
 
LVL 13

Assisted Solution

by:Alexios
Alexios earned 25 total points
ID: 38745338
Hello

to extract to the same directory use command as follows

cpio -icvdu < .cpio
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 475 total points
ID: 38745364
cpio -i "*Freight Survey Totals.xls*" < archivefile.cpio
0
 

Author Comment

by:Jason Yu
ID: 38745418
Hi, woolmilkporc:

i am running your command now, it looks like it's running there. but nothing displayed on the screen yet. I will leave it there. Hopefully, after 40 minutes, it can finish.

Ordinarily speaking, How long does it take to unzip a file from an archive of 67 G ?

Thank you , Kostasp and woolmilkporc for your timely reply. I am really appreciating your posts here. That's the reason I love EE.com.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:Jason Yu
ID: 38745424
for the above command, where is the unzipped file after running/

cpio -i "*Freight Survey Totals.xls*" < archivefile.cpio

Thank you.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38745449
It should have retained its original path, but with the leading "/" stripped, i. e. relative to your current directory:

/current/directory/u1/shares/ncshare/Freight Survey Totals.xls

I think you should repeat the extraction with "-v" specified, so you can see what cpio does.

cpio -iv "*Freight Survey Totals.xls*" < archivefile.cpio

If you're unsure  about the filename (spelling) try

cpio -ivt < archivefile.cpio

so you'll get a table of contents.
0
 

Author Comment

by:Jason Yu
ID: 38745484
it finished, with the result as below:

[root@triton DACS]# cpio -i "*Freight Survey Totals.xls*" < ncdacs2_20121217223057.cpio
131363044 blocks



I am looking for the restored file.
0
 

Author Comment

by:Jason Yu
ID: 38745488
I couldn't find the unzipped file, there is no new directory under current directory.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38745495
Yes, sorry, you must use the "-d" ("--make-directories") flag:

cpio -idv "*Freight Survey Totals.xls*" < archivefile.cpio
0
 

Author Comment

by:Jason Yu
ID: 38745502
Ok, I am rerunning it. Hope this time it works.
0
 

Author Comment

by:Jason Yu
ID: 38745542
it finished showing the result as below;

[root@triton DACS]# cpio -idv "*Freight Survey Totals.xls*" < ncdacs2_2012121722                                                                                                                     3057.cpio
131363044 blocks


but I still didn't find the upzipped file and folder. Please advise.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38745567
Please check the cotents of your archive.

cpio -ivt < ncdacs2_20121217223057.cpio

This will probably give too much output, so use something like "grep -i Survey" to filter:

cpio -ivt < ncdacs2_20121217223057.cpio | grep -i Survey

Once you found the file, use its full name to extract it.

The fact that it didn't work up to now could also be related to the spaces in the filename. I, personally, never have spaces in filenames (but I don't have to deal with Windows clients either).

If this is the culprit something like the following could help:

cpio -idv "*Freight*Survey*Totals.xls*" < ncdacs2_20121217223057.cpio

But before we continue - what's in the table of contents?
0
 

Author Comment

by:Jason Yu
ID: 38745581
I am running the above command now. I don't like to use space in file names too, my coworkers, those wharehouse people, you know them. :)

I hope this time i will get luck.
0
 

Author Comment

by:Jason Yu
ID: 38745593
can I open two putty sessions and run the above two commands at the same time.

I really want to see the result. If both sessions access the same file, will that be the problem?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38745600
No problem. cpio will not lock its input file.
0
 

Author Comment

by:Jason Yu
ID: 38745603
The result is like this:

[root@triton DACS]# cpio -ivt < ncdacs2_20121217223057.cpio | grep -i Survey
131363044 blocks
0
 

Author Comment

by:Jason Yu
ID: 38745620
when I check the folders, I see this, do you think these are unzipped files?

[mis@triton DACS]$ ls -l
total 93104480
-rw-rw-r-- 1 dacs dacs 22960521903 Oct 13 00:31 ncdacs2_20121012223052.cpio.gz
-rw-rw-r-- 1 dacs dacs  9601408282 Jan  1 02:38 ncdacs2_20121231223503.cpio.gz
-rw-rw-r-- 1 dacs dacs 19793141418 Jan  2 07:32 ncdacs2_20130101223444.cpio.gz
-rw-rw-r-- 1 dacs dacs 19704611095 Jan  3 00:03 ncdacs2_20130102223047.cpio.gz
-rw-rw-r-- 1 dacs dacs 23279272596 Jan  4 00:25 ncdacs2_20130103223058.cpio.gz
[mis@triton DACS]$
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38745631
These are old and not so old manually gzipped cpio archives. cpio  does not zip/unzip on its own.

There is no file containing the string "Survey" in your archive.

Let's hope that the file has been written to the archive at all (spaces?).

What do you get with

cpio -ivt < ncdacs2_20121217223057.cpio | grep -i Freight

And please display the whole toc (without "| grep ...", that is). What do you see?
0
 

Author Comment

by:Jason Yu
ID: 38745641
This command finished:

[root@triton DACS]# cpio -idv "*Freight*Survey*Totals.xls*" < ncdacs2_2012121722
131363044 blocks
0
 

Author Comment

by:Jason Yu
ID: 38745652
Can we use this file:

-rw-rw-r-- 1 dacs dacs  9601408282 Jan  1 02:38 ncdacs2_20121231223503.cpio.gz

I think this backup is very new and it's just three days before the file lost.

Could we unzip this file and see if the lost file is there?

Thanks.
0
 

Author Comment

by:Jason Yu
ID: 38745661
what does the output number mean? Like this one

131363044 blocks
0
 

Author Comment

by:Jason Yu
ID: 38745667
it looks like this time got some files unzipped. It shows some files with "freight" in the file names.
0
 

Author Comment

by:Jason Yu
ID: 38745685
It indeed unzipped some files, but not the files they lost. That means this archive doesn't have this file backuped up, right?

[root@triton DACS]# cpio -idv "*Freight*Survey*Totals.xls*" < ncdacs2_2012121722
131363044 blocks
[root@triton DACS]# ^C
[root@triton DACS]# cpio -ivt < ncdacs2_20121217223057.cpio | grep -i Freight
-rw-rw----   1 201      users      111872 Mar  1  2012 u3/u4backup/datacoll/obj/                                                                                                                     old/freight1.cob
-rw-rw----   1 201      users      111872 Mar  1  2012 u3/u4backup/datacoll/obj/                                                                                                                     old/freight1p.cob
-rw-rw----   1 201      users      111872 Mar  1  2012 u3/u4backup/datacoll/obj/                                                                                                                     freight1.cob
-rw-rw----   1 201      users      112128 Mar  1  2012 u3/u4backup/datacoll/obj/                                                                                                                     freight1p.cob
-rw-rw----   1 10005    10003        9456 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightCarriers.frm
-rw-rw----   1 10005    10003        9211 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightCharges.frm
-rw-rw----   1 10005    10003        9239 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightDestinations.frm
-rw-rw----   1 10005    10003        9220 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightMethods.frm
-rw-rw----   1 10005    10003        9344 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightProNumbers.frm
-rw-rw----   1 10005    10003        9168 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightRates.frm
-rw-rw----   1 10005    10003        9066 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightServices.frm
-rw-rw----   1 10005    10003        9216 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightZones.frm
-rw-r-----   1 10004    ftp         54410 Sep 27  2005 u3/u4backup/spnotes/Custo                                                                                                                     mer_Special_Instructions/Eldorado_Furniture/Shipping_Instructions/Freight.pdf
-rw-r-----   1 10004    ftp        757167 Sep 27  2005 u3/u4backup/spnotes/Custo                                                                                                                     mer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Grea                                                                                                                     t_Indoors\ (Direct_To_Store\ -\ freight\ collect).pdf
-rw-r-----   1 10004    ftp        765479 Sep 27  2005 u3/u4backup/spnotes/Custo                                                                                                                     mer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Grea                                                                                                                     t_Indoors\ (Direct_To_Warehouse\ -\ freight\ collect\ &\ prepaid).pdf
-rw-r-----   1 10004    ftp       1151137 Sep 27  2005 u3/u4backup/spnotes/Custo                                                                                                                     mer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Grea                                                                                                                     t_Indoors\ (RRC\ -\ freight\ collect).pdf
-rw-rw----   1 10001    10001      111872 Sep 26  2010 u3/u4backup/testcoll/obj/old/freight1.cob
-rw-rw----   1 10001    10001      111872 Sep 26  2010 u3/u4backup/testcoll/obj/old/freight1p.cob
-rw-rw----   1 10001    10001      111872 Mar  1  2012 u3/u4backup/testcoll/obj/freight1.cob
-rw-rw----   1 10001    10001      112128 Mar  1  2012 u3/u4backup/testcoll/obj/freight1p.cob
-rw-rw----   1 201      users      110848 May 25  2006 u4/datacoll/obj/old/freight1.cob
-rw-rw----   1 201      users      111104 Feb 27  2007 u4/datacoll/obj/old/freight1p.cob
-rw-rw----   1 201      users      111872 Sep 26  2010 u4/datacoll/obj/freight1.cob
-rw-rw----   1 201      users      111872 Sep 26  2010 u4/datacoll/obj/freight1p.cob
-rw-rw----   1 10001    10001      111616 Jun  1  2010 u4/testcoll/obj/old/freight1.cob
-rw-rw----   1 10001    10001      111616 Jun  1  2010 u4/testcoll/obj/old/freight1p.cob
-rw-rw----   1 10001    10001      111872 Sep 26  2010 u4/testcoll/obj/freight1.cob
-rw-rw----   1 10001    10001      111872 Sep 26  2010 u4/testcoll/obj/freight1p.cob
-rw-r-----   1 10004    ftp         54410 Sep 27  2005 u4/spnotes/Customer_Special_Instructions/Eldorado_Furniture/Shipping_Instructions/Freight.pdf
-rw-r-----   1 10004    ftp        757167 Sep 27  2005 u4/spnotes/Customer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Great_Indoors\ (Direct_To_Store\ -\ freight\ collect).pdf
-rw-r-----   1 10004    ftp       1151137 Sep 27  2005 u4/spnotes/Customer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Great_Indoors\ (RRC\ -\ freight\ collect).pdf
-rw-r-----   1 10004    ftp        765479 Sep 27  2005 u4/spnotes/Customer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Great_Indoors\ (Direct_To_Warehouse\ -\ freight\ collect\ &\ prepaid).pdf
-rw-rw----   1 10005    10003        9456 Feb 21  2007 u4/mysql/data21/prod/FreightCarriers.frm
-rw-rw----   1 10005    10003        9211 Feb 21  2007 u4/mysql/data21/prod/FreightCharges.frm
-rw-rw----   1 10005    10003        9239 Feb 21  2007 u4/mysql/data21/prod/FreightDestinations.frm
-rw-rw----   1 10005    10003        9220 Feb 21  2007 u4/mysql/data21/prod/FreightMethods.frm
-rw-rw----   1 10005    10003        9344 Feb 21  2007 u4/mysql/data21/prod/FreightProNumbers.frm
-rw-rw----   1 10005    10003        9168 Feb 21  2007 u4/mysql/data21/prod/FreightRates.frm
-rw-rw----   1 10005    10003        9066 Feb 21  2007 u4/mysql/data21/prod/FreightServices.frm
-rw-rw----   1 10005    10003        9216 Feb 21  2007 u4/mysql/data21/prod/FreightZones.frm
131363044 blocks
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 475 total points
ID: 38745687
Ok, three questions, three answers.

1) Yes, you can use that file.

gunzip ncdacs2_20121231223503.cpio.gz

cpio -idv ...  

2) The number means that your archive consists of that many blocks, roundabout 63 GB3

3) What do you mean with "unzipped?" cpio cannot zip/unzip. What was the exact command you used? If you used the "-t" flag you saw the file entires, but you didn't extract them.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38745692
4) Yes, the file is not there. Seems there is nothing from /u1/... present at all.

Seems you have some special script in place to create the archive which prepends a backslash to the spaces in filenames.

So, if the file were present, this format "*Freight*Survey*Totals.xls" should  have done the trick.
0
 

Author Comment

by:Jason Yu
ID: 38745706
yes, thank you very much. Since the office in North Carolinze have to close now, I have to ask them to switch the tape out because I don't want to this archive be overwritten. I have to keep working on this next Monday.

But i really feel moved by your help. I should treat you for a dinnder for this work.

I am in Los Angeles, CA. my email is condescendent@gmail.com. Give me an email when you have time. I want to make friends with you.
0
 

Author Comment

by:Jason Yu
ID: 38745724
From the output, it looks like all the recoverried files were written back to their original position, am I right?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38745739
No. Two things:

1) You used the -t flag, which means "table of contents". So nothing was written, you just saw the list of files contained in the archive.

2) Please note the missing leading slash. e. g. in "u4/mysql/data21/prod/FreightZones.frm"

So even if the files had been written (they haven't!) their new position would be relative to your current directory, so if you were in /tmp you would have written "/tmp/u4/mysql/data21/prod/FreightZones.frm". Got the difference? But once more, nothing has been written!
0
 

Author Comment

by:Jason Yu
ID: 38745756
thank you very much, woolmilkporc, I learned a lot.


I have to go to lunch now, it's 3:32 PM. here in CA. It's a really nice experience to working with you. I hope you have a wonderful weekend.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38745769
OK,

it's 0:38 AM (Saturday) here in Ol' Europe.

Enjoy your meal, and have a nice weekend, too.

Always glad to help

wmp
0
 

Author Closing Comment

by:Jason Yu
ID: 38753098
got it solved, thank you.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question