Rclone 入门指南

这是一篇发布于 864 天前的文章,部分信息可能已发生改变。

之前一直把各种 PT 下下来的东西丢到 GD 上保存,但是每次去手动备份 / 下载文件的时候都因为记不住命令,需要去翻一次剪贴板历史或者是看一次官方手册,刚好最近有时间,就写个 Rclone 的教程吧。

Rclone 配合 Screen 食用效果更佳哟,你可以去看看关于的 Screen 这篇文章

关于 AutoRclone 和 SA 的创建你可以去看看我的 这篇文章

安装 rclone

Windows

Debian 家族系统安装

因为有官方脚本的加持,所以 rclone 的安装非常非常简单,root 用户执行下面两行命令即可安装:

1
2
3
4
5
# 安装 curl unzip 
apt update && apt install curl unzip -y

#安装rclone
curl https://rclone.org/install.sh | bash

Centos 家族系统安装

1
2
3
4
5
6
7
8
9
yum update
yum install epel-release
yum install curl unzip screen fuse fuse-devel
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64
sudo cp rclone /usr/bin/
sudo chown root:root /usr/bin/rclone
sudo chmod 755 /usr/bin/rclone

安装完成后你可以在终端中输入 rclone --version 来检查你的 rclone 是否已经安装。

1
2
3
4
~ # rclone --version
rclone v1.53.1
- os/arch: linux/amd64
- go version: go1.15

当你看到类似上述结果的输出时,就证明你的 rclone 已经正确安装了。

配置 rclone

首先,输入rclone config 然后按照下面的注释去走就好。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n #输入n,新建一个remote
name> google-drive #起个名字,这里以 google-drive 为例,后面同步文件时会用到
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 Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
\ "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 #输入12,选择 Google Drive
** See help for drive backend at: https://rclone.org/drive/ **

