在本地保存所有內容後,Rsync 提交傳輸/mv

在本地保存所有內容後,Rsync 提交傳輸/mv

有沒有辦法將資料夾同步到刪除伺服器資料夾,但僅在整個傳輸完成後才移動所有內容?

我不希望文件一個接一個地移動,因為這會給正在運行的網頁伺服器帶來麻煩。

我寧願在伺服器上傳輸所有內容後移動整個資料夾(這需要大約 1 秒鐘)

答案1

您正在尋找--延遲更新選項。從man rsync

   --delay-updates
          This  option puts the temporary file from each updated file into
          a holding directory until the end of the transfer, at which time
          all  the files are renamed into place in rapid succession.  This
          attempts to make the updating of the files a little more atomic.
          [...]
          See  also the "atomic-rsync" perl script in the "support" subdir
          for an update algorithm  that  is  even  more  atomic  (it  uses
          --link-dest and a parallel hierarchy of files).

答案2

最安全的方法是讓 rsync 將檔案放置在 Web 伺服器文件根目錄之外的備用目錄中。然後更改伺服器配置以將 docroot 指向新資料夾並通知網路伺服器執行“優美”重新載入其配置。對於 Apache,這應該可以保證不會錯誤處理或丟棄任何請求。

USR1 或優雅訊號使父程序建議子程序在目前請求後退出(或如果它們沒有提供任何服務,則立即退出)。父級重新讀取其設定檔並重新開啟其日誌檔。當每個子進程死亡時,父進程將用新一代配置中的子進程替換它,該子進程立即開始服務新請求。

換句話說,我會使用 shell 腳本和 ssh 來自動執行此操作,而不是嘗試尋找用於管理網頁伺服器的 rsync 選項。

相關內容