2015-04-28 75 views
1

我必須爲外部應用程序實現回退解決方案(auth系統)。因此,我必須保持我的主要授權服務器的auth文件夾與我的後備服務器同步。該文件夾包含幾個.php文件,.bin文件和其他一些文件。不幸的是,我不知道我應該如何實現(例如每小時)將這些文件夾同步到我的後備服務器。在兩臺服務器之間同步文件夾

所有的服務器都使用CPanel/WHM,也許有一個解決方案,或者我該如何保持它們同步?我想過一個.php腳本,它通過FTP登錄並同步它們。我會爲這個.php腳本放一個cronjob。但我甚至不知道這是否可能。如果主服務器處於脫機狀態,它當然不會以負面方式影響我的後備服務器。

我應該怎樣認識到這一點?

+1

你究竟在做什麼同步?如果它只是文件,你可以用git/CI進行部署嗎? – castis

+0

git,svn,rsync,scp - 選擇一個。 :) –

回答

1

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

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。

+0

謝謝你們兩個,去試試這個。 – kentor

+0

你能告訴我如何運行我的rsync命令periodacilly(或onchange),包括鍵入我destionation的ssh密碼的課程?我嘗試了一個使用inotify的小shell腳本。但是這不起作用,因爲我想同步安裝的文件夾。 – kentor

3

我建議你使用RSYNC,假設你沒有共享主機方案。

Rsync代表「遠程同步」,代表遠程和本地文件 同步工具。它使用一種算法,通過僅移動已更改的文件部分來最小化數據複製量 。

http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/

對於這個工作,你需要讓你的服務器的Linux終端上,當然,進入SFTP端口!

+0

rsync也可以通過ssh使用。 rsync的+1。我喜歡它。 –

+0

你能告訴我如何運行我的rsync命令periodacilly(或onchange),包括鍵入我destionation的ssh密碼的課程?我嘗試了一個使用inotify的小shell腳本。但是這不起作用,因爲我想同步安裝的文件夾。 – kentor

相關問題