Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cpio explanation required

Status
Not open for further replies.

grega

Programmer
Feb 2, 2000
932
GB
Maybe someone can explain this ...

I have taken a full backup of a server using find . -print -depth | cpio -ocB > /dev/rmt/0

I can do a full restore using cpio -icvdumB -I /dev/rmt/0

Let's say I only want to restore /home/user1/* and /home/user2/*

1st way to do this is to say cpio -icvdumB -I /dev/rmt/0 "/home/user1/*" "/home/user2/*"

This works fine.

Now, lets say I have a script to do the restore ...
Code:
#!/bin/ksh
RES_LIST="/home/user1/* /home/user2/*"
cpio -icvdumB -I /dev/rmt/0 ${RES_LIST}
This doesn't work, and I reckon it's because of the syntax which cpio requires when specifying patterns to restore. So I try this ...
Code:
#!/bin/ksh
RES_LIST="\"/home/user1/*\" \"/home/user2/*\""
cpio -icvdumB -I /dev/rmt/0 ${RES_LIST}
Now, I would expect this to work, because when using set -x to run the script, the command is exactly the same as the 1st one I used above from the command line. However, this doesn't work :-( Aaaaaargh!

The *only* way I have achieved what I want, is to put a list of all the directories I want to restore in a control file (1 directory per line) and doing

cpio -icvdumB -I /dev/rmt/0 -E /path/to/control/file

This works a treat :)

Now, this isn't a problem but I was wondering if anyone can explain why what should work doesn't! In practive I'll want to restore a lot more than 2 user directories.

BTW, all this is done on Solaris, but will be implemented on SCO - should there be any difference, given cpio is "native"?

Greg.
 
I'm suprised the first one works....
when using the find command with a "." the resulting list of files should be listed as "relative" (ie with a ./path/filename) which I would not expect cpio to match with a path that starts with a / or an "absolute" reference

the other problem could be that you would need to escape the asterisks
RES_LIST="\"/home/user1/\*\" \"/home/user2/\*\""

unix42
 
You're right about the 1st one, and I understand the difference between doing a find . ... cpio and a find /home .... cpio. I just explained what I did badly!

As for escaping the asterisks, I've tried that too. That's why I was using set -x during execution to make sure the shell wasn't expanding the *.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top