ウェブサイト検索

Linux で Rclone を使用して Google ドライブをローカルにマウントする


Linux で Google Drive を使用して Rclone をセットアップする

このガイドでは、Rclone を使用して Google ドライブをローカルにマウントし、Linux オペレーティング システムで Rclone を使用してファイルを Google ドライブにバックアップする手順を説明します。このガイドは Manjaro Linux で正式にテストされていますが、手順はすべての Linux および Unix ディストリビューションで同じです。

始める前に、Linux マシンに Rclone がインストールされていることを確認してください。次のリンクには、Linux および Unix オペレーティング システム用の Rclone インストール手順が含まれています。

  • Linux および Unix に Rclone をインストールする方法

ローカル ファイル マネージャーで Rclone を使用して Google ドライブをマウントするには、Google ドライブからトークンを取得する必要があります。これは、「rclone config」コマンドを使用してコマンド ラインから行う方法と、rclone WebUI から行う 2 つの方法で行うことができます。

まずコマンドラインの方法を見てみましょう。

コマンドラインから Google ドライブにアクセスするように Rclone を構成する

ターミナルを開き、次のコマンドを実行して、Rclone が Google ドライブにアクセスすることを承認します。

rclone config

これにより、対話型のセットアップ プロセスが案内されます。

まず、Rclone は利用可能なリモート (つまり、クラウド プロバイダー) のリストを検索します。

新しいセットアップなので、リモコンはまだ作成していません。それでは、新しいリモコンを作成しましょう。

新しいリモコンを作成するには、"n" と入力して ENTER を押すだけです。次に、リモコンの名前を入力します。ここでは「mygdrive」という名前を付けます。

2022/01/19 16:13:42 NOTICE: Config file "/home/ostechnix/.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> mygdrive    

新しいリモートを作成する

サポートされているクラウドプロバイダーのリストが表示されます。好みのクラウドプロバイダーを選択してください。私たちの場合には。 Google ドライブなので、番号16を入力しました。

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"
 2 / Alias for an existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Better checksums for other remotes
   \ "hasher"
 7 / Box
   \ "box"
 8 / Cache a remote
   \ "cache"
 9 / Citrix Sharefile
   \ "sharefile"
10 / Compress a remote
   \ "compress"
11 / Dropbox
   \ "dropbox"
12 / Encrypt/Decrypt a remote
   \ "crypt"
13 / Enterprise File Fabric
   \ "filefabric"
14 / FTP Connection
   \ "ftp"
15 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
16 / Google Drive
   \ "drive"
17 / Google Photos
   \ "google photos"
18 / Hadoop distributed file system
   \ "hdfs"
19 / Hubic
   \ "hubic"
20 / In memory object storage system.
   \ "memory"
21 / Jottacloud
   \ "jottacloud"
22 / Koofr
   \ "koofr"
23 / Local Disk
   \ "local"
24 / Mail.ru Cloud
   \ "mailru"
25 / Mega
   \ "mega"
26 / Microsoft Azure Blob Storage
   \ "azureblob"
27 / Microsoft OneDrive
   \ "onedrive"
28 / OpenDrive
   \ "opendrive"
29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
30 / Pcloud
   \ "pcloud"
31 / Put.io
   \ "putio"
32 / QingCloud Object Storage
   \ "qingstor"
33 / SSH/SFTP Connection
   \ "sftp"
34 / Sia Decentralized Cloud
   \ "sia"
35 / Sugarsync
   \ "sugarsync"
36 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
37 / Transparently chunk/split large files
   \ "chunker"
38 / Union merges the contents of several upstream fs
   \ "union"
39 / Uptobox
   \ "uptobox"
40 / Webdav
   \ "webdav"
41 / Yandex Disk
   \ "yandex"
42 / Zoho
   \ "zoho"
43 / http Connection
   \ "http"
44 / premiumize.me
   \ "premiumizeme"
45 / seafile
   \ "seafile"
Storage> 16

クラウドプロバイダーを選択する

Google ドライブのクライアント ID とそのシークレットを既に持っている場合は入力します。クライアント ID をお持ちでない場合は、新しいクライアント ID を作成できます。

注: Google アプリケーション クライアント ID の作成はオプションですが、推奨されることに注意してください。独自の Google ドライブ クライアント ID を作成する方法については、このリンクを参照してください。クライアント ID を作成したくない場合でも、問題ありません。単に空白のままにして、他の手順を続行することができます。

Google アプリケーション クライアント 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> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com    
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Google アプリケーション クライアント ID とそのシークレットを入力します

Google クライアント ID をお持ちでない場合は、単に Enter キーを押して、Google アプリケーション クライアント ID とクライアント シークレットの値を空白のままにしておきます。

Google Application Client Id - leave blank normally.
client_id> 
Google Application Client Secret - leave blank normally.
client_secret>

Google ドライブ ファイルへの完全なアクセスを許可するには、「1」(数字の 1)と入力します。繰り返しますが、それはあなたの選択です。フルアクセスを付与したくない場合は、他の選択肢を選択できます。

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

すべてのファイルへのフルアクセスを有効にする

「root_folder_id」と「service_account_file」プロンプトでは、空白のままにして Enter キーを押してデフォルト値を受け入れます。

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>  ##Leave blank and press ENTER
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> ##Leave blank and press ENTER

次に、詳細設定ファイルを編集するかどうかを尋ねられます。編集したくないので、「n」 を入力し、Enter キーを押して続行します。

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

最後に、「Y」 を押して自動構成 (デフォルト) を使用し、Rclone 構成タスクを完了します。

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

