duandeng7132
2012-05-11 01:22
浏览 159
已采纳

如何通过脚本将一组文件/文件夹从linux服务器传输到另一个?

I'm creating a php script to backup my website everyday, backup goes to another linux server of mine but how can i compress all files and send to another linux server via a script?

图片转代码服务由CSDN问答提供 功能建议

我正在创建一个PHP脚本来每天备份我的网站,备份转到我的另一个linux服务器但是怎么能 我压缩所有文件并通过脚本发送到另一个Linux服务器?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • duangang1991 2012-05-11 01:56
    最佳回答

    One possible solution (in bash).

    BACKUP_SERVER_PATH=remote_user@remote_server:/remote/backup/path/
    SITE_ROOT=/path/to/your/site/
    
    cd "$SITE_ROOT"
    now=$(date +%Y%m%d%H%M)
    tar -cvzf /tmp/yoursite.$now.tar.gz .
    scp /tmp/yoursite.$now.tar.gz "$BACKUP_SERVER_PATH"
    

    Some extra stuff to take into account for permission (read access to docroot) and ssh access to the remote server (for scp).

    Note that there are really many ways to do this. Another one, if you don't mind storing an uncompressed version of your site is to use rsync.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题