本指南将引导您完成在本地安装 Google 驱动器的步骤 克隆 然后在 Linux 操作系统中使用 Rclone 将文件备份到谷歌驱动器。 本指南已在 Manjaro Linux 上进行了正式测试,但所有 Linux 和 Unix 发行版的步骤都相同。
在开始之前,请确保您已经在 Linux 机器上安装了 Rclone。 以下链接包含 Linux 和 Unix 操作系统的 Rclone 安装步骤。
- 如何在 Linux 和 Unix 中安装 Rclone
为了在本地文件管理器上使用 Rclone 挂载 Google 驱动器,您需要从 Google 驱动器获取令牌。 您可以通过两种方式进行操作,从使用“rclone config”命令的命令行和从 rclone WebUI。
让我们先看看命令行方式。
配置 Rclone 以从命令行访问 Google 驱动器
打开终端并运行以下命令以授权 Rclone 访问您的 Google 驱动器:
$ rclone config
这将引导您完成交互式设置过程。
首先,Rclone 将搜索可用遥控器的列表(即 Cloud 提供者)。
由于这是我们的新设置,我们还没有创建任何遥控器。 所以让我们创建一个新的遥控器。
要创建一个新的遥控器,只需键入 "n"
并击中 ENTER
. 然后输入遥控器的名称。 在这里,我将其命名为 “我的驱动器”.
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
将显示支持的云提供商列表。 选择您选择的云提供商。 在我们的例子中。 它是 谷歌驱动器,所以我输入了数字 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
Enter 您的 Google 云端硬盘客户端 ID 及其密码(如果您已经拥有它们)。 如果您没有客户 ID,您可以创建一个新的。
笔记: 请注意,创建 Google 应用程序客户端 ID 是可选的,但是 受到推崇的. 要了解如何创建您自己的 Google Drive 客户端 ID,请参阅 这个链接. 如果您不想创建客户端 ID,没问题! 你可以简单地 留空 并继续其他步骤。
我已经创建了 Google Application Client 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,只需按 ENTER 即可将 Google 应用程序客户端 ID 和客户端密码留空:
Google Application Client Id - leave blank normally. client_id> Google Application Client Secret - leave blank normally. client_secret>
类型 1 (数字 1)授予对您的 Google 云端硬盘文件的完全访问权限。 同样,这是您的选择。 如果您不想授予完全访问权限,您可以选择其他任何一种。
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
最后,按下 “是” 使用自动配置(这是默认设置)来完成 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

现在您的网络浏览器将打开,系统将提示您选择一个 Google 帐户以继续。 如果您登录到多个 Google 帐户,请选择您希望允许 Rclone 访问您的 Google 驱动器的一个。

请注意 如果您在创建 client_id 时从 Google API 控制台新创建了一个应用程序,您将看到如下所示的安全警告。 这是正常的。 Google 通常需要几周时间来验证提交的应用程序。
您只需单击即可继续 “先进的” 链接,然后单击 “转到 rclone(不安全)” 关联。

Next Rclone 将询问您是否允许访问您的 Google 驱动器。 点击 “继续” 按钮以授权 Rclone 访问您的 Google 驱动器。

您将在浏览器中看到一条成功消息。

只是 close 浏览器窗口并返回终端。
接下来,系统会提示您是否要将 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

完毕! 一个名为的新遥控器 “我的驱动器” 刚刚创建。
如果您想为不同的提供商创建另一个遥控器,请单击 "n"
并按照与上图相同的步骤进行操作。 或者,只需按 退出 rclone 配置向导 "q"
.
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 Drive
为了从您的文件管理器访问 Google 驱动器的内容,您需要先挂载它。
创建一个挂载点来挂载你的谷歌驱动器。 我将创建一个名为的新挂载点 gdrive.
$ mkdir ~/gdrive
接下来,使用 Rclone 挂载 Google 驱动器,如下所示:
$ rclone mount mygdrive: ~/gdrive/

这里,“mygdrive”是远程名称,“gdrive”是挂载点名称。 用您自己的价值观替换它们。
现在,打开你的文件管理器,你会看到 gdrive 文件夹安装在左侧。 单击它以访问您的 Google 驱动器的内容。

从现在开始,您可以像在本地文件管理器中一样创建、复制、移动、重命名和删除文件/文件夹。 您放入本地挂载文件夹中的任何内容(即 ~/gdrive
文件夹)将上传到您的 Google 驱动器。
您还可以从谷歌驱动器挂载一个特定的目录/文件,如下所示。
$ rclone mount remote:path/to/files /path/to/local/mount
您也可以从命令行执行所有操作。
列出谷歌驱动器内容
要从命令行查看 Google 驱动器中的所有文件,请运行:
$ rclone ls mygdrive:
再次,使用您自己的远程名称替换“mygdrive”。
要列出顶层的所有目录,请运行:
$ rclone lsd mygdrive:
将文件和目录复制到 Google 云端硬盘
为了 example,从本地系统复制目录,比如说 "~/test"
到一个名为 “骨科” 在您的 Google 驱动器中,运行:
$ rclone copy ~/test mygdrive:ostechnix
与 Google 云端硬盘同步文件
您应该将此命令与 警告. 因为,目标已更新以匹配源, 包括必要时删除文件.
由于同步涉及在目标上删除,因此最好先使用 --dry-run
或者 --interactive
/-i
标志以避免数据丢失。
rclone sync -i SOURCE remote:DESTINATION
Rclone 有许多其他的命令行选项。 我们将很快在单独的指南中介绍它们。
卸载谷歌驱动器
要卸载 Google 驱动器,请转到运行“rclone mount
” 命令并按下 "CTRL+c"
停止安装。
您也可以从文件管理器中执行此操作。 在文件管理器中,右键单击挂载点,即“gdrive”,然后单击卸载。
卸载操作可能会失败,因为 example 当挂载点忙时。 发生这种情况时,您可以使用以下命令手动停止挂载:
$ fusermount -u ~/gdrive
结论
在本指南中,我们了解了如何在 Linux 中使用 Rclone 在本地挂载 Google 驱动器,以及两个基本操作 – 如何将文件从本地驱动器复制和同步到 Google 驱动器。
资源: