1

When I try to rsync directory1 to directory2 that have symbolic files that point to the same files in directory1, rsync replace all the symbolic files with real files.

I tried to add -L but it didn't help, -K is for symbolic directories. Is there a flag to keep the symbolic files in the target?

command:

mkdir dir1
cd dir1
echo "TEST" >  file1

cd .. cp -as /HOME/dir1 dir2

now dir2 have a symbolic file that point to the file in dir1.

When I try to run:

rsync -nKLri dir1/ dir2/

I get:

>f+++++++++ file1
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
Jeries
  • 13
  • Did you try with --ignore-existing? – Kusalananda Aug 03 '22 at 12:14
  • Hmmm... Since you were using so many options, I assumed you had been going through the manual to look for useful options. No matter. – Kusalananda Aug 03 '22 at 12:27
  • @Kusalananda it's not a great solution, though, unless the OP can guarantee that all the target files are actually symbolic links to the corresponding source. IMO it's certainly not an obvious answer – Chris Davies Aug 03 '22 at 12:28
  • @roaima Yes, they would possibly want to avoid only files that are symbolic links while updating any other type of file, I suppose. However, the user never says anything about this. As it stands, it's a dupe of Rsync doesn't skip existing files – Kusalananda Aug 03 '22 at 12:30
  • in my directory there is symbolic and regular files, so the rsync will not work if the files have that same name? – Jeries Aug 03 '22 at 12:33
  • 2
    Ironically, if the OP could use hard links instead of symbolic links, rsync could achieve what they seem to want – Chris Davies Aug 03 '22 at 12:33
  • "the rsync will not work if the files have that same name" - that's correct. The --ignore-existing option does exactly what it describes: it completely ignores any existing file in the destination directory tree – Chris Davies Aug 03 '22 at 12:34
  • ok Thanks so the --ignore-existing doesn't help – Jeries Aug 03 '22 at 13:04
  • In that case I assume you will update your question. As it stands right now, that option does seem to solve the specific issue described in the question. – Kusalananda Aug 03 '22 at 13:27
  • When you use rsync's archive option -a 'everything' is copied as is, including symlinks, but excluding hardlinks. When you add -H that is rsync -Ha you also copy hardlinks as hardlinks, give them the same inode (if the file system supports it). Searching for hardlinks costs time and effort, so it is not default. Instead of -a you can also use the -l to copy symlinks as symlinks. Notice that symlinks via -l might not work in the backup environment, however, after restore to the original location they will work. So, is it a backup or do you want the symlinks to work in the target? – sudodus Aug 03 '22 at 16:43
  • I have only soft-links and files on dir2 and I want to use rsync to copy only changed files from dir1 to dir2, dir1have only regular files (there is no symbolic files) – Jeries Aug 04 '22 at 13:16
  • So what about the symbolic links: can there be files in dir1 with the same name as the symbolic links in dir2? In that case, what do you want to happen? Do you want the symbolic links to survive? Or do you want the regular files from dir1 to replace them? Is this some kind of backup (one way) or synchronizing (both ways so that the newest files should survive)? – sudodus Aug 04 '22 at 15:40
  • yes there is files in dir1 with the same name as dir2, if the file is modified then it have to replace the file in dir2 – Jeries Aug 04 '22 at 16:53
  • @Jeries, If the file in dir2 is a symlink and the file in dir1 is a regular file they are different. Always. It makes things very complicated, if you want to compare with what the symlink is pointing to. So I would recommend that you let symlinks in dir2 to be replaced. If you don't want that, please explain why. Otherwise it is difficult to help. – sudodus Aug 05 '22 at 07:05

0 Answers0