2013年6月14日 星期五

下載備份 Google App Engine 應用程式檔案的方法

兩年前玩 GAE 時寫的應用程式原始檔案已經不知放到哪兒了, 取得原始碼的唯一辦法便是從 GAE 下載. 參考了 stackoverflow 這篇 "how to download google appengine (uploaded)application files", 原來只要一道指令就搞定了 :

appcfg.py download_app -A yourAppName -V 1 thePath 

其中, yourAppName 是 App 名稱, thePath 是要放下載檔案之路徑. 只要有安裝 Python 與 GAE SDK, 打開 DOS 視窗, 輸入上面指令就 OK 啦. 例如我的 App 名稱為 gaetrader, 下載檔案要放在 D:\gae\gaetrader 下 (不可事先建立該目錄), 那就用 :

D:\>appcfg.py download_app -A gaetrader -V 1 d:\gae\gaetrader
10:57 PM Host: appengine.google.com
10:57 PM Fetching file list...
2013-06-14 22:57:47,530 WARNING appengine_rpc.py:547 ssl module not found.
Without the ssl module, the identity of the remote host cannot be verified, and
connections may NOT be secure. To fix this, please install the ssl module from
http://pypi.python.org/pypi/ssl .
To learn more, see https://developers.google.com/appengine/kb/general#rpcssl
Email: youraccount@gmail.com
Password for youraccount@gmail.com: *****
10:58 PM Fetching files...
10:58 PM [1/28] cron.yaml
10:58 PM [2/28] index.yaml
10:58 PM [3/28] app.yaml
10:58 PM [4/28] main.py
10:58 PM [5/28] css/jquery-ui-1.8.12.custom.css
.....
這表示此 App 有 28 個檔案, 會依序下載, 注意, 存放下載檔案的目錄不要先建立喔, 下載程式會自動建立, 如果該目錄已存在, 就會出現下列錯誤訊息 :

appcfg.py: error: Cannot download to path "d:\gae\gaetrader": directory already
exists and it isn't empty.

另外要特別注意, 如果你有兩個 gmail 帳戶, 而且會在兩個帳號之間切換, 那麼使用上面的指令後, 帳號會儲存在 Cookie 中, 你每次打開 DOS 畫面就自動進入該帳號, 這時你要下載另一個帳號的 App 時, 輸入上面的指令時就不會再問你的 email 與 password, 而且會說你的 App 不存在 (帳號不同, 當然找不到 App 啊) :

12:06 AM Host: appengine.google.com
12:06 AM Fetching file list...
Error 403: --- begin server output ---
You do not have permission to modify this app (app_id=u'mybidbot').
--- end server output ---

這時你會想找 appcfg 的 logout 參數吧! 很抱歉, 沒有這樣的參數. 這該怎麼辦? 其實這要用 --no_cookies 參數, 例如現在要改下載第二個帳號下的 mybidbot 應用程式, 要輸入如下指令, 這樣就會詢問 email 與 password 了  :

appcfg.py --no_cookies download_app -A mybidbot -V 1 d:\gae\mybidbot

D:\GAE>appcfg.py --no_cookies download_app -A mybidbot -V 1 d:\gae\mybidbot
12:00 AM Host: appengine.google.com
12:00 AM Fetching file list...
2013-06-15 00:00:26,187 WARNING appengine_rpc.py:547 ssl module not found.
Without the ssl module, the identity of the remote host cannot be verified, and
connections may NOT be secure. To fix this, please install the ssl module from
http://pypi.python.org/pypi/ssl .
To learn more, see https://developers.google.com/appengine/kb/general#rpcssl
Email: your2ndaccount@gmail.com
Password for your2ndaccount@gmail.com: ******
12:01 AM Fetching files...
12:01 AM [1/5] app.yaml
12:01 AM [2/5] main.py
12:01 AM [3/5] index.yaml
12:01 AM [4/5] cron.yaml
12:01 AM [5/5] favicon.ico

以上談的是下載, 如果是上傳呢? 除了用 GAE SDK 的上傳按鈕外, 也可以直接用 appcfg update 指令  :

appcfg.py --no_cookies update mybidbot

沒有留言 :