LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 07-25-2009, 01:22 PM   #1
megalosaurus
LQ Newbie
 
Registered: Jul 2009
Posts: 5

Rep: Reputation: 0
How to preserve all timestamps while copying files


I need to copy a directory from one place to another. I want all the files, both in the source and the destination, to have the Access, Modify, and Change timestamps they had before I began the copy. I've found that cp, rsync, and tar each offer options that preserve some of the timestamps, but I can't find a way to preserve all of them. Doing a disk image copy is not an option. The directory has 3 million files spread out over tens of thousands of subdirectories going 20 levels deep, so anything that handles files individually is not practical. Does anyone know of a solution?
 
Old 07-25-2009, 01:34 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
Quote:
Originally Posted by megalosaurus View Post
Doing a disk image copy is not an option. The directory has 3 million files spread out over tens of thousands of subdirectories going 20 levels deep, so anything that handles files individually is not practical.
So this is a separate issue. Your post seems more to be about just how to mirror data or something right? So, there are only a few layers in the storage stack to begin with, and you need to chose where you'll copy: block level? volume? filesystem? by file?

rsync -a sounds to do what you want.

If that looks like it'll be too slow, then I'd say just dd the source device to the target device. why is that not an option?
 
Old 07-25-2009, 02:47 PM   #3
megalosaurus
LQ Newbie
 
Registered: Jul 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Both directories are about 200 GB within a multi-terabyte filesystem, so dd won't work.

I've tried rsync -a. It leaves the timestamps on the source files unchanged, but updates the Access and Change timestamps on the destination.
 
Old 07-25-2009, 02:48 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can preserve the access and modify time, but not the change time, since whenever you copy a file a new inode is created.
 
Old 07-26-2009, 05:09 PM   #5
megalosaurus
LQ Newbie
 
Registered: Jul 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
You can preserve the access and modify time, but not the change time, since whenever you copy a file a new inode is created.
OK - I guess I could live with that if that's the way it has to be. But it also changes the access timestamp at the destination. If I use cp -p, it won't change the access timestamp at the destination, but it changes it at the source. Seems like you just can't win.
 
Old 07-27-2009, 12:24 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by megalosaurus View Post
But it also changes the access timestamp at the destination. If I use cp -p, it won't change the access timestamp at the destination, but it changes it at the source. Seems like you just can't win.
It looks like cpio does the trick:
Code:
<commands> | cpio -p --reset-access-time --preserve-modification-time /path/to/dest/dir
the list of files to copy has to be created and passed as standard input.
 
Old 07-27-2009, 01:47 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Using tar to replicate preserves the mtime and atime:
Code:
> tar -C work/ -cf - home.png | ssh hpmedia 'tar -C rsynctest -xvf - home.png'
home.png
ssh hpmedia stat rsynctest/home.png
  File: `rsynctest/home.png'
  Size: 4624            Blocks: 24         IO Block: 4096   regular file
Device: 831h/2097d      Inode: 7676168     Links: 1
Access: (0640/-rw-r-----)  Uid: ( 1000/jschiwal)   Gid: ( 1000/jschiwal)
Access: 2009-07-27 01:44:21.000000000 -0500
Modify: 2009-07-27 01:41:42.000000000 -0500
Change: 2009-07-27 01:44:21.000000000 -0500
jschiwal@qosmio:~> stat work/home.png
  File: `work/home.png'
  Size: 4624            Blocks: 16         IO Block: 4096   regular file
Device: 807h/2055d      Inode: 1114126     Links: 1
Access: (0640/-rw-r-----)  Uid: ( 1000/jschiwal)   Gid: ( 1000/jschiwal)
Access: 2009-07-27 01:44:21.000000000 -0500
Modify: 2009-07-27 01:41:42.000000000 -0500
Change: 2009-07-27 01:41:42.000000000 -0500
 
Old 07-31-2009, 10:34 AM   #8
megalosaurus
LQ Newbie
 
Registered: Jul 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
Using tar to replicate preserves the mtime and atime:
It's copying the atime from the source to the destination, but it's still updating the atime at the source before it begins.
 
Old 07-31-2009, 10:36 AM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You are right, I should have included the --atime-preserve option.
 
Old 07-31-2009, 10:56 AM   #10
megalosaurus
LQ Newbie
 
Registered: Jul 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
It looks like cpio does the trick:
Code:
<commands> | cpio -p --reset-access-time --preserve-modification-time /path/to/dest/dir
the list of files to copy has to be created and passed as standard input.
cpio changes the ctime at the source and destination.
 
Old 07-31-2009, 11:11 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Just out of curiosity, why are you so concerned about change time? It is related to the inode and it is transparent to many commands, which on the contrary refer to the modification and/or the access time to work properly.
 
Old 07-11-2015, 03:57 PM   #12
Doctor_Pi
LQ Newbie
 
Registered: Jul 2015
Posts: 1

Rep: Reputation: Disabled
Dump and Restore?

I believe Dump and Restore will preserve all timestamps.

Ivan.
 
Old 07-13-2015, 05:19 AM   #13
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
"rsync -a" too.
 
  


Reply



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
Timestamps, VSFTP, Samba & files edited on a server dsackett Linux - Newbie 3 11-24-2008 01:10 PM
Help - My Samba share changes the timestamp when copying files to it.. Preserve Time. hheejj Linux - Software 2 06-28-2005 09:34 AM
preserve user/group when copying files km4hr Linux - Software 1 01-11-2005 05:21 PM
Preserve file permissions when copying from NTFS to a Samba share? somedude Linux - Software 4 06-11-2004 09:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 01:19 PM.

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
Open Source Consulting | Domain Registration