之前介绍了通过 gdrive 在服务器上管理 Google drive 文件,实现服务器数据备份自动上传功能。最近发现有一个新的开源项目 rclone 支持更多的网盘,同时更新迭代速度也更快。

GitHub 主页:https://github.com/rclone/rclone

他支持的网盘列表:https://rclone.org/overview/

下面介绍它的安装使用方法。

安装

Linux 下一键安装命令:

curl https://rclone.org/install.sh | sudo bash

macos 通过 brew 安装:

brew install rclone

配置

首次运行执行初始化配置:

rclone config

根据提示创建新 remote:

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

然后设置此连接名称,后续就是通过这个名称来操作不同的网盘的:

name> remote

下一步选择网盘类型,如果是 Google drive 选择 16:

Type of storage to configure.
Choose a number from below, or type in your own value
[snip]
16 / Google Drive
   \ "drive"
[snip]
Storage> 16

下面的 id 和 secret 都默认回车即可:

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

下面设置可访问全部网盘文件,选择 1:

Scope that rclone should use when requesting access from drive.
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

下面几步都默认回车即可。

注意到了 use auto config 的时候要选择 No,因为我们是远程 ssh 访问的服务器:

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> n

下面会返回一个链接,复制链接到浏览器后,登录 google 账户给 rclone 授权。授权完成后会返回一个字符串码,粘贴回终端。

后续几步默认回车即可,最后输入 q 退出 config。

使用

配置完成后我们就可以使用了,下面介绍一些基本语法。下面示例中网盘配置名称为 remote。

列出网盘的所有文件:

rclone ls remote:

列出一个文件夹内的所有文件:

rclone ls remote:abc

创建一个文件夹:

rclone mkdir remote:abc
rclone mkdir remote:abc/def

删除网盘内一个文件:

rclone delete remote:abc/123.txt

删除一个文件夹:

rclone rmdir remote:abc

复制本地一个文件到网盘:

rclone copy 123.txt remote:abc

更多可用命令可以参考官方文档:https://rclone.org/docs/#subcommands

标签:无

你的评论