之前一直把各种 PT 下下来的东西丢到 GD 上保存,但是每次去手动备份 / 下载文件的时候都因为记不住命令,需要去翻一次剪贴板历史或者是看一次官方手册,刚好最近有时间,就写个 Rclone 的教程吧。
Rclone 配合 Screen 食用效果更佳哟,你可以去看看关于的 Screen 的这篇文章 Screen 的安装和使用
关于 AutoRclone 和 SA 的创建你可以去看看我的 Rclone 进阶 —— AutoRclone + Gclone 这篇文章。
安装 rclone
Windows
Debian 家族系统安装
因为有官方脚本的加持,所以 rclone 的安装非常非常简单,root 用户执行下面两行命令即可安装:
# 安装 curl unzip
apt update && apt install curl unzip -y
#安装rclone
curl https://rclone.org/install.sh | bashCentos 家族系统安装
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 是否已经安装。
~ # rclone --version
rclone v1.53.1
- os/arch: linux/amd64
- go version: go1.15当你看到类似上述结果的输出时,就证明你的 rclone 已经正确安装了。
配置 rclone
首先,输入rclone config 然后按照下面的注释去走就好。
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 的配置已经完成,可以用来上传下载数据了,也可以挂载,像本地硬盘一样操作里面的数据。
挂载为本地磁盘
# 创建挂载目录
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 duration | rclone响应内核的时间限制(并非所有操作系统都支持)。 |
| —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 stringArray | libfuse / 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 string | IP地址:端口或:端口绑定服务器。 (默认为“ localhost:5572”) |
| —rc-allow-origin string | 设置允许的CORS原点。 |
| —rc-baseurl string | URL的前缀-根目录留空。 |
| —rc-cert string | SSL PEM密钥(证书和CA证书的串联) |
| —rc-client-ca string | 客户证书颁发机构用来验证客户端 |
| —rc-files string | 要在HTTP服务器上提供服务的本地文件的路径。 |
| —rc-htpasswd string | htpasswd文件-如果未提供,则不进行身份验证 |
| —rc-job-expire-duration duration | 使已完成的异步作业过期,且早于该值(默认值为1m0s) |
| —rc-job-expire-interval duration | 检查过期的异步作业的时间间隔(默认为10s) |
| —rc-key string | SSL 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 string | syslog的功能,例如KERN,USER,…(默认为“ DAEMON”) |
| —timeout duration | IO空闲超时(默认为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 | 打印更多的东西(重复更多) |
全部的参数可以参考官方文档
使用
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
这个可能是是使用最频繁的命令了,可以把文件从一个地拷贝到另外一个地方,且会跳过已复制完成的
rclone copy source:sourcepath dest:destpsth但是上面这条命令并不会显示进度,所以我更多的是使用下面这条命令来进行备份
rclone copy -P source:sourcepath dest:destpsth如果要增量备份且限制最大上行速度,可以使用下面这条命令
rclone copy -P --size-only --bwlimit 20M source:sourcepath dest:destpsth同时,rclone 默认为 4 线程,如果想改变线程数的话,加上
--transfers 8即可。
rclone copy -P --size-only --bwlimit 20M source:sourcepath dest:destpsth --transfers 8- 注:
rclone copy复制总是指定路径下的数据;而不是当前目录。
rclone sync
同步数据
rclone sync source:path dest:path- 注:
- 同步数据时,可能会删除目的地址的数据;建议先使用–dry-run标志来检查要复制、删除的数据。
- 同步数据出错时,不会删除任何目的地址的数据。
rclone sync同步的始终是path目录下的数据,而不是path目录。(空目录将不会被同步)
rclone move
移动数据
rclone move source:path dest:path- 注:
- 同步数据时,可能会删除目的地址的数据;建议先使用–dry-run标志来检查要复制、删除的数据。
rclone purge
删除一个目录下所有数据
rclone purge remote:path- 注:
- 此命令,
将会删除path目录下所有数据,请慎重使用!- 删除path目录下部分数据,请使用
rclone delete命令
rclone mkdir & rclone rmdir
rclone mkdir remote:pathrclone rmdir remote:path- 注:
- rmdir 只能删除空目录,删除非空目录请使用
rclone purge
rclone ckeck
检查源和目标地址文件是否匹配。命令格式如下:
rclone check source:path dest:path这条命令其实可以加上--size-only,这样相较于使用 checksum 校验要快很多很多。
rclone ls
列出指定path下,所有的文件以及文件大小和路径。命令格式如下:
rclone ls remote:pathrclone lsd
列出指定path下,所有目录、容器、桶。命令格式如下:
rclone lsd remote:pathrclone delete
删除指定目录的内容。命令格式如下:
rclone delete remote:path- 注:
- 不同于
rclone purge、rclone delete可使用include/exclude过滤器选择删除文件内容。
# 先检查哪些文件将被删除
# 使用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:pathrclone size
获取指定path下所有数据文件的总大小。命令格式如下:
rclone size remote:path