Linux下使用rclone掛載網盤到本地


Linux下使用rclone掛載網盤到本地

Rclone是一個支持掛載多數國外網盤的工具。

Rclone官網傳送們

目前Rclone支持掛載的網盤有:Google Drive、 Dropbox 、Google Cloud Storage 、Microsoft One Drive 、Hubic、 Backblaze B2 、Yandex Disk 、Openstack Swift / Rackspace cloud files / Memset Memstore 等。更強大的是,Rclone還支持SFTP 、FTP 、HTTP掛載。

配置步驟(以Ubuntu為例)

第一步:安裝rclone

方法一:rclone一鍵安裝腳本
curl https://rclone.org/install.sh | sudo bash

方法二:
wget https://www.moerats.com/usr/shell/rclone_debian.sh && bash rclone_debian.sh

第二步:授權(以onedrive為例)

rclone authorize "onedrive"

會出現以下信息:

2018/01/23 20:28:56 NOTICE: Config file "C:\\Users\\Administrator\\.config\\rclo
ne\\rclone.conf" not found - using defaults
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p  #這里選擇個人版,你想掛載Business就選擇b
If your browser doesn't open automatically go to the following link: http://127.
0.0.1:53682/auth  #接下來會彈出瀏覽器,要求你登錄賬號進行授權
Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"xxxx"}  #請復制{xx}整個內容,后面需要用到
<---End paste

第三步:配置(鏈接網盤,以onedrive為例)

rclone config

會出現以下信息:

n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Rats             #隨便填,后面要用到
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Box
   \ "box"
 5 / Cache a remote
   \ "cache"
 6 / Dropbox
   \ "dropbox"
 7 / Encrypt/Decrypt a remote
   \ "crypt"
 8 / FTP Connection
   \ "ftp"
 9 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
10 / Google Drive
   \ "drive"
11 / Hubic
   \ "hubic"
12 / Local Disk
   \ "local"
13 / Microsoft Azure Blob Storage
   \ "azureblob"
14 / Microsoft OneDrive
   \ "onedrive"
15 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
16 / Pcloud
   \ "pcloud"
17 / QingCloud Object Storage
   \ "qingstor"
18 / SSH/SFTP Connection
   \ "sftp"
19 / Webdav
   \ "webdav"
20 / Yandex Disk
   \ "yandex"
21 / http Connection
   \ "http"
Storage> 14      #選擇14,Microsoft OneDrive
Microsoft App Client Id - leave blank normally.
client_id>       #留空 
Microsoft App Client Secret - leave blank normally.
client_secret>   #留空 
Remote config
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p           #這里選擇個人版,你想掛載Business就選擇b
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n           #選擇n
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
    rclone authorize "onedrive"
Then paste the result below:
result> {"access_token":""}  #輸入之前在客戶端授權的內容
--------------------
[Rats]
client_id = 
client_secret = 
token = {"access_token":""}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y        #  選擇y
Current remotes:

Name                 Type
====                 ====
Rats                 onedrive

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中的OneDrive掛載到本地/home/songtianlun/onedrive目錄下,並清空本地目錄內容(--allow-non-empty)

rclone mount OneDrive: /home/songtianlun/onedrive --allow-non-empty

注:網盤目錄和本地目錄名稱不可一致,否則報錯

利用Screen讓Rclone在后台運行

screen -S onedrive

之后再運行掛載命令。

掛載完成后再用快捷鍵CTRL-a d 來暫時斷開當前會話。最后用screen -r <screen_pid>重新連接上。

若沒有安裝Screen,可以使用如下命令安裝:

yum install screen  #centos系統
apt-get install screen  #debian/ubuntu系統

掛載效果:

第五步:卸載磁盤

fusermount -qzu LocalFolder

# LocalFolder 為本地掛載目錄

常用命令

rclone config – 以控制會話的形式添加rclone的配置,配置保存在.rclone.conf文件中。 
rclone copy – 將文件從源復制到目的地址,跳過已復制完成的。 
rclone mount-掛載
rclone sync – 將源數據同步到目的地址,只更新目的地址的數據。 
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 – 交互式查找重復文件,進行刪除/重命名操作。

參考文獻


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM