Scp 或 rsync 90 天前的文件到远程服务器 (EC2)

问题描述

我正在尝试获取 90 天之前的日志文件,并尝试将它们发送到 ec2 实例的远程服务器。我正在尝试此命令,但它不起作用。

find /var/log/* -mtime +90 -print0 | rsync --remove-source-files -av -e ssh -i keypair.pem ubuntu@ip:/

它给出了这个错误

ubuntu@ip: Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]

解决方法

-i 是 ssh 的选项,而不是 rsync。您正在使用 -e。很好,但是你必须用引号将所有 ssh 参数传递给它。 第二件事你必须告诉 rsync 你正在通过标准输入管道

find /var/log/* -mtime +90 -print0 | rsync --remove-source-files -av -e 'ssh -i keypair.pem' --files-from=- --from0 /var/log/ ubuntu@ip:/

https://unix.stackexchange.com/questions/87018/find-and-rsync