Ubuntu安裝配置rclone(Onedrive應用)


rclone安裝

命令行安裝

腳本安裝

curl https://rclone.org/install.sh | sudo bash
# 或者
curl https://rclone.org/install.sh | sudo bash -s beta  # 測試版

源文件安裝

從預編譯二進制文件安裝:curl命令可換為wget、axel,當然也可以直接(瀏覽器)手動下載

# 1. 獲取源文件並解壓縮,然后切換到解壓目錄
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64

# 2. 復制二進制文件並修改用戶(組)權限
sudo cp rclone /usr/bin/
sudo chown root:root /usr/bin/rclone
sudo chmod 755 /usr/bin/rclone

deb包安裝

下載對應deb包:https://rclone.org/downloads/

dpkg命令

sudo dpkg -i xxx.deb
sudo apt-get install -f

gdeb命令

sudo apt install gdebi-core   # 安裝第三方工具
sudo gdebi xxx.deb

rclone配置

獲取客戶端ID和密鑰

在默認情況下執行請求時,rclone使用所有rclone用戶共享的一對客戶端ID和密鑰。

可以按照以下步驟獲取自己的客戶ID和密鑰

  1. 打開https://apps.dev.microsoft.com/#/appList ,然后單擊添加應用(Add an app) 。
  2. 輸入應用的名稱,然后點擊“繼續”。 應記下應用程序 ID(Application Id)以便配置中使用
  3. 在“應用程序機密(Application Secrets)”下,單擊“ 生成新密碼(Generate New Password)“ ,系統會隨即機生成一段密碼。注意:此密碼只出現一次,應立即復制並保存該密碼以便配置中使用。
  4. 在”平台(Platforms)“下,單擊“添加平台(Add platform)” ,然后單擊Web 。 在”重定向URL(Redirect URLs)“輸入http://localhost:53682/
  5. 在”Microsoft Graph 權限(Microsoft Graph Permissions)“下 ,添加委派的權限(delegated permissions):Files.ReadFiles.ReadWriteFiles.Read.AllFiles.ReadWrite.Alloffline_accessUser.Read
  6. 滾動到底部,然后單擊“ 保存(Save)“ 。

下圖是完成后的截圖示例:

配置向導

配置示例:

客戶端id: 399f84a2-32f5-47fa-a866-d415078a91d9

密鑰:heq****************************

bl@bl:~$ rclone config
Current remotes:    

Name                 Type
====                 ====
onedrive             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> n  # 新建選擇 n  (我已經配置過了1個,所以多了幾個選項)
name> myod      # 自定義配置名稱      	                                    
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 Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
   \ "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 / Koofr
   \ "koofr"
16 / Local Disk
   \ "local"
17 / Mega
   \ "mega"
18 / Microsoft Azure Blob Storage
   \ "azureblob"
19 / Microsoft OneDrive
   \ "onedrive"
20 / OpenDrive
   \ "opendrive"
21 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
22 / Pcloud
   \ "pcloud"
23 / QingCloud Object Storage
   \ "qingstor"
24 / SSH/SFTP Connection
   \ "sftp"
25 / Webdav
   \ "webdav"
26 / Yandex Disk
   \ "yandex"
27 / http Connection
   \ "http"
Storage> 19   # 輸入OneDrive對應的編號
** See help for onedrive backend at: https://rclone.org/onedrive/ **

Microsoft App Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> 399f84a2-32f5-47fa-a866-d415078a91d9     #  應用/客戶端id
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> heq************************    # 密碼/密鑰
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n    # n,不進行高級配置
Remote config
Make sure your Redirect URL is set to "http://localhost:53682/" in your custom config.
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> y   #  y, 同意自動配置,(瀏覽器會自動重定向本地請求授權,成功返回“Success! All done. Please go back to rclone.”)
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
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Type in driveID
   \ "driveid"
 4 / Type in SiteID
   \ "siteid"
 5 / Search a Sharepoint site
   \ "search"
Your choice> 1    #  1,Onedrive個人或者商業版
Found 1 drives, please select the one you want to use:
0:  (personal) id=7bbf0a5dc86d77be
Chose drive to use:> 0   #  0
Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=7bbf0a5dc86d77be
Is that okay?
y) Yes
n) No
y/n> y   # y, 確認版本
--------------------
[myod]
type = onedrive
client_id = 399f84a2-32f5-47fa-a866-d415078a91d9
client_secret = heq****************************
token = {"access_token":"token,通過~/.config/rclone/rclone.conf文件也可以查看","expiry":"2019-04-27T03:12:32.874487926+08:00"}
drive_id = 7bbf0a5dc86d77be
drive_type = personal
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  # y, 確認配置
Current remotes:

Name                 Type
====                 ====
myod                 onedrive
onedrive             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, 退出

測試連接

bl@bl:~$ rclone lsd onedrive:
          -1 2017-06-12 19:00:15         1 Office Online 擴展
          -1 2019-04-26 23:51:59         5 oucbl
          -1 2019-04-26 01:02:53         2 圖片
          -1 2019-02-26 04:03:36         9 文檔
          -1 2017-01-11 22:17:39         0 電子郵件附件

$ rclone lsd onedrive: # 查看當前網盤的目錄。(有時候網絡不穩定,需要多試幾次)

onedrive是rclone配置名,需要修改為自己的配置名稱

掛載Onedrive

普通用戶權限也可以掛載成功,只是使用過程中可能出現一些問題,具體沒深入研究;這里就直接使用管理權限。

有教程推薦使用 screen 在后台運行掛載命令,較穩定一點;這里就不說明了。

掛載遠程目錄到本地

示例:遠程網盤目錄oucbl掛載到本地/home/bl/One-Drive下:

bl@bl:~$ sudo rclone mount onedrive:/oucbl /home/bl/One-Drive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

相關參數解釋如下:

  • --copy-links - 顯示軟鏈接內容
  • --no-gzip-encoding - 不使用 gzip-encoding
  • --no-check-certificate - 不驗證ssl證書
  • --allow-other - 允許其它用戶訪問
  • --allow-non-empty - 允許掛載目錄非空
  • --umask 000 - 覆寫文件掩碼為 000

更多參數選項請參考官方文檔:https://rclone.org/commands/rclone_mount/

停止掛載

一般情況下使用Ctrl+C便可停止掛載,如果停止失敗,使用如下命令停止掛載(本地/home/bl/One-Drive):

bl@bl:~$ sudo fusermount -qzu /home/bl/One-Drive  #停止掛載

備注

1T Onedrive教育申請:https://products.office.com/en-us/student?tab=students


鑒於網絡問題,暫不打算常用,這里不做開機自啟配置了,具體可在參考里面2個博客中查看。


另一個免費OneDrive客戶端:onedrive

github: https://github.com/skilion/onedrive

教程示例:https://www.maketecheasier.com/sync-onedrive-linux/

參考

rclone-rsunc for cloud storage--Configure

https://rclone.org/docs/

rclone-rsunc for cloud storage--Microsoft OneDrive

https://rclone.org/onedrive/

Ubuntu 18.04 手動安裝 rclone 並自動掛載 Google Drive

https://timelate.com/archives/install-rclone-on-ubuntu.html#cl-11

Linux下rclone簡單教程(支持VPS數據同步,多種網盤,支持掛載)

https://ymgblog.com/2018/03/09/296/


免責聲明!

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



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