Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Find symlinks, or what should be symlinks...



On Tue, Apr 22, 2014 at 05:11:41PM +0900, Darren Cook wrote:
> In setting up my new notebook, I copied over the big Projects directory
> tree. My first try (using rsync, via a NAS disk) had problems
> (everything had the 'x' permission set, and symlinks didn't get copied).
> 
> So, I set up sshd, and "scp -rp"-ed the directory tree. It took a while
> longer than expected, and I realized it must have followed all the
> symlinks into a "data" directory tree, and copied them as files. Not
> major, I thought, there are just a few, I can move it around afterwards
> (and it saves having to copy the data directory...).
> 
> But, poking around, I realize there were lots of symlinks. E.g. a
> directory containing library files:
>    xxx.1.2.3.so
>    xxx.so
> 
> These are now both 2MB files, instead of one being a link to the other.
> 
> How would you fix this?
> 
> I could delete and start again, using rsync, with it set to keep
> symlinks within the same disk).
> 
> ...Would rsync, to the existing tree, replace xxx.so above with a
> symlink, automatically? If so, not starting again and instead just
> running rsync, might be perfect?
> 
> Or I could run some clever bash script (??) to find all symlinks on the
> old machine. Then I have a list of what I need to fix manually.
> 
> Or I started wondering if there is a tool to hunt for duplicate files
> and sub-directories in a directory tree? That might give me an optimum
> list of what should be symlinked, and at least I'd then know the size of
> the problem.
> 
> Darren
> 

To partially update the tree on your new machine, that is to only re-write the
symlinks, the following might work: select the symlinks on the old machine using
find, pass that list to rsync and let it copy them over to the new box via ssh:

  find $source -type l -print0 | rsync -l0R --files-from=- user@newbox:$destination

  find  -type l         -> find symlinks below $source
        -print0         -> use \0 to separate filenames instead of newlines, print them
  rsync -l              -> copy symlinks as symlinks
        -0              -> process \0 separated input
        -R              -> use relative paths. From find we get ./foo/bar,
                           which would normally be put into $destination/bar,
                           but this way we get $destination/foo/bar
        --files-from=-  -> read file names from stdin

I hope this helps somehow (and is correct).

Best regards
Jens.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links