cancel
Showing results for 
Search instead for 
Did you mean: 

GZIP

 
Piotr Kirklewski
Super Advisor

GZIP

Hi guys

I've created a backup file with following command:

find . -depth -print | cpio -ocv | gzip > /backup/backup.cgz

Now I want to restore some files from the archive.

I was struggling with finding how can I do a partial restore.
For example I need to restore only /dev directory.
Please help

Regards

Peter
Jesus is the King
8 REPLIES
Shoghi Martinez G.
Honored Contributor

Re: GZIP

Try this:
gunzip -c /backup/backup.cgz|cpio -idx /dev/*

Please try restoring another directory before extracting the /dev, to test.
Shoghi Martinez G.
Honored Contributor

Re: GZIP

ooops no x option in linux.
Steven Schweda
Honored Contributor

Re: GZIP

> gunzip -c /backup/backup.cgz|cpio -idx /dev/*

It's hard to believe that an unquoted
wildcard like
/dev/*
on the command line would do anything like
what you want.
Stephen P. Schaefer
Frequent Advisor

Re: GZIP

When you created the backup, what was the current directory, i.e., what was "."? If that was really the command you used to create the backup, then it wasn't "/", because then the archive would attempt to include /backup/backup.cgz itself, and either generate an error when it tried to do so, or never finish. Perhaps you're leaving out parts of the find with which you excluded /backup/backup.cgz?

Anyway, you can find out the names of the files in the backup with

gunzip -c < /backup/backup.cgz | cpio -t

If you really did use "find . -depth -print", then the names will all begin with "./". Specify the directory you want to retrieve beginning with that "./", e.g.,

gzip -c < /backup/backup.cgz | cpio -i ./foo

Remember that the extracted directory will be relative to your current directory (result of pwd) when you run the command.
Piotr Kirklewski
Super Advisor

Re: GZIP

I was in / directory.

Now I'm in the same directory and I do :

rm -fr /tmp

[root@localhost /]# gunzip -c /backup/backup.cgz|cpio -id /tmp
6481003 blocks

But no /tmp directrory is created

Please advice

Regards

Peter

Jesus is the King
Steven Schweda
Honored Contributor

Re: GZIP

> But no /tmp directrory is created


> [...] you can find out the names of the
> files in the backup with
> [...]

Read that part again. Repeat as needed.
Piotr Kirklewski
Super Advisor

Re: GZIP

[root@localhost /]# gzip -c < /backup/backup.cgz | cpio -i ./tmp
cpio: warning: skipped 49742 bytes of junk
cpio: warning: skipped 15654 bytes of junk
cpio: premature end of file
Jesus is the King
Brendan Peter Murphy
Occasional Advisor

Re: GZIP

xref Stephen Scheafer : "the archive would attempt to include /backup/backup.cgz itself, and either generate an error when it tried to do so, or never finish."

Looks like you're cpio archive didn't complete properly. Are you sure you didn't see warning/error messages when backing up or is the backup line you quote in a cron script directing messages to /dev/null?

I tend to prefer using tar myself. It has gzip and bzip2 functionality built into it, so the backup line you use above would look something like this:

GZIP
# tar -czvf /backup/backup.tgz .

BZIP2
# tar -cjvf /backup/backup.tbz2 .

Again you need to ensure that the archive file being created is not part of the directory structure being archived otherwise you have problems.