rclone 实现 GoogleDrive 同步至 OneDrive

安装 rclone 工具

➜ mkdir /root/rclone
➜ cd /root/rclone 

# 安装 rclone
➜ curl https://rclone.org/install.sh | sudo bash

# fuse 用于挂载
➜  yum install -y fuse

配置 rclone 连接 GoogleDrive

配置 GoogleDrive

➜ rclone config
2021/07/23 09:00:03 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 新建连接
n/s/q> n

# 输入连接别名
name> gd

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 / 1Fichier
   \ "fichier"
...
...
14 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
15 / Google Drive
   \ "drive"
16 / Google Photos
   \ "google photos"
...
...
42 / premiumize.me
   \ "premiumizeme"
43 / seafile
   \ "seafile"
# 输入存储类型的序号(15 Google Drive)
Storage> 15 

Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
# 直接回车
client_id> 

OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
# 直接回车
client_secret> 


Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
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> 1   

ID of the root folder
Leave blank normally.
Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.
Enter a string value. Press Enter for the default ("").
# 直接回车
root_folder_id> 

Service Account Credentials JSON file path 
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.
Enter a string value. Press Enter for the default ("").
# 直接回车
service_account_file> 


Edit advanced config?
y) Yes
n) No (default)
# 直接回车
y/n> 

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
# 输入 n(正通过远程机器连接)
y/n> n


Verification code
Go to this URL, authenticate then paste the code here.
# 将下述的 URL 粘贴至浏览器,进行授权获取授权码
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=2022...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=...UnHng
Enter a string value. Press Enter for the default ("").
# 授权后粘贴授权码
config_verification_code> 4/1AX4XfWjS23E..32hxY_oJ6bBMO8....LvlQf6g

Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
# 直接回车
y/n> 

--------------------
[gd]
type = drive
scope = drive
token = {"access_token":"ya29.a0A.......Yig","token_type":"Bearer","refresh_token":"1//06WCE7nY.....ftuyiRGE9yiY","expiry":"2021-07-23T10:03:37.835469729-07:00"}
team_drive = 
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
# 直接回车
y/e/d> 

Current remotes:
Name                 Type
====                 ====
gd                   drive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
# 输入 q 退出
e/n/d/r/c/s/q> q

挂载 GoogleDrive

➜  mkdir /root/rclone/google
➜  nohup rclone mount gd:/ /root/rclone/google --vfs-cache-mode writes
# 或 rclone mount gd:/ /root/rclone/google --daemon --vfs-cache-mode writes
➜  df -h
➜  rclone df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G  201M  1.8G  11% /run
/dev/sda2        79G   35G   41G  46% /
/dev/sda1       488M  240M  223M  52%
gd:             1.0P     0  1.0P   0% /root/rclone/google

配置 rclone 连接 OneDrive

配置 OneDrive

➜  rclone config

Current remotes:
Name                 Type
====                 ====
gd                   drive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
# 输入 n 创建新的连接
e/n/d/r/c/s/q> n

# 输入连接的别名
name> od

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 / 1Fichier
   \ "fichier"
 2 / Alias for an existing remote
   \ "alias"
...
...
22 / Local Disk
   \ "local"
23 / Mail.ru Cloud
   \ "mailru"
24 / Mega
   \ "mega"
25 / Microsoft Azure Blob Storage
   \ "azureblob"
26 / Microsoft OneDrive
   \ "onedrive"
27 / OpenDrive
   \ "opendrive"
...
...
42 / premiumize.me
   \ "premiumizeme"
43 / seafile
   \ "seafile"
# 输入 OneDrive 的序号
Storage> 26

OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
# 直接回车
client_id> 

OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
# 直接回车
client_secret> 

Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
   \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
# 根据 OneDrive 情况选择(或者直接回车)
region> 

Edit advanced config?
y) Yes
n) No (default)
# 直接回车
y/n> 

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
# 输入 n(正通过远程连接)
y/n> n

For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
        rclone authorize "onedrive"