Google Application Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> #留空,直接回车
Google Application Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> #留空,直接回车
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 #这里选1,Full access
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> #留空,直接回车
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> #留空,直接回车
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 or Y didn't work
y) Yes
n) No
y/n> n #输入n,不使用自动配置
#回车之后会出现一串网址,复制网址到电脑浏览器打开,登陆自己的谷歌账号,获得授权code,复制此code
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815644.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=3bnvsdf3514f98710fe9c9ef38770lkmxa
Log in and authorize rclone for access
Enter verification code> 4/fABXKI1n3Q6Go5k28QJWLgruilsmszhRf8w9bRRqFVihPb08lpddbw #粘贴code,回车
Configure this as a team drive?
y) Yes
n) No
y/n> n #输入 n,不配置为团队盘,但是如果你想挂载团队盘的话这里得输入 Y,然后跟着提示走即可。
--------------------
[google-drive]
type = drive
scope = drive
token = {"access_token":"ya29.Gls6Bs6JkTo3HCfXKpeUv-Hg9uq9QXPZ-itJum2cv2xDAeUTUp15qAlh2FVrGtuDhpRyBp-6bx0dMPj","token_type":"Bearer","refresh_token":"1/4zPbnV-XGj3Ld_Rggr6E5_2mzSu5Cu4qkw_OZ8e-pgDulS78OZka","expiry":"2020-10-01T14:13:46.118120025Z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y #输入y,确认
Current remotes:

Name Type
==== ====
google-drive 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,退出配置

至此,rclone 的配置已经完成,可以用来上传下载数据了,也可以挂载,像本地硬盘一样操作里面的数据。

挂载为本地磁盘

1
2
3
cd /mnt && mkdir google_drive
#挂载
rclone mount DriveName:Folder LocalFolder --allow-non-empty --allow-other --transfers 2 --buffer-size 32M --low-level-retries 200 --dir-cache-time 12h --vfs-read-chunk-size 32M --vfs-read-chunk-size-limit 1G &

DriveName为初始化配置填的name,Folder为Google Drive里的文档夹名,LocalFolder为服务器上的本地文档夹名。

参数

挂载参数

参数说明
–allow-non-empty允许在非空目录上挂载。
–allow-other允许访问其他用户。
–allow-root允许访问root用户。
–attr-timeout duration缓存文件/目录属性的时间。 (默认1秒)
–daemon将mount作为守护程序运行(后台模式)。
–daemon-timeout durationrclone响应内核的时间限制(并非所有操作系统都支持)。
–debug-fuse调试FUSE内部-需要-v。
–default-permissions使内核根据文件模式强制执行访问控制。
–dir-cache-time duration是时候缓存目录条目了。 (默认为5m0s)
–dir-perms FileMode目录权限(默认0777)
–file-perms FileMode文件权限(默认0666)
–fuse-flag stringArray直接传递给libfuse / WinFsp的标志或参数。如果需要,请重复。
–gid uint32覆盖文件系统设置的gid字段。 (默认为1000)
-h, –help帮助安装
–max-read-ahead SizeSuffix可以为顺序读取预取的字节数。 (默认为128k)
–no-checksum不要比较下载/下载时的校验和。
–no-modtime不要读/写修改时间(可以加快修改速度)。
–no-seek不允许在文件中查找。
-o, –option stringArraylibfuse / WinFsp的选项。如果需要,请重复。
–poll-interval duration等待两次轮询更改之间的时间。必须小于dir-cache-time。仅在受支持的遥控器上。设置为0禁用。 (默认为1m0s)
–read-only挂载为只读。
–uid uint32覆盖文件系统设置的uid字段。 (默认为1000)
–umask int覆盖文件系统设置的权限位。
–vfs-cache-max-age duration缓存中对象的最长期限。 (默认为1h0m0s)
–vfs-cache-max-size SizeSuffix缓存中对象的最大总大小。 (默认关闭)
–vfs-cache-mode CacheMode缓存模式 关闭(off)
–vfs-cache-poll-interval duration轮询缓存以查找陈旧对象的时间间隔。 (默认为1m0s)
–vfs-read-chunk-size SizeSuffix逐块读取源对象。 (默认为128M)
–vfs-read-chunk-size-limit SizeSuffix如果大于–vfs-read-chunk-size,则在每次读取块后将块大小加倍,直到达到限制。 “关闭”是无限的。 (默认关闭)
–volname string设置卷名(并非所有操作系统都支持)。
–write-back-cache使内核缓冲区写入,然后再将其发送到rclone。否则,将使用直写式缓存。

全部的挂载参数可以参考官方的文档

全局参数

参数说明
–ask-password允许提示输入密码以进行加密配置。 (默认为true)
–auto-confirm如果启用,请勿请求控制台确认。
–backup-dir string使备份成为基于DIR的层次结构。
–bind string绑定到传出连接的本地地址,IPv4,IPv6或名称。
–buffer-size SizeSuffix读取每个–transfer文件时的内存缓冲区大小。 (默认为16M)
–bwlimit BwTimetable带宽限制(千字节/秒),或者使用后缀b
–ca-cert string用于验证服务器的CA证书
–cache-dir string目录rclone将用于缓存。 (默认为”$HOME/.cache/rclone”)
–checkers int要并行运行的检查程序数。 (默认为8)
-c, –checksum根据校验和(如果有)和大小(而不是修改时间和大小)跳过
–client-cert string用于相互TLS身份验证的客户端SSL证书(PEM)
–client-key string用于相互TLS身份验证的客户端SSL私钥(PEM)
–compare-dest string使用DIR从服务器端复制文件。
–config string配置文件。 (默认为”$HOME/.config/rclone/rclone.conf”)
–contimeout duration连接超时(默认为1m0s)
–copy-dest string也将dest与DIR进行比较。
–cpuprofile string将cpu配置文件写入文件
–delete-after同步时,传输后删除目标位置上的文件(默认)
–delete-before同步时,在传输之前删除目标文件
–delete-during同步时,在传输过程中删除文件
–delete-excluded从同步中删除目标上的文件
–disable string禁用以逗号分隔的功能列表。使用帮助查看列表。
-n, –dry-run在没有永久更改的情况下进行试运行
–dump DumpFlags要转储的项目列表:标头,正文,请求,响应,身份验证,过滤器,goroutines,openfiles
–dump-bodies转储HTTP标头和正文-可能包含敏感信息
–dump-headers转储HTTP标头-可能包含敏感信息
–drive-server-side-across-configs允许服务器对拷
–exclude stringArray排除文件匹配模式
–exclude-from stringArray从文件中读取排除模式
–exclude-if-present string如果文件名存在,则排除目录
–fast-list如果可用,请使用递归列表。使用更多的内存,但更少的事务。
–files-from stringArray从文件中读取源文件名列表
-f, –filter stringArray添加文件过滤规则
–filter-from stringArray从文件中读取过滤模式
–ignore-case忽略过滤器中的大小写(不区分大小写)
–ignore-case-sync同步时忽略大小写
–ignore-checksum跳过校验和的过帐副本检查。
–ignore-errors即使有I / O错误也要删除
–ignore-existing跳过目标上存在的所有文件
–ignore-size跳过使用mod-time或checksum时忽略大小。
-I, –ignore-times不要跳过匹配大小和时间的文件-传输所有文件
–immutable不要修改文件。如果现有文件已被修改,则失败。
–include stringArray包含文件匹配模式
–include-from stringArray从文件中读取包含模式
–log-file string将所有内容记录到该文件
–log-format string日志格式选项的逗号分隔列表(默认为“日期,时间”)
–log-level string日志级别DEBUG
–low-level-retries int低级重试次数。 (默认为10)
–max-age Duration仅传输s或后缀ms
–max-backlog int同步或检查积压的最大对象数。 (默认为10000)
–max-delete int同步时,限制删除次数(默认为-1)
–max-depth int如果设置,则将递归深度限制为此。 (默认为-1)
–max-size SizeSuffix仅传输小于k或后缀b
–max-stats-groups int要保留在内存中的统计信息组的最大数量。在最大的最旧的位置将被丢弃。 (默认为1000)
–max-transfer SizeSuffix要传输的最大数据大小。 (默认关闭)
–memprofile string将内存配置文件写入文件
–min-age Duration仅传输s或后缀ms
–min-size SizeSuffix仅传输大于k或后缀b
–modify-window duration认为最大时间差相同(默认为1ns)
–multi-thread-cutoff SizeSuffix对于此大小以上的文件,请使用多线程下载。 (默认为250M)
–multi-thread-streams int用于多线程下载的最大流数。 (默认为4)
–no-check-certificate不要验证服务器SSL证书。不安全
–no-gzip-encoding不要设置Accept-Encoding:gzip。
–no-traverse不要遍历副本上的目标文件系统。
–no-update-modtime如果文件相同,请不要更新目标模块时间。
-P, –progress在传输过程中显示进度。
-q, –quiet打印尽可能少的东西
–rc启用远程控制服务器。
–rc-addr stringIP地址:端口或:端口绑定服务器。 (默认为“ localhost:5572”)
–rc-allow-origin string设置允许的CORS原点。
–rc-baseurl stringURL的前缀-根目录留空。
–rc-cert stringSSL PEM密钥(证书和CA证书的串联)
–rc-client-ca string客户证书颁发机构用来验证客户端
–rc-files string要在HTTP服务器上提供服务的本地文件的路径。
–rc-htpasswd stringhtpasswd文件-如果未提供,则不进行身份验证
–rc-job-expire-duration duration使已完成的异步作业过期,且早于该值(默认值为1m0s)
–rc-job-expire-interval duration检查过期的异步作业的时间间隔(默认为10s)
–rc-key stringSSL PEM私钥
–rc-max-header-bytes int请求标头的最大大小(默认为4096)
–rc-no-auth某些方法不需要身份验证。
–rc-pass string认证密码。
–rc-realm string身份验证领域(默认为“ rclone”)
–rc-serve启用投放远程对象。
–rc-server-read-timeout duration服务器读取数据的超时时间(默认为1h0m0s)
–rc-server-write-timeout duration服务器写入数据的超时时间(默认为1h0m0s)
–rc-user string认证用户名。
–rc-web-fetch-url string用于获取webgui发行版的URL。 (默认为“ https://api.github.com/repos/rclone/rclone-webui-react/releases/latest”)
–rc-web-gui在本地主机上启动WebGUI
–rc-web-gui-update更新/强制更新为Web GUI的最新版本
–retries int如果操作失败,请重试此操作多次(默认值为3)
–retries-sleep duration重试操作失败之间的间隔,例如500ms,60s,5m。 (0禁用)
–size-only仅基于大小跳过,不基于调制时间或校验和
–stats duration打印状态之间的间隔,例如500ms,60s,5m。 (0禁用)(默认1m0s)
–stats-file-name-length int统计资料中的最大档案名称长度。 0为无限制(默认为45)
–stats-log-level string显示–stats输出的日志级别DEBUG
–stats-one-line使统计数据适合一行。
–stats-one-line-date启用–stats-one-line并添加当前日期/时间前缀。
–stats-one-line-date-format string启用–stats-one-line-date并使用自定义格式的日期。将日期字符串括在双引号(“)中。请参见https://golang.org/pkg/time/#Time.Format
–stats-unit string以“位”或“字节” /秒(默认“字节”)的形式在统计数据中显示数据速率
–streaming-upload-cutoff SizeSuffix如果文件大小未知,则切换到分块上传的截止时间。上载到截止时间或文件结束时开始。 (默认为100k)
–suffix string添加到已更改文件的后缀。
–suffix-keep-extension使用–suffix时保留扩展名。
–syslog使用Syslog进行记录
–syslog-facility stringsyslog的功能,例如KERN,USER,…(默认为“ DAEMON”)
–timeout durationIO空闲超时(默认为5m0s)
–tpslimit float将每秒HTTP事务数限制为此。
–tpslimit-burst int–tpslimit的最大事务爆发次数。 (默认为1)
–track-renames同步时,请重命名跟踪文件并在可能的情况下进行服务器端移动
–transfers int多线程传输(要并行运行的文件传输数。) (默认为4)
-u, –update跳过目标上较新的文件。
–use-cookies启用会话cookiejar。
–use-json-log使用json日志格式。
–use-mmap使用mmap分配器(请参阅文档)。
–use-server-modtime使用服务器修改时间而不是对象元数据
–user-agent string将用户代理设置为指定的字符串。默认值为rclone /版本(默认为”rclone/v1.49.5”)
-v, –verbose count打印更多的东西(重复更多)

全部的参数可以参考官方文档

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
rclone config - 以交互式的形式添加rclone的配置,配置保存在.rclone.conf文件中。
rclone mount - 将网盘挂载为本地磁盘
rclone copy - 将文件从源复制到目的地址,跳过已复制完成的。
rclone sync - 将源数据同步到目的地址,只更新目的地址的数据。–dry-run标志来检查要复制、删除的数据
rclone move - 将源数据移动到目的地址。
rclone delete - 删除指定路径下的文件内容。
rclone purge - 清空指定路径下所有文件数据。
rclone mkdir - 创建一个新目录。
rclone rmdir - 删除空目录。
rclone check - 检查源和目的地址数据是否匹配。
rclone ls - 列出指定路径下所有的文件以及文件大小和路径。
rclone lsd - 列出指定路径下所有的目录/容器/桶。
rclone lsl - 列出指定路径下所有文件以及修改时间、文件大小和路径。
rclone md5sum - 为指定路径下的所有文件产生一个md5sum文件。
rclone sha1sum - 为指定路径下的所有文件产生一个sha1sum文件。
rclone size - 获取指定路径下,文件内容的总大小。.
rclone version - 查看当前版本。
rclone cleanup - 清空remote。
rclone dedupe - 交互式查找重复文件,进行删除/重命名操作。

rclone copy

这个可能是是使用最频繁的命令了,可以把文件从一个地拷贝到另外一个地方,且会跳过已复制完成的

1
rclone copy source:sourcepath dest:destpsth

但是上面这条命令并不会显示进度,所以我更多的是使用下面这条命令来进行备份

1
rclone copy -P source:sourcepath dest:destpsth

如果要增量备份且限制最大上行速度,可以使用下面这条命令

1
rclone copy -P --size-only --bwlimit 20M source:sourcepath dest:destpsth

同时,rclone 默认为 4 线程,如果想改变线程数的话,加上--transfers 8 即可。

1
rclone copy -P --size-only --bwlimit 20M source:sourcepath dest:destpsth --transfers 8
  • 注:
  1. rclone copy 复制总是指定路径下的数据;而不是当前目录。

rclone sync

同步数据

1
rclone sync source:path dest:path
  • 注:
  1. 同步数据时,可能会删除目的地址的数据;建议先使用–dry-run标志来检查要复制、删除的数据。
  2. 同步数据出错时,不会删除任何目的地址的数据。
  3. rclone sync同步的始终是path目录下的数据,而不是path目录。(空目录将不会被同步)

rclone move

移动数据

1
rclone move source:path dest:path
  • 注:
  1. 同步数据时,可能会删除目的地址的数据;建议先使用–dry-run标志来检查要复制、删除的数据。

rclone purge

删除一个目录下所有数据

1
rclone purge remote:path
  • 注:
  1. 此命令,将会删除path目录下所有数据,请慎重使用!
  2. 删除path目录下部分数据,请使用rclone delete命令

rclone mkdir & rclone rmdir

1
rclone mkdir remote:path
1
rclone rmdir remote:path
  • 注:
  1. rmdir 只能删除空目录,删除非空目录请使用rclone purge

rclone ckeck

检查源和目标地址文件是否匹配。命令格式如下:

1
rclone check source:path dest:path

这条命令其实可以加上--size-only,这样相较于使用 checksum 校验要快很多很多。

rclone ls

列出指定path下,所有的文件以及文件大小和路径。命令格式如下:

1
rclone ls remote:path

rclone lsd

列出指定path下,所有目录、容器、桶。命令格式如下:

1
rclone lsd remote:path

rclone delete

删除指定目录的内容。命令格式如下:

1
rclone delete remote:path
  • 注:
  1. 不同于rclone purgerclone delete可使用include/exclude过滤器选择删除文件内容。
1
2
3
4
5
6
7
8
9
10
# 先检查哪些文件将被删除
# 使用rclone lsl 列出大于100M的文件
rclone --min-size 100M lsl remote:path
# 使用--dry-run 检查将要被删除的文件
rclone --dry-run --min-size 100M delete remote:path
# 删除最大100k的图片
rclone --dry-run --max-size 100k delete onedrive:/images

# 使用 rclone delete 进行文件删除
rclone --min-size 100M delete remote:path

rclone size

获取指定path下所有数据文件的总大小。命令格式如下:

1
rclone size remote:path