Leonel Atencio對rsync的建議很棒。
這是我使用的rsync shell腳本。它放在我的項目中名爲/publish
的文件夾中。要點包含shell腳本提到的rs_exclude.txt文件。
rsync.sh
# reverse the comments on the next two lines to do a dry run
#dryrun=--dry-run
dryrun=
c=--compress
exclude=--exclude-from=rs_exclude.txt
pg="--no-p --no-g"
#delete is dangerous - use caution. I deleted 15 years worth of digital photos using rsync with delete turned on.
# reverse the comments on the next two lines to enable deleting
#delete=--delete
delete=
rsync_options=-Pav
rsync_local_path=../
[email protected]
rsync_server_path="/home/www.example.com"
# choose one.
#rsync $rsync_options $dryrun $delete $exclude $c $pg $rsync_local_path $rsync_server_string:$rsync_server_path
#how to specify an alternate port
#rsync -e "ssh -p 2220" $dryrun $delete $exclude $c $pg $rsync_local_path $rsync_server_string:$rsync_server_path
https://gist.github.com/treehousetim/2a7871f87fa53007f17e
通過cron
Source
編輯你的crontab運行。
# crontab -e
Crontab條目是每行一個。註釋字符是英鎊(#)符號。針對您的cron條目使用以下語法。
這些示例假設您將rsync.sh腳本放入~/rsync
這些示例還將創建rsync輸出的日誌文件。
每分鐘
* * * * * ~/rsync/rsync.sh > ~/rsync/rsync.log
每5分鐘
*/5 * * * * ~/rsync/rsync.sh > ~/rsync/rsync.log
保存你的crontab並退出編輯器。您應該看到一條消息,確認您添加到crontab。
你究竟在做什麼同步?如果它只是文件,你可以用git/CI進行部署嗎? – castis
git,svn,rsync,scp - 選擇一個。 :) –