rclone 教程

Rclone是一个命令行程序,支持不同网盘的同步上传,下载等功能。
官方地址:https://rclone.org/

安装Rclone

Script installation

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

验证是否安装成功

1
2
3
4
[root@i-2ld7xfi6 ~]# rclone version
rclone v1.54.0
- os/arch: linux/amd64
- go version: go1.15.7

Linux installation from precompiled binary

Fetch and unpack

1
2
3
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64

Copy binary file

1
2
3
sudo cp rclone /usr/bin/
sudo chown root:root /usr/bin/rclone
sudo chmod 755 /usr/bin/rclone

Install manpage

1
2
3
sudo mkdir -p /usr/local/share/man/man1
sudo cp rclone.1 /usr/local/share/man/man1/
sudo mandb

Run rclone config to setup. See rclone config docs for more details.

1
rclone config

Install with docker

1
2
3
4
5
6
7
8
$ docker pull rclone/rclone:latest
latest: Pulling from rclone/rclone
Digest: sha256:0e0ced72671989bb837fea8e88578b3fc48371aa45d209663683e24cfdaa0e11
...
$ docker run --rm rclone/rclone:latest version
rclone v1.49.1
- os/arch: linux/amd64
- go version: go1.12.9

Here are some commands tested on an Ubuntu 18.04.3 host:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# config on host at ~/.config/rclone/rclone.conf
# data on host at ~/data

# make sure the config is ok by listing the remotes
docker run --rm \
--volume ~/.config/rclone:/config/rclone \
--volume ~/data:/data:shared \
--user $(id -u):$(id -g) \
rclone/rclone \
listremotes

# perform mount inside Docker container, expose result to host
mkdir -p ~/data/mount
docker run --rm \
--volume ~/.config/rclone:/config/rclone \
--volume ~/data:/data:shared \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro --volume /etc/group:/etc/group:ro \
--device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined \
rclone/rclone \
mount dropbox:Photos /data/mount &
ls ~/data/mount
kill %1

命令详情

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
[root@i-2ld7xfi6 ~]# rclone
Usage:
rclone [flags]
rclone [command]

Available Commands:
about Get quota information from the remote.
authorize Remote authorization.
backend Run a backend specific command.
cat Concatenates any files and sends them to stdout.
check Checks the files in the source and destination match.
cleanup Clean up the remote if possible.
config Enter an interactive configuration session.
copy Copy files from source to dest, skipping already copied.
copyto Copy files from source to dest, skipping already copied.
copyurl Copy url content to dest.
cryptcheck Cryptcheck checks the integrity of a crypted remote.
cryptdecode Cryptdecode returns unencrypted file names.
dedupe Interactively find duplicate filenames and delete/rename them.
delete Remove the files in path.
deletefile Remove a single file from remote.
genautocomplete Output completion script for a given shell.
gendocs Output markdown docs for rclone to the directory supplied.
hashsum Produces a hashsum file for all the objects in the path.
help Show help for rclone commands, flags and backends.
link Generate public link to file/folder.
listremotes List all the remotes in the config file.
ls List the objects in the path with size and path.
lsd List all directories/containers/buckets in the path.
lsf List directories and objects in remote:path formatted for parsing.
lsjson List directories and objects in the path in JSON format.
lsl List the objects in path with modification time, size and path.
md5sum Produces an md5sum file for all the objects in the path.
mkdir Make the path if it doesn't already exist.
mount Mount the remote as file system on a mountpoint.
move Move files from source to dest.
moveto Move file or directory from source to dest.
ncdu Explore a remote with a text based user interface.
obscure Obscure password for use in the rclone config file.
purge Remove the path and all of its contents.
rc Run a command against a running rclone.
rcat Copies standard input to file on remote.
rcd Run rclone listening to remote control commands only.
rmdir Remove the empty directory at path.
rmdirs Remove empty directories under the path.
serve Serve a remote over a protocol.
settier Changes storage class/tier of objects in remote.
sha1sum Produces an sha1sum file for all the objects in the path.
size Prints the total size and number of objects in remote:path.
sync Make source and dest identical, modifying destination only.
touch Create new file or change file modification time.
tree List the contents of the remote in a tree like fashion.
version Show the version number.

Use "rclone [command] --help" for more information about a command.
Use "rclone help flags" for to see the global flags.
Use "rclone help backends" for a list of supported services.

rclone config

官方文档:https://rclone.org/commands/rclone_config/

查看默认配置文件的位置

1
2
3
[root@i-2ld7xfi6 rclone]# rclone config file
Configuration file is stored at:
/root/.config/rclone/rclone.conf

rclone 编辑配置

  • 使用rclone config按照提示一步步配置
1
2
3
4
5
6
7
[root@i-2ld7xfi6 ~]# rclone config
2021/02/07 20:18:22 NOTICE: Config file "/root/.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>
  • 编辑配置文件/root/.config/rclone/rclone.conf,以s3为例
1
2
3
4
5
6
7
8
9
10
[root@i-2ld7xfi6 rclone]# vim rclone.conf
[s3-overseas]
type = s3
provider = AWS
env_auth = false
access_key_id = <your-aws-access-key-id>
secret_access_key = <your-aws-secret-access-key>
region = <your-region-id>
acl = public-read
endpoint = https://s3.<your-region-id>.amazonaws.com

配置文件详解
[s3-overseas]: 定义该S3在本地的一个别名,后续执行命令时方便调用
type: 指定该配置的类型
provider: 存储的提供商,具体可参照官方文档
env_auth: 是否从环境变量中读取
access_key_id: 有权限操作bucket的 AK
secret_access_key: 有权限操作bucket的 SK
region: bucket所处的地区
acl: 上传的文件的权限
endpoint: bucket的加速地址 点击查看AWS加速节点

如果 env_auth 配置为 true , 可以避免在rclone.conf中写上AWS的key和secret,而是直接使用~/.aws/中的配置
也可以在运行rclone时,通过指定环境变量AWS_PROFILE=来使用某一个profile

-------------本文结束感谢您的阅读-------------