LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-15-2009, 03:13 AM   #1
nonoitall
Member
 
Registered: Feb 2005
Posts: 75

Rep: Reputation: 16
Help to sync files based on content


Okay, I'll cut to the chase. There are two directories:

/dir1
/dir2
  • I want files and directories that exist in dir2 and not in dir1 to be deleted from dir2.
  • I want files and directories that exist in dir1 and not in dir2 to be copied to dir2 and have their timestamps from dir1 preserved.
  • I want files and directories on dir2 that differ (based on their content) from dir1 to be overwritten by the ones in dir1, and have their timestamps from dir1 preserved.
  • I don't want any other files or directories on dir2 to be changed at all - not even their timestamps.

What's the best way to accomplish this?

Last edited by nonoitall; 01-15-2009 at 03:14 AM.
 
Old 01-15-2009, 03:27 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
well this is laregly the default behaviour of rsync. add the -t option to preserve timestamps and --delete to delete the dir2 files. It might seem odd using rsync within a machine, but the code is all there, just need to connect to your self.

$ rsync -avz --delete -e ssh user@localhost:/where/ever/dir1 /where/ever/dir2
 
Old 01-15-2009, 04:48 AM   #3
nonoitall
Member
 
Registered: Feb 2005
Posts: 75

Original Poster
Rep: Reputation: 16
That method will overwrite the timestamps of unchanged files on dir2 though (and it will assume files with different timestamps are different without checking content). The closest I've been able to get is using:
Code:
rsync -rlvzc --delete <src> <dest>
...but this doesn't preserve the timestamps of new/changed files. (Preserving file permissions is unimportant in this instance.) I also tried:
Code:
rsync -rlvzct --delete <src> <dest>
...but this overwrites the timestamps of unchanged files.
 
  


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
Routing based on Content?? Roddles Linux - Networking 6 01-09-2007 10:29 PM
How to forward packets based on HTTP header content? varange Linux - Networking 4 11-24-2006 03:39 PM
Remove files based on content stefaandk Linux - General 2 08-13-2005 09:03 AM
renaming text files based upon a pattern in their content Spacepup Linux - General 1 07-28-2005 02:43 PM
Finding files based on content benjaminrtz Linux - General 2 08-05-2002 12:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:12 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
Open Source Consulting | Domain Registration