1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to keep directory permissions with cpio ?

Discussion in 'Userland Programming and Scripting' started by olivier, Aug 26, 2009.

  1. olivier

    olivier New Member

    Messages:
    40
    Likes Received:
    0
    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
     
  2. vivek

    vivek New Member

    Messages:
    809
    Likes Received:
    0
    Look at -o and -i option.

     
  3. olivier

    olivier New Member

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