Raspberry Pi 3上で作成した作業ログやその他の作成物を外部ストレージに格納したい。
その方法を探して、Dropboxに格納できることがわかったので、やってみました。
参考にしたサイト
コマンドラインからDropboxを操作する方法(+Jenkinsとの連携)
Raspberry Pi 3 側の設定<1>
cpanm のインストール
wget は既にインストール済みだったため、手順から省いています。
未インストールの場合は、先にインストールしてください。
まず、cpanm からインストールします。
$ wget https://raw.github.com/miyagawa/cpanminus/master/cpanm
--2020-04-05 13:58:53-- https://raw.github.com/miyagawa/cpanminus/master/cpanm
raw.github.com (raw.github.com) をDNSに問いあわせています... 151.101.228.133
raw.github.com (raw.github.com)|151.101.228.133|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 301 Moved Permanently
場所: https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm [続く]
--2020-04-05 13:58:54-- https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm
raw.githubusercontent.com (raw.githubusercontent.com) をDNSに問いあわせています... 151.101.228.133
raw.githubusercontent.com (raw.githubusercontent.com)|151.101.228.133|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 302780 (296K) [text/plain]
`cpanm' に保存中
cpanm 0%[ ] 0 --.-KB/s
cpanm 40%[=======> ] 119.13K 586KB/s
cpanm 100%[===================>] 295.68K 782KB/s 時間 0.4s
2020-04-05 13:58:55 (782 KB/s) - `cpanm' へ保存完了 [302780/302780]
Dropbox API Command のインストール
次に、dropboxapi をインストールします。
私はこのインストールに1時間近くかかりました。
腹ごしらえなどをしながら、ゆっくり待ちましょう。
$ sudo perl cpanm App::dropboxapi
--> Working on App::dropboxapi
Fetching http://www.cpan.org/authors/id/A/AS/ASKADNA/App-dropboxapi-2.13.tar.gz ... OK
==> Found dependencies: Module::Build::Tiny
--> Working on Module::Build::Tiny
Fetching http://www.cpan.org/authors/id/L/LE/LEONT/Module-Build-Tiny-0.039.tar.gz ... OK
==> Found dependencies: ExtUtils::InstallPaths, ExtUtils::Config, ExtUtils::Helpers
--> Working on ExtUtils::InstallPaths
〜〜あまりに長いので中略〜〜
Fetching http://www.cpan.org/authors/id/S/SH/SHAY/Class-Singleton-1.5.tar.gz ... OK
Configuring Class-Singleton-1.5 ... OK
Building and testing Class-Singleton-1.5 ... OK
Successfully installed Class-Singleton-1.5
Building and testing DateTime-TimeZone-2.38 ... OK
Successfully installed DateTime-TimeZone-2.38
Building and testing DateTime-1.52 ... OK
Successfully installed DateTime-1.52
Building and testing DateTime-Format-Strptime-1.77 ... OK
Successfully installed DateTime-Format-Strptime-1.77
Building and testing App-dropboxapi-2.13 ... OK
Successfully installed App-dropboxapi-2.13
87 distributions installed
Dropbox 側の設定
Dropbox は、事前にアカウント作成まで終えている前提です。
未作成の人は、作成してください。(無料のアカウントです)
Dropbox Developers でアプリケーションを作成する
Deveropers に移動します。
- App console を選択
- Create app を選択
- Create a new app on the DBX Platform の質問に回答する
- Choose an API —> Dropbox API
- Choose the type of access you need —> App folder – Access to a single folder created specifically for your app.
- Name your app —> 自分の好きな名前で
I agree to Dropbox API Terms and Conditions —> check
- Create app を選択
アプリケーションの名前は、自分で決めたものを入力します。
今回は、raspberrypi2myfolder としました。
アプリケーションが作成されたら、App Key と App Secret を忘れずにメモします。
すぐに使うので、テキストに貼っておくのが良いです。
Raspberry Pi 3 側の設定<2>
dropbox-api のセットアップ
対話式でセットアップを進めます。
Please Input API Key に対して、先ほどの App Key を入力してください。
Please Input API Secret に対して、先ほどの App Secret を入力してください。
Open the Login URL で表示されたURLにブラウザでアクセスしてください。
ブラウザで認証が終わったら、認証用のコード が表示されます。
Input code and press Enter に対して、認証用のコード を入力してください。
$ dropbox-api setup
Please Input API Key:
Please Input API Secret:
1. Open the Login URL: https://www.dropbox.com/oauth2/authorize?client_id=App Key&response_type=code
2. Input code and press Enter:
success! try
> dropbox-api ls
> dropbox-api find /
格納の確認
Raspberry Pi 3 に作成したログをDropboxに格納し、Macのブラウザで格納を確認します。
$ dropbox-api put 20200405_135702.log dropbox:/

無事に格納されていることを確認できました。
個人的つまづきポイント
- dropbox-api のインストールに時間がかかったこと(暇でした)
- 認証用コード の貼り付け場所がブラウザ上だと勘違いしていたこと