LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-18-2009, 11:41 AM   #1
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Can cpio copy symlinks and preserve the modification time?


Hello

I tried using cpio to make an exact copy of files to another directory
Code:
find . -depth -print0 | cpio --null -pmvd <target directory>
The man page says the -m option will "Restore modification times of extracted files to those given in the archive".

The source directories (/etc/rc.[0-6S].d in turn) contain symbolic links and an ordinary file. After running the command, the modification times on all the symlinks in <target directory> was the time the command was run.

Can cpio copy symlinks and preserve the modification time?

Code:
$ cpio --version
cpio (GNU cpio) 2.9
Best

Charles
 
Old 08-16-2009, 05:56 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,358
Blog Entries: 55

Rep: Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545
Quote:
Originally Posted by catkin View Post
After running the command, the modification times on all the symlinks in <target directory> was the time the command was run. (..) Can cpio copy symlinks and preserve the modification time?
Symbolic links in /etc/rc[0-6].d (subtle difference) are relative ones as far as I know, so when you copy the files they point to then the MAC times of those files will have changed?
 
Old 08-17-2009, 03:03 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Original Poster
Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Hello unSpawn

Thanks for you reply -- I'd give up hope on this one!

Yes -- in the specific case of /etc/init[S0-9].d/ symlinks, they are relative.

I'm using /bin/ls to display symlink modification time so it really is the modification time of the symlink (as opposed to Nautilus that shows the modification time of the symlink target).

In testing, I copied the targets in the same find and cpio pipe; their modification times were preserved as expected.

Best

Charles
 
Old 08-17-2009, 07:36 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,358
Blog Entries: 55

Rep: Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545
Quote:
Originally Posted by catkin View Post
I'd give up hope on this one!
I'm doing a NTLB run.


Quote:
Originally Posted by catkin View Post
Can cpio copy symlinks and preserve the modification time?
As far as I can see preserving completely MAC times on files yes but symlinks no (but I only tried afio, cpio and rsync not tar or cp). My 'man 2 lstat', 'man readlink' and 'man symlink' are not to clear about standards but this, Red Hat Bugzilla Bug 230866 (cp: utimes: see comment #6 From Tim Waugh) and Debian Bug 313237 (tar: utimensat patch) show solutions vary (...is likely not the answer you're looking for ;-p).
 
Old 08-17-2009, 09:33 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Original Poster
Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
NTLB?

Thanks for the links.

dar restores symlink (and directory) modification times but not access times.

Your research suggests that the problem arises because there are no syscalls to set timestamps on the new symlinks as we would like. That was true until kernel 2.6.22 which introduced support for the lutimes() syscall but the utilities we have been using have not been re-written to take advantage of it.

Here's some history FWIW.

Symlinks were introduced in BSD 4.3 but netsearching didn't find anything about the design philosophy or discussion. I guess it was before RFCs, public debate and published committee decisions. Maybe symlinks were thought of as simply "pointers" so things like timestamps and permissions were irrelevant -- which would have been OK except symlinks were implemented using the existing inode data structure so symlinks got all the inode data including timestamps.

Permissions were especially daft because they were set but ignored. I vaguely recall that some OSes used to set permissions but later versions of the same OSes enforced 777 which was less misleading.

Last edited by catkin; 08-17-2009 at 09:35 AM. Reason: Removed tosh about atimes
 
Old 08-17-2009, 10:17 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,358
Blog Entries: 55

Rep: Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545
Quote:
Originally Posted by catkin View Post
NTLB?
Meaning "No Thread Left Behind" as our fellow LQ member "rerushg" defined it.
I'm just trawling through the backlog queue in search of interesting posts.


Quote:
Originally Posted by catkin View Post
Your research suggests that the problem arises because there are no syscalls to set timestamps on the new symlinks as we would like.
If I read the posts right then it's more about POSIX not mandating coverage of all struct items for slinks.


Quote:
Originally Posted by catkin View Post
That was true until kernel 2.6.22 which introduced support for the lutimes() syscall but the utilities we have been using have not been re-written to take advantage of it.
Well that is good to know!


Quote:
Originally Posted by catkin View Post
Symlinks were introduced in BSD 4.3
One source suggests Unix 4.2BSD as does 'man 1 ln' (couldn't find 'man 2 lstat') for 4.3BSD Reno (couldn't find 4.2BSD either ;-p).
I'm glad we don't have to go into parallel universes like "design philosophy" vs reality ;-p

Last edited by unSpawn; 08-17-2009 at 10:34 AM. Reason: //more *is* more
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change modification time/time created recursively?? Drigo Linux - Newbie 4 08-05-2009 07:45 AM
Tar: Preserve file creation/modification date Sum1 Linux - Software 2 05-15-2009 03:50 PM
cpio doesn't have -P (available on solaris) option which preserve ACL's RAJCHAND094 Linux - Software 3 06-26-2008 11:50 AM
Make KDE/Konqueror preserve time, ownership on file copy tisource Linux - Software 2 06-27-2006 01:23 PM
Heeelp! How to preserve file date modification attribute Slackovado Slackware 1 03-30-2005 09:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration