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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-24-2011, 10:10 AM
|
#1
|
|
Member
Registered: Feb 2004
Location: New Jersey, USA
Distribution: Ubuntu 11.10
Posts: 46
Rep:
|
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.
|
|
|
|
12-24-2011, 11:52 AM
|
#2
|
|
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,167
|
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.
|
|
|
|
12-24-2011, 12:33 PM
|
#3
|
|
Member
Registered: Feb 2004
Location: New Jersey, USA
Distribution: Ubuntu 11.10
Posts: 46
Original Poster
Rep:
|
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!
|
|
|
|
12-24-2011, 12:49 PM
|
#4
|
|
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,167
|
FirstFolder? Do you mean in directory named PartialTree? The slashes are subtle but important; did you include the trailing slash on PartialTree/ ?
|
|
|
|
12-24-2011, 01:16 PM
|
#5
|
|
Member
Registered: Feb 2004
Location: New Jersey, USA
Distribution: Ubuntu 11.10
Posts: 46
Original Poster
Rep:
|
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.
|
|
|
|
12-24-2011, 08:15 PM
|
#6
|
|
Member
Registered: Feb 2004
Location: New Jersey, USA
Distribution: Ubuntu 11.10
Posts: 46
Original Poster
Rep:
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:41 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|