接触Obsidian以后,决心将笔记从OneNote转换成Markdown格式,再由Obisian管理,同步则还是用OneDrive。OneDrive在Linux下没有客户端,不过可以借助Rclone与OneDrive API交互做同步。

安装

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

配置

Rclone的文档相当齐全,这里参考https://rclone.org/onedrive/ 进行配置。终端输入

rclone config

按提示设定storage的名称(这里设定为onedrive),选择storage类型为Microsoft OneDrive,随后Rclone会唤起浏览器打开登录页面

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
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
[snip]
XX / Microsoft OneDrive
   \ "onedrive"
[snip]
Storage> 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
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
n) No
y/n> y
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 / 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!Eqwertyuiopasdfghjklzxcvbnm-7mnbvcxzlkjhgfdsapoiuytrewqk
Chose drive to use:> 0
Found drive 'root' of type 'business', URL: https://org-my.sharepoint.com/personal/you/Documents
Is that okay?
y) Yes
n) No
y/n> y
--------------------
[remote]
type = onedrive
token = {"access_token":"youraccesstoken","token_type":"Bearer","refresh_token":"yourrefreshtoken","expiry":"2018-08-26T22:39:52.486512262+08:00"}
drive_id = b!Eqwertyuiopasdfghjklzxcvbnm-7mnbvcxzlkjhgfdsapoiuytrewqk
drive_type = business
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

使用

复制

从本地复制到OneDrive:

rclone copy ./Note onedrive:Note --exclude '.*/' --progress
  • --exclude '.*/':忽略以.开头的文件夹
  • --progress:显示进度

同步

从本地同步到OneDrive:

rclone sync ./Note onedrive:Note --exclude '.*/' --progress

由于OneDrive没有提供删除文件的API,所以这里用rclone copyrclone sync的效果是一样的。不过如果用的是其它类型的云,那么rclone sync有可能导致文件删除,因此最好先用--dry-run预演一下。另外值得注意的是,目前rclone sync只能单向同步

挂载

挂载OneDrive目录到本地:

rclone mount onedrive: ~/onedrive --daemon --vfs-cache-mode full

GUI

打开Rclone提供的Web GUI

rclone rcd --rc-web-gui

可以通过这个界面管理配置、挂载目录等