Avatar of Jason Yu
Jason Yu
Flag for United States of America asked on

how to use cpio to unzip file

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
LinuxStorage Software

Avatar of undefined
Last Comment
Jason Yu

8/22/2022 - Mon
SOLUTION
Alexios

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
woolmilkporc

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jason Yu

ASKER
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.
Jason Yu

ASKER
for the above command, where is the unzipped file after running/

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

Thank you.
woolmilkporc

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Jason Yu

ASKER
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.
Jason Yu

ASKER
I couldn't find the unzipped file, there is no new directory under current directory.
woolmilkporc

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

cpio -idv "*Freight Survey Totals.xls*" < archivefile.cpio
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Jason Yu

ASKER
Ok, I am rerunning it. Hope this time it works.
Jason Yu

ASKER
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.
woolmilkporc

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?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Jason Yu

ASKER
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.
Jason Yu

ASKER
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?
woolmilkporc

No problem. cpio will not lock its input file.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Jason Yu

ASKER
The result is like this:

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

ASKER
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]$
woolmilkporc

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?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Jason Yu

ASKER
This command finished:

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

ASKER
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.
Jason Yu

ASKER
what does the output number mean? Like this one

131363044 blocks
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Jason Yu

ASKER
it looks like this time got some files unzipped. It shows some files with "freight" in the file names.
Jason Yu

ASKER
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
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
woolmilkporc

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Jason Yu

ASKER
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.
Jason Yu

ASKER
From the output, it looks like all the recoverried files were written back to their original position, am I right?
woolmilkporc

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!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Jason Yu

ASKER
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.
woolmilkporc

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
Jason Yu

ASKER
got it solved, thank you.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23