Jump to content

Fun times with tar


Recommended Posts

I've had a google around for this problem, and have come up with nothing.

 

I was looking for a shortcut way of identifying and copying the dozen or so files I have modified this weekend onto a thumbdrive, so I can take them back to work Monday morning.

 

"Sounds like a 5 minute job using tar", I thought, ignoring the giggles from the demons of stupidity lining up behind me at the sound of the magic phrase "5 minute job".

 

Well, tar will quite happily back up either all my files in the directory and subdirectories, regardless of date, or it will archive nothing at all.

 

Here's my tar command line (all on one line, of course):

tar 
   --create --file=archive.tar.gz 
   --gzip 
   --exclude=out --exclude=*/.svn --exclude=*~ --exclude=*.tar.gz 
   --newer=2005-06-11 
   --verbose *

(Yes, those excludes do point to the fact that I use subversion as a RCS at home - excellent tool, BTW.)

 

Here's a partial listing of the files in one of the folders I am trying to back up - this is the root of the hierarchy:

$ ls -l
total 95
-rwxr-xr-x   1 sean sean  1552 May 27 12:50 autobuild.bat*
-rwxr-xr-x   1 sean sean  1225 Apr  4 18:56 autobuild.properties*
-rwxr-xr-x   1 sean sean 15977 May 27 17:01 autobuild.xml*
-rwxr-xr-x   1 sean sean  1242 May 31 16:09 build*
...
-rw-rw-rw-   1 sean sean  1225 Apr 23 18:41 run-midp.bat
drwxr-xrwx   5 sean sean  4096 Feb 26 22:37 src/
drwxr-xrwx   6 sean sean  4096 Feb 26 22:37 tools/

Note those dates - some as far back as late April They all appear in the resulting .tar.gz archive. If instead, I change the date to today (2005-06-12), then nothing at all is backed up - this is expected as I haven't actually changed them yet today.

Now, I did do a recursive chmod on these files to make them all writable, but that was Friday evening (2005-06-10) so even if that updated the modification time (and it looks like it hasn't), the bulk of the files shouldn't be included.

 

I then thought that tar maybe has got the wrong end of the stick as far as the modification times are concerned, so I'll look at the tar -t output directly. Here's just one line:

-rwxr-xr-x sean/sean     12434 2005-05-25 17:32:46 tools/java/postprocessor/Readme.txt

Now, I don't know about you, but a modification time of 2005-05-25 is definitely before 2005-06-10.

 

I am sure to be missing something glaringly obvious here. Can anyone tell me what it is?

 

[moved from Software by spinynorman]

Link to comment
Share on other sites

Now, I did do a recursive chmod on these files to make them all writable, but that was Friday evening (2005-06-10) so even if that updated the modification time (and it looks like it hasn't), the bulk of the files shouldn't be included.

That was it, folks. If I just use the usual "ls -l", the listed modification time wasn't changed, but if I use

ls -l --time=ctime

to list the files, all the times are listed as 2005-06-11 21:39. My memory must have been wrong, and I did the chmod on Saturday night instead of Friday.

I am sure to be missing something glaringly obvious here.

It seems that it's just the usual - I have no idea even what day of the week it is. Sorry for the threadwaste...

Edit. I initially solved this by finding the first file I knew I had modified, and using that as an argument to --newer. However, there is an option for doing what I really wanted - it is called --newer-mtime, which takes the modification time only of the file data into account, ignoring changes to the file attributes. Hope this is useful to some other confused soul.

Edited by sellis
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...