1

I'm a beginner with rsync. I have a file "filelist.txt" with some files with full path :

/tmp/folder1/file.txt
/tmp/folder2/file.txt
/tmp/folder2/file.txt

I want to copy this files from the server A to serveur B, and create directories if it's needed. This file can evolve several time a day, so I don't want to handle dir creation manually on the other server before transfert files.

So I used :

cat filelist.txt | xargs -I {} rsync -r {} admin@ttt.i-test.fr:{}

But I have for each line :

rsync: change_dir#3 "/tmp/folder1" failed: No such file or directory (2)
rsync error: errors selecting input/output files, dirs (code 3) at main.c(632) [receiver=3.0.3]
rsync: connection unexpectedly closed (8 bytes received so far) [sender]

What I'm doing wrong ?

user2178964
  • 124
  • 6
  • 16
  • 40

1 Answers1

3

You can use the --relative option. For example:

rsync --files-from filelist.txt -R -av / user@host:/

According to rsync manual:

  • -R, --relative

    Use relative paths. This means that the full path names specified on the command line are sent to the server rather than just the last parts of the filenames. This is particularly useful when you want to send several different directories at the same time. For example, if you used this command:

        rsync -av /foo/bar/baz.c remote:/tmp/
    

    ... this would create a file named baz.c in /tmp/ on the remote machine. If instead you used

        rsync -avR /foo/bar/baz.c remote:/tmp/
    

    then a file named /tmp/foo/bar/baz.c would be created on the remote machine, preserving its full path. These extra path elements are called "implied directories" (i.e. the "foo" and the "foo/bar" directories in the above example).

    [...]

pynexj
  • 19,215
  • 5
  • 38
  • 56
  • It works, but I still had some weird error : building file list ... done cannot delete non-empty directory: tmp could not make way for new symlink: tmp tmp/folder2/ tmp/folder2/file.txt tmp/folder2/toto.sh sent 254 bytes received 70 bytes 129.60 bytes/sec total size is 26 speedup is 0.08 rsync error: some files could not be transferred (code 23) at /System/Volumes/Data/SWE/macOS/BuildRoots/d7e177bcf5/Library/Caches/com.apple.xbs/Sources/rsync/rsync-55/rsync/main.c(996) [sender=2.6.9] – user2178964 Aug 20 '21 at 18:47
  • only limited formatting is allowed in comments. it's not good for discussion. please ask a new question. – pynexj Aug 22 '21 at 03:21