TAGS :Viewed: 4 - Published at: a few seconds ago

[ Unwanted names in path while rsyncing to NFS-Share ]

I am using a NAS to backup my file server. The NAS exports /share/Backup via NFS, which is mounted on the fileserver as /mount/qnap. I want to keep track which files are rsynced but exclude the Backup-Dir, which contains many small files.Therefore I am running two instances of rsync, one with -v and another one without. The following command works as it should, after executing it the directory structure on /mount/qnap is identical to /mount/btrfs-raid.

rsync --delete -av --exclude Backup /mnt/btrfs-raid/ /mnt/qnap/

Rsyncing the Backup folder with the command

rsync --delete -av /mnt/btrfs-raid/Backup /mnt/qnap/Backup

produces the following directory structure on the NAS:


To get the result I want I have to delete the last "Backup" from the target directory path:

rsync --delete -av /mnt/btrfs-raid/Backup /mnt/qnap/

Why does the second example not work like the first one? Thanks Stefan

Answer 1

Trailing slashes in paths are important for rsync. See the documentation.

rsync -avz foo:src/bar /data/tmp

This would recursively transfer all files from the directory src/bar on the machine foo into the /data/tmp/bar directory on the local machine. The files are transferred in "archive" mode, which ensures that symbolic links, devices, attributes, permissions, ownerships, etc. are preserved in the transfer. Additionally, compression will be used to reduce the size of data portions of the transfer.

rsync -avz foo:src/bar/ /data/tmp

A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the directory by name", but in both cases the attributes of the containing directory are transferred to the containing directory on the destination. In other words, each of the following commands copies the files in the same way, including their setting of the attributes of /dest/foo: