Solved

how to use cpio to unzip file

Posted on 2013-01-04
30
523 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
  • 19
  • 10
30 Comments
 
LVL 13

Assisted Solution

by:Alexios
Alexios earned 25 total points
Comment Utility
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
Comment Utility
cpio -i "*Freight Survey Totals.xls*" < archivefile.cpio
0
 

Author Comment

by:Jason Yu
Comment Utility
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
 

Author Comment

by:Jason Yu
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I couldn't find the unzipped file, there is no new directory under current directory.
0
 
LVL 68

Expert Comment

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

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

Author Comment

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

Author Comment

by:Jason Yu
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No problem. cpio will not lock its input file.
0
 

Author Comment

by:Jason Yu
Comment Utility
The result is like this:

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

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Jason Yu
Comment Utility
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
Comment Utility
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
Comment Utility
This command finished:

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

Author Comment

by:Jason Yu
Comment Utility
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
Comment Utility
what does the output number mean? Like this one

131363044 blocks
0
 

Author Comment

by:Jason Yu
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
got it solved, thank you.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now