pythonやnodejsでgoogle driveにアップする仕組みを以前つくりましたが……あの後色々検討したところ、別のクラウド、あるいは自前の鯖にアップロードする可能性というのが出てきました。
私のターゲット環境ではリアルタイム性は必須ではなく、なんなら翌日反映という事ですらいいので……これはもしかしてrsyncなのでは?と思い改めて調べなしてみました。
すると、クラウド版rsyncともいえるrcloneというツールが。
実際のところ
前提条件
- raspberry pi 4B
- raspberryOS(32bit)
手順
$ curl https://rclone.org/install.sh | sudo bash
$ rclone config 2022/02/02 15:20:33 NOTICE: Config file "/home/pi/.config/rclone/rclone.conf" not found - using defaults No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n
name> googledrive
Option Storage. Type of storage to configure. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value. 1 / 1Fichier \ "fichier" … 16 / Google Drive \ "drive" … 45 / seafile \ "seafile" Storage> 16
クライアント情報入力
クライアントidを入手して入力
Option client_id. Google Application Client Id Setting your own is recommended. See https://rclone.org/drive/#making-your-own-client-id for how to create your own. If you leave this blank, it will use an internal key which is low performance. Enter a string value. Press Enter for the default (""). client_id>xxx
続いてシークレットキー
Option client_secret. OAuth Client Secret. Leave blank normally. Enter a string value. Press Enter for the default (""). client_secret>yyy
google driveの設定
スコープの設定
今回はファイルアップをするので1
Option scope. Scope that rclone should use when requesting access from drive. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value. 1 / Full access all files, excluding Application Data Folder. \ "drive" 2 / Read-only access to file metadata and file contents. \ "drive.readonly" / Access to files created by rclone only. 3 | These are visible in the drive website. | File authorization is revoked when the user deauthorizes the app. \ "drive.file" / Allows read and write access to the Application Data folder. 4 | This is not visible in the drive website. \ "drive.appfolder" / Allows read-only access to file metadata but 5 | does not allow any access to read or download file content. \ "drive.metadata.readonly" scope> 1
デフォフォルダidやルートフォルダを設定
Option root_folder_id. ID of the root folder. Leave blank normally. Fill in to access "Computers" folders (see docs), or for rclone to use a non root folder as its starting point. Enter a string value. Press Enter for the default (""). root_folder_id> Option service_account_file. Service Account Credentials JSON file path. Leave blank normally. Needed only if you want use SA instead of interactive login. Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`. Enter a string value. Press Enter for the default (""). service_account_file>
各種オススメ設定を使って細かいところ
玄人向け設定ファイルを弄るか否か
Edit advanced config? y) Yes n) No (default) y/n> n
自動設定を有効
Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machine y) Yes (default) n) No y/n> y
認証URL
google は認証URLが必要
2022/02/02 15:23:37 NOTICE: Make sure your Redirect URL is set to "urn:ietf:wg:oauth:2.0:oob" in your custom config. 2022/02/02 15:23:37 NOTICE: If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=xxx
今回はraspiなのでマシンパワーが不足しておりxwindw越しに実行するのは処理上、現実的ではありませんでした
今回はvncでブラウザに繋いで設定しました
クロージング
まとまった所
2022/02/02 15:26:03 NOTICE: Got code Configure this as a Shared Drive (Team Drive)? y) Yes n) No (default) y/n> n -------------------- [googledrive] type = drive client_id = xxx client_secret = yyy scope = drive token = {"access_token":"xxx","token_type":"Bearer","refresh_token":"yyy","expiry":"2022-02-02T16:26:02.760404009+09:00"} team_drive = --------------------
y) Yes this is OK (default) e) Edit this remote d) Delete this remote y/e/d> y
だと
Current remotes: Name Type ==== ==== googledrive drive e) Edit existing remote n) New remote d) Delete remote r) Rename remote c) Copy remote s) Set configuration password q) Quit config e/n/d/r/c/s/q>