How to RSYNC a single file?

后端 未结 4 1441
庸人自扰
庸人自扰 2021-01-31 06:33

Currently i only RSync-ing the Directories as like:

* * * * * rsync -avz /var/www/public_html/images root@:/var/www/public_html
         


        
4条回答
  •  一向
    一向 (楼主)
    2021-01-31 07:21

    To date, two of the answers aren't quite right, they'll get more than one file, and the other isn't as simple as it could be, here's a simpler answer IMO.

    The following gets exactly one file, but you have to create the dest directory with mkdir. This is probably the fastest option:

    mkdir -p ./local/path/to/file
    rsync user@remote:/remote/path/to/file/ -zarv --include "filename" --exclude "*" ./local/path/to/file/
    

    If there is only one instance of file in /remote/path, rsync can create directories for you if you do the following. This will probably take a little more time because it searches more directories. Plus it's will create empty directories for directories in /remote/path that are not in ./local

    cd ./local
    rsync user@remote:/remote/path -zarv --include "*/" --include "filename" --exclude "*" .
    

    Keep in mind that the order of --include and --exclude matters.

提交回复
热议问题