2012年3月9日 星期五

[轉載] 使用WinSCP的SFTP同步備份資料

0

資料來源:http://www.joetsuihk.com/node/116#comment-80460979

現在我用的方案是winscp,這是目前我找到"唯一"可以透過sftp來做檔案同步的軟體
可以在http://winscp.net/eng/docs/lan... 下載
安裝完以後,只要寫一個 .bat file 如下即可

@echo on (將執行中的訊息印出來)
cd c:\program files\winscp (再把工作目錄轉到 winscp的安裝目錄)
winscp.com /command "option transfer automatic" "option echo on" "open sftp://username:password@11.22.33.44:22" "synchronize remote -mirror -delete -criteria=both d:/somedir /myhome/remotedir" "close " "exit"

其中一對quotation mark代表一個指令
前面兩個option設定transfer mode(option transfer automatic), 並印出執行間的訊息(option echo on)
再來用ssh的帳號(e.g. username)密碼(password,請用你自己的) 走sftp,port22登入 (open sftp://username:password@11.22.33.44:22)
最後 "synchronize remote -mirror -delete -criteria=both d:/somedir /myhome/remotedir"
做synchronize 採單向備分(參數remote),如果有檔案在遠端 (/myhome/remotedir)目錄下,卻不在local (d:\somedir) 裡,就將其刪除 (參數 -delete)
完成以後利用 "close" 關閉這一個session,再利用 "exit"離開 winscp
最後再排程執行即可

0 意見 :

張貼留言

 
Design by ThemeShift | Bloggerized by Lasantha