2014年12月29日月曜日

RaspberryPiからGoogleDriveにアップロード

備忘録として。
RaspberryPiからGoogleDriveにファイルの同期(※)が簡単に出来ましたのでご報告です。(※同期とは言うものの、こちらからのアップロードはOKで、かつ、アップロードしたファイルをGoogleDriveから削除するとローカルドライブのファイルも削除されます。ですが、RaspberryPiからアップロードしたファイル以外はGoogleDriveのファイルを変更してもローカルドライブには変更が反映されない様子です。もし私の誤解でしたらご指摘頂けると助かります。)

こちら(↓)の情報に従いました。
http://raspberrywebserver.com/serveradmin/back-up-your-pi-to-your-google-drive.html

以下は簡単に日本語で説明するだけのことです。

まずはアップデートして、griveをインストールします。

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install git cmake build-essential libgcrypt11-dev libjson0-dev libcurl4-openssl-dev libexpat1-dev libboost-filesystem-dev libboost-program-options-dev binutils-dev libboost-test-dev libqt4-dev libyajl-dev

$ git clone git://github.com/Grive/grive.git

/home/pi/grive/libgrive/src/drive/State.cc 左のファイルの251と252と256行に"(boost::uint64_t)"を加えて、下記のようにします。


void State::Write( const fs::path& filename ) const
{
    Json last_sync ;
    last_sync.Add( \"sec\", Json((boost::uint64_t)m_last_sync.Sec() ) );
    last_sync.Add( \"nsec\", Json((boost::uint64_t)m_last_sync.NanoSec() ) );

    Json result ;
    result.Add( \"last_sync\", last_sync ) ;
    result.Add( \"change_stamp\", Json((boost::uint64_t)m_cstamp) ) ;
 
    std::ofstream fs( filename.string().c_str() ) ;
    fs << result ;
}


cmakeとmakeを行います。makeにはかなりの時間がかかりました。

$ cd ./grive
$ cmake .
$ make


google_driveのディレクトリーを作って、

$ mkdir ~/google_drive
$ cp ./grive/grive ~/google_drive


初回のGoogleDriveへのアクセスを"-a option"を使って行いますが、その前に、RaspberryPiのブラウザでgoogleにログインして、下記を行います。

$ cd ./google_drive/
$ ./grive -a

ターミナルウィンドウにリンク先が表示されるので、RaspberryPiのブラウザでそのリンクにアクセスします。その後表示されるコードをターミナルウィンドウに入力するのですが、コピペ出来ないみたいで、手で入力する必要がありそうです。

これで準備完了です。

/google_drive のディレクトリーの内容を変更して、

cd ./google_drive
./grive

とgriveを作動させるとGoogleDriveとローカルドライブの両方に変更が反映される(※)という訳です。

ありがたや。

0 件のコメント:

コメントを投稿