Xubuntu 18.04 で rclone を使ってGoogleドライブと同期する

rcloneでGoogleドライブとローカルを同期したのでメモ。

aptでrcloneをインストールする

$ sudo apt install rclone

それからrclone configで初期設定。

$ rclone config
2019/06/26 10:48:23 NOTICE: Config file "/home/hoge/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
n/r/c/s/q> n

新規作成は「n」

name> Google

設定の名前をつける。
わかりやすく「Google」

Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Dropbox
   \ "dropbox"
 5 / Encrypt/Decrypt a remote
   \ "crypt"
 6 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
 7 / Google Drive
   \ "drive"
 8 / Hubic
   \ "hubic"
 9 / Local Disk
   \ "local"
10 / Microsoft OneDrive
   \ "onedrive"
11 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
12 / SSH/SFTP Connection
   \ "sftp"
13 / Yandex Disk
   \ "yandex"
Storage> 7   

Googleドライブは「7」

Google Application Client Id - leave blank normally.
client_id> 
Google Application Client Secret - leave blank normally.
client_secret> 
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> y

client_idとclient_secretは何もいれずにEnter
そして「y」を押すとブラウザが開いてGoogle認証ログインするので、rcloneを「許可」するを選ぶ

Waiting for code...
Got code
--------------------
[Google]
client_id = 
client_secret = 
token = {"access_token":"...","token_type":"Bearer","refresh_token":"...","expiry":"2019-06-26T11:52:02.661189132+09:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

ターミナルに戻り、「y」

Current remotes:

Name                 Type
====                 ====
Google               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> q

設定完了。
「q」で終了

そしたらローカルにフォルダ作って、リモートと同期

$ mkdir googledrive
$ cd googledrive
$ rclone sync Google: .

しばらく待つとリモートからローカルへの同期が完了する。

逆はこうだが、ローカルにないリモートのファイルが消されちゃうので、-n オプションつけて注意しながら同期という運用でカバー。

$ cd googledrive
$ rclone sync -n . Google: