Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的应用程序在主从服务器中运行。如果文件上传请求将发送到从服务器,我需要将该文件移动到主服务器。现在它只是上传到奴隶。它不会与主服务器同步。
如何在 php 中使用 ssh 在文件上传期间将上传的文件从从属移动到主控?
服务器平台是带有apache和mysql的ubuntu。
我建议您在 cron 运行的 ssh 上使用 rsync。首先执行:
$ crontab -e
并添加如下内容:
*/5 * * * * rsync -e 'ssh -i [identity_file]' [src_dir] [user]@[host]:[trg_dir]
此命令将每 5 分钟同步一次您的目录。随意调整 '*/5 * * * *' 模式以满足您的需要。
最后:
$ man crontab
和:
$ man rsync