Then paste the result.
Enter a string value. Press Enter for the default ("").
# 1. 需要在本地电脑下载 rclone:https://rclone.org/downloads/
# 2. 并在本地电脑运行 rclone authorize "onedrive",会打开浏览器引导授权
# 3. 授权后电脑终端会显示授权码
# 例:
# $  ./rclone authorize "onedrive"
# 2021/07/24 00:40:12 NOTICE: Config file "C:\\Users\\1\\.config\\rclone\\rclone.conf" not found - using defaults
# If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=u...._3gM6pQ
# Log in and authorize rclone for access
# Waiting for code...
# Got code
# Paste the following into your remote machine --->
# {"access_token":"eyJ0eXAiOiJKV1QiLCJub25jZSI6InljXzJYVjJRV244alNIU096eTh3Ri1YY29TeHNmMjJSSXJHR0hCa1RMZnciLCJhbGciOiJSUzI1NiIsIng1dCI6....GU49MxSgHEpoQ","expiry":"2021-07-24T01:40:24.4490729+08:00"}
# <---End paste

# 粘贴授权码
config_token{"access_token":"eyJ0eXAiOiJKV1QiLCJub25jZSI6InljXzJYVjJRV244alNIU096eTh3Ri1YY29TeHNmMjJSSXJHR0hCa1RMZnciLCJhbGciOiJSUzI1NiIsIng1dCI6....GU49MxSgHEpoQ","expiry":"2021-07-24T01:40:24.4490729+08:00"}


Type of connection
Enter a string value. Press Enter for the default ("onedrive").
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)
   \ "url"
 4 / Search for a Sharepoint site
   \ "search"
 5 / Type in driveID (advanced)
   \ "driveid"
 6 / Type in SiteID (advanced)
   \ "siteid"
 7 / Sharepoint server-relative path (advanced, e.g. /teams/hr)
   \ "path"
# 输入 OneDrive 账户类型
config_type> 1


Drive OK?
Found drive "root" of type "business"
URL: https://igph-my.sharepoint.com/personal/xchenhao..._org/Documents
y) Yes (default)
n) No
# 直接回车
y/n> 


--------------------
[od]
type = onedrive
token = {"access_token":"eyJ0eXAiOiJKV1QiLCJub25jZS.......29TeHNmMjJSSXJHR0hCa1RMZnciLCJhbGciOiJSUzI1NiIsIng1dCI....oXm8Bb7WEv-o0EoA","token_type":"Bearer","refresh_token":"0.AV0Ar4aOTlX1...HEpoQ","expiry":"2021-07-24T01:40:24.4490729+08:00"}
drive_id = b!AudODz2rqU2jDfDk3eplbwK4HpsTVc5fOqAcTp
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
# 直接回车
y/e/d> 


Current remotes:
Name                 Type
====                 ====
gd                   drive
od                   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

挂载 OneDrive

➜  mkdir /root/rclone/one
➜  nohup rclone mount od:/ /root/rclone/one --vfs-cache-mode writes
# rclone mount od:/ /root/rclone/one --daemon --vfs-cache-mode writes
➜  df -h
➜  rclone df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G  201M  1.8G  11% /run
/dev/sda2        79G   35G   41G  46% /
/dev/sda1       488M  240M  223M  52%
od:             5.0T  1.7M  5.0T   1% /root/rclone/one
gd:             1.0P     0  1.0P   0% /root/rclone/google

从 GoogleDrive 同步文件至 OneDrive

➜  yum install screen

# 同步大量数据使用 screen 会话尽可能保护 rclone 执行不被中断
➜  screen -S syntask

# 将 GoogleDrive 中的目录(如 rsc)同步至 OneDrive
➜  rclone copy gd:/rsc od:/rsc

其它

取消挂载

# 取消挂载 GoogleDrive
fusermount -qzu  /root/rclone/google 
# 取消挂载 OneDrive
fusermount -qzu  /root/rclone/one

参考

  • https://rclone.org/ Rclone
  • https://cyhour.com/825/ 参考使用 rclone 将 Google Drive 文件同步至 OneDrive
  • https://shikey.com/2020/04/10/rclone-google-drive-v15.html 利用 Rclone 挂载 Google Drive/OneDrive
  • https://blog.csdn.net/hzlarm/article/details/107127717 Rclone 连接 Google Drive
  • https://www.jianshu.com/p/4f9cd009f590 rclone 挂载 Onedrive
  • https://streamelody.github.io/2018/09/rclone-gdrive-baidupcs/ GCP 上使用 rclone 挂载 GoogleDrive+百度盘下载
  • https://blog.6yfz.cn/tutorial/mover-onedrive.html 网盘转存-将文件转存到 OneDrive
上一篇:Eliassen Group vendor 检测眼球视线的oa 又细又多做不完


下一篇:Sentinel核心源码解析