• PtBoxClub

Linux下rclone简单教程(支持VPS数据同步,多种网盘,支持挂载)

Linux教程 半醉丶 6年前 (2018-03-09) 10446次浏览 0个评论
目录
[隐藏]

因为最近有这个方面的需求,所以简单学习了一下,这里简单介绍一下 rclone 以及基础的用法吧!

1.Rclone 介绍

Rclone 支持 linux 丶 windows 等多个平台,且支持多个已知网盘服务商,如微软的 onedrive,Google Drive 等,Rclone 主要可以用来同步数据丶备份数据以及将网盘挂在到本地使用,且 Rclone 还是支持部分同步的,类似于增量备份。

Github 地址:https://github.com/ncw/rclone

官方网站:https://rclone.org/

这里主要介绍下 Linux 下 Rclone 的用法

Windows 下挂载及使用的详细方法请参考 R 酱的这篇文章:使用 rclone 在 Windows 下挂载 Google 团队云盘

2.Rclone 的安装

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

3.配置

rclone config

以下是全部配置过程,需要操作的地方用红色字体标注了!


root@arm1:~# rclone config
2018/06/12 15:36:43 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> n       **********************选择 n,新建配置文件
name> test       **********************输入配置的名称
Type of storage to configure.
Choose a number from below, or type in your own value
1 / Alias for a existing remote
\ “alias”
2 / Amazon Drive
\ “amazon cloud drive”
3 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
\ “s3”
4 / Backblaze B2
\ “b2”
5 / Box
\ “box”
6 / Cache a remote
\ “cache”
7 / Dropbox
\ “dropbox”
8 / Encrypt/Decrypt a remote
\ “crypt”
9 / FTP Connection
\ “ftp”
10 / Google Cloud Storage (this is not Google Drive)
\ “google cloud storage”
11 / Google Drive
\ “drive”
12 / Hubic
\ “hubic”
13 / Local Disk
\ “local”
14 / Mega
\ “mega”
15 / Microsoft Azure Blob Storage
\ “azureblob”
16 / Microsoft OneDrive
\ “onedrive”
17 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ “swift”
18 / Pcloud
\ “pcloud”
19 / QingCloud Object Storage
\ “qingstor”
20 / SSH/SFTP Connection
\ “sftp”
21 / Webdav
\ “webdav”
22 / Yandex Disk
\ “yandex”
23 / http Connection
\ “http”
Storage> 11       **********************这里是添加 googledrive 云盘,选择 11,当然你也可以添加其它云盘
Google Application Client Id – leave blank normally.
client_id>       **********************回车留空即可
Google Application Client Secret – leave blank normally.
client_secret>       **********************回车留空即可
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>       **********************回车留空即可,这里是云盘 API 权限的设置
ID of the root folder – leave blank normally. Fill in to access “Computers” folders. (see docs).
root_folder_id>       **********************回车留空即可
Service Account Credentials JSON file path – leave blank normally.
Needed only if you want use SA instead of interactive login.
service_account_file>
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,手动配置
If your browser doesn’t open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=20111111644.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=1111111111111111111111       **********************在本地打开这个链接,添加 google 云盘账号授予 rclone 权限
Log in and authorize rclone for access
Enter verification code> 4/AAC8CPF21dYWqRnNSw479Fa8dUb11111111111111111111111111E       **********************输入在浏览器获取的认证 code
Configure this as a team drive?
y) Yes
n) No
y/n> y       **********************是否团队云盘,我这里是,所以选择 Y
Fetching team drive list…
Choose a number from below, or type in your own value
1 / back
\ “0AAbWF01111111111”
2 / back2
\ “0ABf3gOL111111111”
Enter a Team Drive ID> 1       **********************选择一个你要添加的团队云盘
——————–
[test]
type = drive
client_id =
client_secret =
scope =
root_folder_id =
service_account_file =
token = {“access_token”:”ya29.GlvY1111qGBysX4tO_V5ZSO1PZ_Kq1111111111111111fksugvyOFC-MzvAPnl1rsi3OOwMFTdkk11111111H_u5zzPRp0eB_iLzKsZOVzP3R2ee1111AVmO”,”token_type”:”Bearer”,”refresh_token”:”1/r5Q_pH11111111CV-xiMne9_w62y_ag11bT_H9zz7qc”,”expiry”:”2018-06-12T16:37:16.714510063+08:00″}
team_drive = 0AA11111111111111
——————–
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y       **********************输入 y,配置到这里就完成了
Current remotes:

Name Type
==== ====
test 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 退出即可!

 

到这里我们的第一个名字为 google 的Google Drive 云盘就添加完毕了

4.Rclone 基础操作

4.1.复制 rclone copy

从源地址(前面的)复制到目的地址,会自动跳过已存在的文件

rclone copy google:/ /home/data
rclone copy /home/data google:/       //google 是前面设置的网盘名称,google:/是代表网盘的根目录

当然还可以两个网盘互相拷贝复制文件,比如上面通过 rclone config 创建了名称为google这个网盘,你可以再创建名称为google1 的另一个网盘账号,

然后通过以下命令实现网盘文件互相拷贝,这个操作不占用本地磁盘空间。

rclone copy google:/ google1:/

4.2.同步 rclone sync

同步数据会删除目的地址中的文件,比如目的地址中有 1.txt 这个文件,而源地址中没有,则 1.txt 会被删除,请注意

rclone sync google:/data /home/data

比如/home/data 里有 1.txt,而 google 网盘的 data 目录没有,那么/home/data 的 1.txt 就被删除了。

当然你可以利用 cron 写个计划任务定期同步,具体百度吧。

4.3.挂载 rclone mount

这里使用 screen 在后台运行挂载命令,较稳定一点

apt-get install screen
screen -S rmount
rclone mount google:/data /home/data

以上是将网盘的 data 目录挂载到/home/data 目录下,

执行完后同时按 Ctrl+A+D 就可以退出 screen 的窗口,使用 screen -r rmount 可以返回。

注意:挂载的空间是不能用于跑 PT 啥的,有 API 限制的,我试过了老是出错。

 

4.4.其它常见命令

rclone mkdir google:/test   //在云盘根目录创建 test 文件夹
rclone ls google:/          //列出根目录以下所有文件及位置大小
rclone lsd google:/         //列出根目录下所有文件夹

简单的大概就这些操作了,以后发现了什么再补充吧,以上就是以 Google Drive 为例的,其它类似教程都可以从以下获取

 

以上均参考于此:https://rclone.org/drive/

rclone 常见命令介绍:https://rclone.org/commands/

Linux 下 rclone 简单教程(支持 VPS 数据同步,多种网盘,支持挂载)


如无注明,所有文章皆为“半醉”原创,转载请保留文章出处。如有借鉴未注明请发邮件到 [email protected],深表抱歉!
喜欢 (2)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址