a4fb [Solved] How to keep directory permissions with cpio ? - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > Userland Programming & Scripting

Userland Programming & Scripting C, Shell, Perl, Sed & Awk

Reply
 
Thread Tools Display Modes
  #1  
Old August 26th, 2009, 16:47
olivier olivier is offline
Junior Member
 
Join Date: Nov 2008
Location: France
Posts: 38
Thanks: 9
Thanked 1 Time in 1 Post
Default How to keep directory permissions with cpio ?

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

Last edited by olivier; August 26th, 2009 at 21:26. Reason: solved
Reply With Quote
  #2  
Old August 26th, 2009, 16:52
vivek's Avatar
vivek vivek is offline
Member
 
Join Date: Nov 2008
Location: Hyper Space
Posts: 809
Thanks: 3
Thanked 184 Times in 102 Posts
Default

Look at -o and -i option.

Quote:
Permissions of the files will be the same as the permissions associated with the files copied out using cpio -o.
__________________
Neither in this world nor elsewhere is there any happiness in store for him who always doubts. If you enjoyed my answer please consider donating some money to FreeBSD foundation @ http://www.freebsdfoundation.org/
Reply With Quote
  #3  
Old August 26th, 2009, 21:24
olivier olivier is offline
Junior Member
 
Join Date: Nov 2008
Location: France
Posts: 38
Thanks: 9
Thanked 1 Time in 1 Post
Default

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mounting a filesystem with different permissions? wonslung General 2 June 19th, 2009 11:55
question about nullfs and permissions wonslung General 3 June 16th, 2009 08:00
NFS mounting and permissions Trojan Web & Network Services 9 May 25th, 2009 07:39
DNS and Permissions Enter4 Web & Network Services 1 February 6th, 2009 22:19
FTP ports help on permissions rowinms Web & Network Services 1 January 13th, 2009 08:37


All times are GMT +1. The time now is 08:12.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0