LoginSignup
49
47

More than 3 years have passed since last update.

rcloneを使用したGoogle Driveのバックアップ

Last updated at Posted at 2019-03-15

はじめに

Google DriveのバックアップのためにGoogle Drive APIを使用することを検討しましたが、rcloneを使えば、もっと簡単にバックアップできることがわかりました。
本記事は、rcloneを使用してGoogle Driveのバックアップを行った際のメモです。

前提

  • Googleアカウント作成済み
  • Homebrewインストール済み

環境

macOS Mojave(10.14.3)

インストール & 設定

インストール

$ brew install rclone

設定

$ rclone config
2019/03/15 18:39:43 NOTICE: Config file "/Users/xxx/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one

新規追加なので、nを選択

n) New remote
s) Set configuration password
q) Quit config
n/s/q> n

任意の名前をつける(今回はgdriveとする)

name> gdrive

リモート種別を選択。今回はGoogle Driveなので、12を選択

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 / A stackable unification remote, which can appear to merge the contents of several remotes
   \ "union"
 2 / Alias for a existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Dropbox
   \ "dropbox"
 9 / Encrypt/Decrypt a remote
   \ "crypt"
10 / FTP Connection
   \ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
12 / Google Drive
   \ "drive"
13 / Hubic
   \ "hubic"
14 / JottaCloud
   \ "jottacloud"
15 / Local Disk
   \ "local"
16 / Mega
   \ "mega"
17 / Microsoft Azure Blob Storage
   \ "azureblob"
18 / Microsoft OneDrive
   \ "onedrive"
19 / OpenDrive
   \ "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
21 / Pcloud
   \ "pcloud"
22 / QingCloud Object Storage
   \ "qingstor"
23 / SSH/SFTP Connection
   \ "sftp"
24 / Webdav
   \ "webdav"
25 / Yandex Disk
   \ "yandex"
26 / http Connection
   \ "http"
Storage> 12
** See help for drive backend at: https://rclone.org/drive/ **

未入力でOK(そのままEnter)

Google Application Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>

未入力でOK(そのままEnter)

Google Application Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>

Google Driveへのアクセス権限
今回はフルアクセスを許可(1を選択)しますが、適宜選択してください。

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

未入力でOK(そのままEnter)

ID of the root folder
Leave blank normally.
Fill in to access "Computers" folders. (see docs).
Enter a string value. Press Enter for the default ("").
root_folder_id>

未入力でOK(そのままEnter)

Service Account Credentials JSON file path
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file>

詳細設定
今回は省略(nを選択)します。

Edit advanced config? (y/n)
y) Yes
n) No
y/n> n

アクセス許可のための認証を自動で行うかどうか。
今回はブラウザから認証するため、nを選択します。

Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n

ここで、ブラウザが起動し、Googleのログイン画面に遷移するので、ログインします。
ログイン後に、アクセス許可を求める画面が表示されるので、「許可」をクリックします。
スクリーンショット_2019-03-15_19_11_41.png
表示されたコードをコピーします。
スクリーンショット_2019-03-15_19_15_16.png

コピーしたコードを貼り付けます。

Enter verification code> XXXXXXXXXXXX

今回は共有ドライブを使用しないのでnを選択します。

Configure this as a team drive?
y) Yes
n) No
y/n> n

設定内容に間違いがなければ、yを選択します。

--------------------
[gdrive]
type = drive
scope = drive
token = {"access_token":"XXXX","token_type":"XXXX","refresh_token":"XXXX","expiry":"2019-03-15T20:19:56.619869+09:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

設定が完了したので、qを選択します。

Current remotes:

Name                 Type
====                 ====
gdrive               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

実行

Google Drive内の全ファイルを表示

$ rclone ls gdrive:

ローカルのカレントディレクトリ内の全ディレクトリ、全ファイルをGoogle Driveにコピー

$ rclone copy . gdrive:

Google Drive内の任意のファイルをローカルにコピー

日本語ファイル名でもOK

$ rclone copy gdrive:無題のドキュメント.docx .

まとめ

rcloneはGoogle Driveだけでなく、Dropbox、Amazon S3、Google Cloud Storageなど幅広く対応しています。
また、異なるリモート同士のデータの転送も容易なので、バックアップツールとして非常に便利です。
まだ使い始めたばかりですが、もっと使いこなしていきたいなと思います。

参考

49
47
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
49
47