Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Appending files to a cpio archive with gzip

2,583 views
Skip to first unread message

brumik

unread,
Nov 4, 2012, 1:26:10 PM11/4/12
to
I need to append files to an existing cpio archive and use gzip but
found out the second bit is not appending how I want: e.g. for
simplicity sake:

# mkdir test
# mkdir test1

# find test | cpio -o | gzip -c > /var/tmp/cpio.gz

1 blocks

I then append test1 to the archive:

# find test1 | cpio -o | gzip -c >> /var/tmp/cpio.gz
1 blocks

Resulting archive is only the first file is added, second one was
ignored:

# cpio -itv < cpio
drwx------ 2 root root 0 Nov 4 18:14 2012, test
2 blocks

Is there any special trick? I tried the -A for append option with gzip
but it expects a file and requires -O option.
I need to use find and cpio as I have a complex search pattern to
build filelist to backup.

Thanks

Barry Margolin

unread,
Nov 4, 2012, 3:09:40 PM11/4/12
to
In article
<1c3b7dcb-ecbd-48d6...@g8g2000yqp.googlegroups.com>,
You can't append to an existing compressed file. You have to decompress
it, add to that, and then recompress.

The fact that it contains a cpio archive is irrelevant -- this is just
the nature of the gzip file format.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Kenny McCormack

unread,
Nov 4, 2012, 3:21:21 PM11/4/12
to
In article <barmar-18FAF5....@news.eternal-september.org>,
Barry Margolin <bar...@alum.mit.edu> wrote:
...
>You can't append to an existing compressed file. You have to decompress
>it, add to that, and then recompress.

Oopsie!

From "man gzip":

ADVANCED USAGE
Multiple compressed files can be concatenated. In this case, gunzip
will extract all members at once. For example:

gzip -c file1 > foo.gz
gzip -c file2 >> foo.gz

Then

gunzip -c foo

is equivalent to

cat file1 file2

Whether this works with tar and/or cpio (or any other archiving format) is,
of course, a function of the particular archiver format chosen.

>The fact that it contains a cpio archive is irrelevant -- this is just
>the nature of the gzip file format.

Actually, as you now see, it does matter.

--

First of all, I do not appreciate your playing stupid here at all.

- Thomas 'PointedEars' Lahn -

Barry Margolin

unread,
Nov 4, 2012, 11:20:16 PM11/4/12
to
In article <k76io1$v7k$1...@news.xmission.com>,
gaz...@shell.xmission.com (Kenny McCormack) wrote:

> In article <barmar-18FAF5....@news.eternal-september.org>,
> Barry Margolin <bar...@alum.mit.edu> wrote:
> ...
> >You can't append to an existing compressed file. You have to decompress
> >it, add to that, and then recompress.
>
> Oopsie!
>
> From "man gzip":
>
> ADVANCED USAGE
> Multiple compressed files can be concatenated. In this case, gunzip
> will extract all members at once. For example:
>
> gzip -c file1 > foo.gz
> gzip -c file2 >> foo.gz
>
> Then
>
> gunzip -c foo
>
> is equivalent to
>
> cat file1 file2
>
> Whether this works with tar and/or cpio (or any other archiving format) is,
> of course, a function of the particular archiver format chosen.
>
> >The fact that it contains a cpio archive is irrelevant -- this is just
> >the nature of the gzip file format.
>
> Actually, as you now see, it does matter.

Oops, sorry.

So the question then is whether you can append one cpio archive onto
another. Because your original attempt is effectively equivalent to:

( find test | cpio -o; find test1 | cpio ) | gzip -c

brumik

unread,
Nov 5, 2012, 2:50:47 AM11/5/12
to
On Nov 5, 4:20 am, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article <k76io1$v7...@news.xmission.com>,
>  gaze...@shell.xmission.com (Kenny McCormack) wrote:
>
>
>
>
>
>
>
>
>
> > In article <barmar-18FAF5.15094004112...@news.eternal-september.org>,
I tried this but still cant get it to work, by example I want to
archive all files in dir1, but only directories in dir2 to the
archive:

# find . | sort
.
./dir1
./dir1/testfile
./dir2
./dir2/dir_to_backup
./dir2/dont_backup_file

# ( find dir1 | cpio -ov; find dir2 -type d | cpio -ov ) | gzip -c > /
var/tmp/testarchive.cpio.gz
dir1
dir1/testfile
1 blocks
dir2
dir2/dir_to_backup
1 blocks

# gzip -dc /var/tmp/testarchive.cpio.gz | cpio -it
dir1
dir1/testfile
1 blocks

As we see only dir1 was archived, unfortunately despite many tries I
cant find a way to use the find command (solaris) to find all given
files in a directory but *only* print directory names under dir2 (in
one command), hence was using two find commands,





Geoff Clare

unread,
Nov 5, 2012, 8:57:39 AM11/5/12
to
The latest POSIX standard requires find to support -path, which would
allow you to use one find command. (I'm not sure if Solaris 11 supports
it - I have access to a Solaris 11 system but it appears to be down
at the moment - but maybe you're using an older Solaris release anyway.)

find dir1 dir2 -path 'dir2/*' ! -type d -o -print

In any case, you can do what you want with two find commands as long
as you only use one cpio command:

( find dir1; find dir2 -type d ) | cpio -ov | gzip -c > ......

--
Geoff Clare <net...@gclare.org.uk>

Barry Margolin

unread,
Nov 5, 2012, 10:43:11 AM11/5/12
to
In article
<0e3ecfd7-cdb0-4e13...@j12g2000vbm.googlegroups.com>,
> I tried this but still cant get it to work

Of course it doesn't work. I said it's equivalent to what you originally
tried, so it fails for the same reason: you can't append cpio archives
to each other.

brumik

unread,
Nov 5, 2012, 10:46:23 AM11/5/12
to
On Nov 5, 2:11 pm, Geoff Clare <ge...@clare.See-My-Signature.invalid>
wrote:
> Geoff Clare <netn...@gclare.org.uk>

Its Solaris 10 I'm on so its not available.

However your method worked just fine, thank you.
0 new messages