How to keep directory permissions with cpio ?

olivier

Member
Developer

Reaction score: 4
Messages: 45

Hi,

Under my NanoBSD system, I need to copy all files and directories (that are differents from a reference).
And because the destinations directories don't exist, I'm using cpio.

Here is an extract of my shell script:

Code:
(
    cd /etc
    for i in "$@" `find * -type f`
    do
        if [ -f /cfg/$i ]
        then
            cmp -s /etc/$i /cfg/$i || cp -pfv /etc/$i /cfg/$i 2>/dev/null
        else
            cmp -s /conf/base/etc/$i /etc/$i || (find $i -print | cpio -dumpv /cfg/ 2>/dev/null)
        fi
    done
)
This script compare the file between /cfg and /etc, or /conf/base/etc and /etc and copy all modified file to /cfg.

The problem is that cpio don't preserve directory permission:
Code:
[root@router]~#ls -alh /conf/base/etc | grep local
drwxr-xr-x   6 root  wheel      512B Aug 25 21:08 local
[root@router]~#ls -alh /cfg | grep local
drwx------   3 root  wheel   512B Aug 26 15:39 local
And I didn't find what cpio parameter to use for keeping permission.
I've tried to add "-depth" option to find (as reported here), but no changes.

Anyone have an idea ?

Thanks
 

vivek

Aspiring Daemon

Reaction score: 195
Messages: 805

Look at -o and -i option.

Permissions of the files will be the same as the permissions associated with the files copied out using cpio -o.
 
OP
OP
olivier

olivier

Member
Developer

Reaction score: 4
Messages: 45

I've the problem by replacing this line:
Code:
for i in "$@" `find * -type f`
by:
Code:
for i in "$@" `find * -depth`
 
Top