linux - 使用 find 从远程同步文件

标签 linux bash ssh find rsync

我想将远程文件与本地目录同步。文件必须是从今天早上 0 点开始的。 我尝试用这个命令下载文件,但是这个方法不起作用。 我怎样才能实现我的目标?

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/是我的本地 windows 目录 - 脚本是从 git bash 控制台启动的(find 和 rsync 可用)

最佳答案

你的命令有两个问题
1) 不断询问 ssh 密码,所以制作了 2 个单独的命令来列出和复制。
2) 列表中的项目包含/home/user/test,rsync 将尝试将其复制到/home/user/test/home/user/test,抛出错误。需要文件基本名称。

# 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/'

我不使用 git bash,所以如果 $(...) 表达式不起作用,请尝试使用反引号或使用完整的 bash。

关于linux - 使用 find 从远程同步文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50372835/

相关文章:

linux - 如何检测挂起的 Linux 服务?

php - 如何在 Linux 上从大文件中过滤掉数据?

java - 错误 : Could not find or load main class ( in Java 8)

ssh - 无法在 MacOS Sierra 上运行 "ssh -X"

ssh - 使用PuTTY的tail -f挂起

ssh - 在 ConEmu 中,有没有办法为频繁的 ssh session 创建快捷方式?

php - 在 php 中发送邮件时如何删除显示系统信息的 header

linux - 如何在没有密码的情况下以另一个用户身份运行脚本?

Ruby 使用 stdin 两次

linux - 使用wget获取谷歌翻译的结果