Web ブラウザが開き、続行するには Google アカウントを選択するよう求められます。複数の Google アカウントにログインしている場合は、Rclone に Google ドライブへのアクセスを許可するアカウントを選択してください。

Googleアカウントを選択してください

注意してください client_id の作成中に Google API コンソールからアプリを新規作成した場合は、次のようなメッセージが表示されます。以下に示すようなセキュリティ警告が表示されます。それは正常です。 Google は通常、提出されたアプリを確認するのに数週間かかります。

「詳細」 リンクをクリックしてから、「rclone (安全ではありません) に移動」 リンクをクリックするだけで先に進むことができます。

Googleのセキュリティ警告メッセージ

次に Rclone は Google ドライブへのアクセス許可を求めます。 [続行] ボタンをクリックして、Rclone に Google ドライブへのアクセスを許可します。

RcloneにGoogleアカウントへのアクセスを許可する

ブラウザに成功メッセージが表示されます。

Rcloneの設定が完了しました

ブラウザウィンドウを閉じて、ターミナルに戻ってください。

次に、Google ドライブを共有ドライブとして作成するかどうかを尋ねるメッセージが表示されます。 「n」 と入力し (デフォルトです)、Enter キーを押します。

Configure this as a Shared Drive (Team Drive)?

y) Yes
n) No (default)
y/n> n

新しいリモートの詳細が確認のためにターミナルに表示されます。すべて問題ないようであれば、"y" と入力して Enter キーを押し、リモートの作成を続行します。

y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

Rcloneリモートの作成が完了しました

終わり! 「mygdrive」 という名前の新しいリモートが作成されました。

別のプロバイダー用に別のリモートを作成する場合は、「n」 をクリックし、上記と同じ手順に従います。または、"q" を押して rclone 構成ウィザードを終了します。

Current remotes:

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

次のコマンドを使用すると、いつでも設定されたリモートのリストを表示できます。

rclone listremotes

サンプル出力:

mygdrive:

リモコンの一覧表示

Rcloneを使用してGoogleドライブをローカルにマウントする

ファイル マネージャーから Google ドライブのコンテンツにアクセスするには、まずファイル マネージャーをマウントする必要があります。

Googleドライブをマウントするためのマウントポイントを作成します。 gdrive という名前の新しいマウント ポイントを作成します。

mkdir ~/gdrive

次に、以下に示すように、Rclone を使用して Google ドライブをマウントします。

rclone mount mygdrive: ~/gdrive/

Rcloneを使用してGoogleドライブをマウントする

ここで、「mygdrive」はリモート名、「gdrive」はマウント ポイント名です。それらを独自の値に置き換えてください。

ファイルマネージャーを開くと、 左側にgdrive フォルダーがマウントされていることがわかります。それをクリックして、Google ドライブのコンテンツにアクセスします。

Rcloneを使用してGoogleドライブをローカルにマウントする

今後は、ローカル ファイル マネージャーと同じように、ファイル/フォルダーの作成、コピー、移動、名前変更、削除を行うことができます。ローカル マウント フォルダー (つまり、~/gdrive フォルダー) に置いたものはすべて、Google ドライブにアップロードされます。

以下のように、Google ドライブから特定のディレクトリ/ファイルをマウントすることもできます。

rclone mount remote:path/to/files /path/to/local/mount

コマンドラインからもすべてを行うことができます。

Googleドライブのコンテンツを一覧表示する

コマンドラインから Google ドライブ内のすべてのファイルを表示するには、次のコマンドを実行します。

rclone ls mygdrive:

再度、「mygdrive」を独自のリモート名を使用して置き換えます。

最上位のディレクトリをすべてリストするには、次を実行します。

rclone lsd mygdrive:

ファイルとディレクトリを Google ドライブにコピーする

たとえば、ローカル システムからディレクトリをコピーするには、「"~/test" と言って Google ドライブの 「ostechnix」 というディレクトリにコピーします。 、 走る:

rclone copy ~/test mygdrive:ostechnix

Googleドライブとファイルを同期する

このコマンドは注意して使用する必要があります。デスティネーションはソースと一致するように更新されるため、必要に応じてファイルを削除することも含まれます

同期には宛先での削除が含まれるため、最初に --dry-run または --interactive/- を使用して同期操作をテストすることが常にベスト プラクティスです。データ損失を避けるための i フラグ。

rclone sync -i SOURCE remote:DESTINATION

Rclone には他にも多くのコマンド ライン オプションがあります。これらについては、近々別のガイドで説明する予定です。

Googleドライブをアンマウントする

Google ドライブをアンマウントするには、ターミナル ウィンドウに移動して「rclone mount」コマンドを実行し、「CTRL+c」 を押すだけです。マウントを停止します。

ファイルマネージャーからも同様に実行できます。ファイルマネージャーから、マウントポイント(「gdrive」)を右クリックし、「アンマウント」をクリックします。

アンマウント操作は、マウント ポイントがビジー状態である場合などに失敗する可能性があります。そのような場合は、次のコマンドを使用してマウントを手動で停止できます。

fusermount -u ~/gdrive

結論

このガイドでは、Linux で Rclone を使用して Google ドライブをローカルにマウントする方法と、ローカル ドライブから Google ドライブにファイルをコピーして同期する 2 つの基本操作について説明しました。

関連記事:

  • Linux で Rclone を使用して Dropbox をローカルにマウントする方法
  • Linux で Rclone を使用して Dropbox と Google ドライブ間でファイルを転送する方法

リソース:

  • Rclone ドキュメント

関連記事