如何仅同步特定的文件列表? [英] How to rsync only a specific list of files?
问题描述
我在各个子目录中有大约 50 个左右的文件,我想将它们推送到远程服务器.我认为 rsync 可以使用 --include-from 选项为我做到这一点.如果没有 --exclude="*" 选项,目录中的所有文件都会被同步,如果有选项,则没有文件.
I've about 50 or so files in various sub-directories that I'd like to push to a remote server. I figured rsync would be able to do this for me using the --include-from option. Without the --exclude="*" option, all the files in the directory are being synced, with the option, no files are.
rsync -avP -e ssh --include-from=deploy/rsync_include.txt --exclude=* ./ root@0.0.0.0:/var/www/ --dry-run
我最初将它作为干运行,显然 0.0.0.0 已被远程服务器的 IP 取代.rsync_include.txt 的内容是我要上传的文件的相对路径的新行分隔列表.
I'm running it as dry initially and 0.0.0.0 is obviously replaced by the IP of the remote server. The contents of rsync_include.txt is a new line separated list of relative paths to the files I want to upload.
有没有更好的方法可以让我在星期一早上逃脱?
Is there a better way of doing this that is escaping me on a Monday morning?
推荐答案
下面 atp 的回答更好.请使用那个!
如果您要查找特定的文件列表,则可以更轻松地将它们直接放在命令行上:
You might have an easier time, if you're looking for a specific list of files, putting them directly on the command line instead:
# rsync -avP -e ssh `cat deploy/rsync_include.txt` root@0.0.0.0:/var/www/
然而,这是假设您的列表不会太长以至于命令行长度会成为问题,并且 rsync_include.txt
文件只包含真实路径(即没有注释,并且没有正则表达式).
This is assuming, however, that your list isn't so long that the command line length will be a problem and that the rsync_include.txt
file contains just real paths (i.e. no comments, and no regexps).
这篇关于如何仅同步特定的文件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!