最近在學習 MySQL 的 bin-log 時候考慮到數據備份的問題,忽然想到若是能將數據經過 Linux 命令行方式備份到百度網盤,那是一件多麼牛逼的事情。百度網盤有免費的 2TB 存儲空間,並且有百度作靠山,不怕數據丟失,安全可靠。說幹就幹,經過百度 and 谷歌找到了幾種方式,比較喜歡 bypy 的方式,使用簡單,方便。下邊簡單的總結一下如何使用 bypy 實現百度網盤數據的同步。api
這是一個百度雲的 Python 客戶端,其主要目的和功能,就是爲 Linux 使用者提供一種在命令行下,使用百度雲盤中2T存儲空間的方法。它提供文件列表、下載、上傳、比較、向上同步、向下同步,等操做。瀏覽器
系統環境:安全
Linux 系統 + Python 2.7app
安裝軟件工具:工具
pip install requests pip install bypy
受權登錄:學習
執行 bypy info,顯示下邊信息,根據提示,經過瀏覽器訪問下邊灰色的https連接,若是此時百度網盤帳號正在登錄,會出現長串受權碼,複製。測試
[root@ineedle ~]# bypy info Please visit: # 訪問下邊這個鏈接,複製受權碼 https://openapi.baidu.com/oauth/2.0/authorize?scope=basic+netdisk&redirect_uri=oob&response_type=code&client_id=q8WE4EpCsau1oS0MplgMKNBn And authorize this app Paste the Authorization Code here within 10 minutes. Press [Enter] when you are done # 提示在下邊粘貼受權碼
在下邊圖示紅色位置粘貼受權碼,耐心等待一會便可(1-2分鐘)this
Press [Enter] when you are done a288f3d775fa905a6911692a0808f6a8 Authorizing, please be patient, it may take upto None seconds... Authorizing/refreshing with the OpenShift server ... OpenShift server failed, authorizing/refreshing with the Heroku server ... Successfully authorized Quota: 2.015TB Used: 740.493GB
受權成功。spa
測試上傳和同步本地文件到雲盤命令行
因爲百度PCS API權限限制,程序只能存取百度雲端/apps/bypy目錄下面的文件和目錄。咱們能夠經過:
[root@ineedle ~]# bypy list /apps/bypy ($t $f $s $m $d):
把本地當前目錄下的文件同步到百度雲盤:
# bypy upload
把雲盤上的內容同步到本地:
# bypy downdir
比較本地當前目錄和雲盤根目錄,看是否一致,來判斷是否同步成功:
# bypy compare