LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-24-2011, 10:10 AM   #1
legacyprog
Member
 
Registered: Feb 2004
Location: New Jersey, USA
Distribution: Ubuntu 11.10
Posts: 52

Rep: Reputation: 15
Unhappy Best way to merge two directory trees with replace?


I realize there must be many ways to merge directory trees, but I am picking my way through a hard drive recovery and I'd appreciate the assist to save me time (which is my enemy right now).

My situation is two large directory trees on the same server, the roots are:
/Public2/MasterTree
/Backup/PartialTree

The directory structures are similar (i.e., the /Backup tree was a point in time backup of portions of /Public2/MasterTree, only the most important files, /Public2/MasterTree is complete at an older point in time).

As you may imagine, I need to copy the files from /Backup/PartialTree overlaying or creating any files in the equivalent target path, including creating any folders needed to contain new files.

I have tried cp -u -r (which did not seem to update though I thought it would) and cp -r (which created PartialTree as a tree UNDER /Public2/Backup.

I have never used rsync so I'm not sure I want to turn this into a learning experience while trying to recover data, and my bash is not good enough to trust either (I don't consider myself a newbie, but some might). This is Ubuntu 11.10 if it matters.

Thanks in advance for any help, and Happy Holidays.
 
Old 12-24-2011, 11:52 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 206Reputation: 206Reputation: 206
Yes, this definitely sounds like a job for rsync. Do turn this into a learning experience, coupled with suggestions here on the Forums.

These days, I only use cp and scp for the simplest of copy jobs.

This is probably a good start:

Code:
rsync -av /Backup/PartialTree/ /Public2/MasterTree
-HAX can also be added depending on how anal you want to get.

Just read the critical portions of the man page so you understand what you're doing.

Last edited by jhwilliams; 12-24-2011 at 11:53 AM. Reason: woops, had the src and dest backwards. fixed.
 
Old 12-24-2011, 12:33 PM   #3
legacyprog
Member
 
Registered: Feb 2004
Location: New Jersey, USA
Distribution: Ubuntu 11.10
Posts: 52

Original Poster
Rep: Reputation: 15
Thanks jhwilliams, but my first shot at using rsync using the syntax you suggested just copied all the folders from /Backup/PartialTree/ under /Public2/MasterTree/FirstFolder.

I did review the man rsync page but it is daunting. Your suggested command certainly makes sense. The -a implies recursion. I am puzzled.

I'll be off and on today with family commitments. Feel free to leave any additional comments for me to review later. But in any case thanks and Happy Holidays!
 
Old 12-24-2011, 12:49 PM   #4
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 206Reputation: 206Reputation: 206
FirstFolder? Do you mean in directory named PartialTree? The slashes are subtle but important; did you include the trailing slash on PartialTree/ ?
 
Old 12-24-2011, 01:16 PM   #5
legacyprog
Member
 
Registered: Feb 2004
Location: New Jersey, USA
Distribution: Ubuntu 11.10
Posts: 52

Original Poster
Rep: Reputation: 15
Running out of the house now, but I up arrowed the Terminal and it seems I did include the trailing slash on PartialTree as you showed, but not on MasterTree, as you showed. Unless it's cause I used sudo, but I doubt that. Will check later. Thanks for hanging in there. I can do experiments with junk directories, maybe that's what I should do.
 
Old 12-24-2011, 08:15 PM   #6
legacyprog
Member
 
Registered: Feb 2004
Location: New Jersey, USA
Distribution: Ubuntu 11.10
Posts: 52

Original Poster
Rep: Reputation: 15
OK, for anyone stumbling on this thread in the future, after I got back from the family Christmas party, I did a test with a couple junk directory trees (I created test files in them with the touch command) and (of course) the rsync -av worked just fine, as jhwilliams and man rsync suggested.

So I figured it must be something I was doing wrong with the two particular directory trees in question. So I kept adjusting the syntax and it eventually worked, but I was left with /Public2/MasterTree/PartialTree. That's right, it put the entire PartialTree hierarchy under the MasterTree, so I deleted it and decided to "try again". This time I thought if I did "sudo rsync -av /Backup/PartialTree/. /Public2/MasterTree/." it might work better, because the -d switch description in man rsync gave me the impression that using /. at the end was an alternate way of calling attention to the contents of a directory, not the directory itself. However now rsync started refusing to do anything, so I looked and somehow all my updates *had* been applied to the actual /Public2/MasterTree structure! So either rsync did that *in addition* to creating the entire PartialTree hierarchy under /Public2/MasterTree, or else in my attempts to get this all to work I had stumbled on something that accomplished what I needed but I had counted it as an error (maybe the time that I ended up with the entire MasterTree hierarchy stored under /Backup/PartialTree? perhaps that was rsync's way of "synchronizing" the two trees?).

I didn't want to just leave this thread dangling, but clearly I do not have a way of confirming the best approach for anyone trying to do the same as me in the future. Sorry! I gave it my best try in the time I had available.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Same files on distinct directory trees 0p3r4t4 Linux - General 1 11-25-2011 05:01 AM
Merge directory trees mrwall-e Linux - Software 5 02-20-2011 08:37 AM
mkisofs and preserving directory trees crontab Linux - Software 2 03-27-2009 10:00 AM
Q: on deleting directory trees n00bJoe Arch 3 03-09-2006 12:13 PM
How to keep 2 directory trees synchronised? hrr Linux - General 2 07-02-2003 12:01 PM


All times are GMT -5. The time now is 02:03 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration