Rsync - How to Include Specific Parts of File Path

时间:2017-06-15 09:58:12

标签: rsync

I'm trying to use Rsync filters to manipulate how the file structure appears at my target destination. I've read through other SE questions and consulted Google, but am still having trouble.

As an example, I have the following file structure:

/home/donglecow/images/123/001/image.jpg
/home/donglecow/images/123/002/image.jpg
/home/donglecow/images/456/001/image.jpg
/home/donglecow/images/456/002/image.jpg

When running Rsync, I want to copy this exact structure: images/123/001/image.jpg, omitting /home/donglecow/at first.

Once I have this working, I want to copy over everything under images recursively. The problem I'm having is that it only copies over the last directory and its contents, for example: 001/image.jpg.

The command I'm using is: rsync -avvvrz --exclude='/home/donglecow/' --include='images/*' /home/donglecow/images/123/001/ /home/donglecow/rsyncDestination.

I end up with: /home/donglecow/rsyncDestination/001/image.jpg, but want /home/donglecow/rsyncDestination/images/123/001/image.jpg.

Where am I going wrong?

1 个答案:

答案 0 :(得分:1)

You need to use the --relative (-R) argument. That will create the intermediate directories.

Edit:

If you don't want the "/home/donglecow/" you'll need to run rsync from that directory. For example:

cd /home/donglecow
rsync -aRvvvrz --exclude='*/images/' --include='images/*' images/123/001/ /home/donglecow/rsyncDestination