VPS加载Microsoft OneDrive到本地盘

之前玩了玩怎么将 Google Drive 加载到本地(本馆档案), 这次试试 Microsoft OneDrive.

主要思路是 –

1- 设置Rclone

  • 1.1 – 在本地的Mac/Windows侧(不是远端的VPS)获得 Token

Onedrive 的 Authorization 需要从本地浏览器打开后自动获取, 所以在我本地的 Mac 上

# download rclone for mac from
# https://rclone.org/downloads/ 
# 在local terminal
./rclone authorize "onedrive"
# 需要打开浏览器登录后产生一段授权码
# 然后 ---> 之后到 <---之间的包括{}在内的所有字符拷贝 = 称之为 Auth_Text
Auth_Text = ‘{“access_token”:”eyJ…+08:00″}’
  • 2.1 – 远程 VPS 设置 Rclone
# 先安装必要的组件
apt install -y fuse

itlwin at ~ ❯ rclone config
Current remotes:
Name                 Type
====                 ====
gdrive_omgd          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> n

name> onedrive_lava

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
...
13 / Google Drive
   \ "drive"
...
23 / Microsoft OneDrive
   \ "onedrive"
...
Storage> 23
** 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>

Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").

client_secret>

Edit advanced config? (y/n)
y) Yes
n) No (default)

y/n> n

Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No

y/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 (same rclone version recommended) :
	rclone authorize "onedrive"
Then paste the result below:

###
### 就是这个时候将 Auth_Text 整个 Paste 到这里 ###
###

result> {"access_token":"eyJ0eXAiOiJKV1-----------","token_type":"Bearer","refresh_token":"OAQABAAAAAAAm-06blBE1TpVMil8KPQ41yYoA-------","expiry":"2020-05-09T20:19:10.976723+08:00"}

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

Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=b!Og4d-jVr7k-q7B3qDsRiRMzqmE7IFj5AsSQGzuJQI-

Chose drive to use:> 0

Found drive 'root' of type 'business', URL: https://wh5vh-my.sharepoint.com/personal/****/Documents

Is that okay?
y) Yes (default)
n) No

y/n> y

--------------------
[onedrive_lava]
type = onedrive
token = {"access_token":"eyJ0eXAiOiJKV1Qi--------","token_type":"Bearer","refresh_token":"OAQABAAAAAAAm--------","expiry":"2020-05-09T20:19:10.976723+08:00"}
drive_id = b!Og4d-jVr7k-q7B3qDsRiRMzqmE7IFj5AsSQGzuJQI
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote

y/e/d> y

Current remotes:

Name                 Type
====                 ====
gdrive_omgd          drive
onedrive_lava        onedrive

2- 测试一下

rclone about onedrive_xyza1pin:

3- Mount

自己先试试

# mount root folder of remote drive
drivename='onedrive_lava'
mkdir -p /root/${drivename}
/usr/bin/rclone mount ${drivename}: /root/${drivename} --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes --daemon

### 卸载
fusermount -qzu /root/${drivename}

开机自动加载

drivename='onedrive_lava'
# ----------------------------
#以下是一整条命令,一起复制到SSH客户端运行 #不能带 --daemon 不然失败
mkdir -p /root/${drivename} && cat > /etc/systemd/system/rclone_${drivename}.service <<EOF
[Unit]
Description=rclone_${drivename}
 
[Service]
User=root
# mount root folder of remote drive
# 根据磁盘大小设定 cache size (--vfs-cache-max-size 6G --vfs-cache-max-age 6h) 也可以只设定 max-age
# 如果用于bt下载和小硬盘的话, 建议比如Aria2当中concurrent download 变成1或2

# 本地硬盘如果够大的话
ExecStart=/usr/bin/rclone mount ${drivename}: /root/${drivename} --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
# 启动(单次)
systemctl start rclone_${drivename}
# 设置开机启动:
systemctl enable rclone_${drivename}
# 停止、查看状态可以用:
systemctl stop rclone_${drivename}
systemctl status rclone_${drivename}

1 thought on “VPS加载Microsoft OneDrive到本地盘”

  1. Pingback: Rclone技巧 & 加载Google Drive到本地目录 – 1024 & 4201

Leave a Reply