简体   繁体   English

使用查找从远程Rsync文件

[英]Rsync files from remote using find

I would like to synchronize remote files with local directory. 我想将远程文件与本地目录同步。 Files must be from today 0AM. 文件必须从今天凌晨0点开始。 I tried to download files with this command, but this method does not work. 我尝试使用此命令下载文件,但是此方法不起作用。 How can I achieve my goal? 我如何实现我的目标?

ssh user@192.168.1.100 'find /home/user/test/ -mtime -1 -type f' | rsync --archive --verbose -zz --human-readable --rsh='ssh user@192.168.1.100:/home/user/test/' '/e/rc/'

/e/rc/ is my local windows directory - script is launched from git bash console (find and rsync are avaible) / e / rc /是我的本地Windows目录-脚本从git bash控制台启动(找到和rsync可用)

Your commands have 2 problems 您的命令有2个问题
1) ssh password is constantly asked so made 2 separated commands to list and copy. 1)不断要求ssh密码,因此请使用2个单独的命令进行列出和复制。
2) Items in list contains /home/user/test which rsync will try to copy to /home/user/test/home/user/test, throwing an error. 2)列表中的项目包含/ home / user / test,rsync将尝试将其复制到/ home / user / test / home / user / test,并抛出错误。 Files basename is needed. 需要文件基名。

# we need to get file basename since rsync+ssh will copy with respect to user home
files=$(ssh user@192.168.0.10 "find /home/user/test/ -mtime -1 -type f -exec basename {} ';'")
# do the actual copy reading list of files-from stdout
echo "$files" | rsync -avz --files-from=- user@192.168.0.10:test/ '/e/rc/'

I don't use git bash so if $(...) expression does not work try to use backticks or use a full fledged bash. 我不使用git bash因此如果$(...)表达式不起作用,请尝试使用反引号或使用完整的bash。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM