0

So, I am trying to keep the synlink structure when transfering files, so my folder structure:

$HOME/backup/backup/symlinks
    - $HOME/Documents/hello.txt
$HOME/backup/backup/data

Now, when I sync I want to keep the symlinks full folder structure.

What it does now:

$HOME/backup/backup/symlinks
    - $HOME/Documents/hello.txt
$HOME/backup/backup/data
    - hello.txt

What I want it to do

$HOME/backup/backup/symlinks
    - $HOME/Documents/hello.txt
$HOME/backup/backup/data
    - /home/user/Documents/hello.txt (aka, create the full structure inside the backup/data folder)

So, I want create a full path inside my data folder, to where the original symlinks content came from.

I have tried the following:

rsync -a ${BACKUP}/backup/symlinks/ /${BACKUP}/backup/data/
rsync -aK ${BACKUP}/backup/symlinks/ /${BACKUP}/backup/data/
rsync -aKL ${BACKUP}/backup/symlinks/ /${BACKUP}/backup/data/

Is this possible with rsync? If so, how can I got about achieving this.

  • So this is not a question about copying hello.txt as a symbolic link or as the file that the link points to, but to replace that directory entry (the symbolic link file) with the full pathname of the file linked to? – Kusalananda May 24 at 6:23
0

I think you need to resolve the links first and then run rsync on the individual files. That way it can keep the resolved directory structure via -R. Ie. try this on Linux:

rsync -avRL --files-from=<(find ${BACKUP}/backup/symlinks/ -exec readlink -f {} \;) / /${BACKUP}/backup/data/

and this on Mac OS:

rsync -avRL --files-from=<(find ${BACKUP}/backup/symlinks/ -exec readlink {} \;) / /${BACKUP}/backup/data/

It assumes that the find command outputs the correct absolute paths, ie. that ${BACKUP} is an absolute directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.