Linux 如何 RSYNC 单个文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14888012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to RSYNC a single file?
提问by u775856
Currently i only RSync-ing the Directories
as like:
目前我只有 RSync-ing 之Directories
类的:
* * * * * rsync -avz /var/www/public_html/images root@<remote-ip>:/var/www/public_html
So how do i rsync
one single file like, /var/www/public_html/.htaccess
?
那么我如何rsync
像一个单一的文件一样,/var/www/public_html/.htaccess
?
采纳答案by Michael Place
You do it the same way as you would a directory, but you specify the full path to the filename as the source. In your example:
您以与目录相同的方式执行此操作,但您指定文件名的完整路径作为源。在你的例子中:
rsync -avz /var/www/public_html/.htaccess root@<remote-ip>:/var/www/public_html/
回答by Kenny Evitt
Michael Place's answer works great if, relative to the root directory for both the source and target, all of the directories in the file's path already exist.
如果相对于源和目标的根目录,文件路径中的所有目录都已经存在,那么 Michael Place 的答案就很好用。
But what if you want to sync a file with this source path:
但是如果你想用这个源路径同步一个文件怎么办:
/source-root/a/b/file
/source-root/a/b/file
to a file with the following target path:
到具有以下目标路径的文件:
/target-root/a/b/file
/target-root/a/b/file
and the directories aand bdon't exist?
并且目录a和b不存在?
You need to run an rsync command like the following:
您需要运行如下 rsync 命令:
rsync -r --include="/a/" --include="/a/b/" --include="/a/b/file" --exclude="*" [source] [target]