最近在网上看到900G的视频资源,可惜是在Google Drive里,难为我在大天朝,还这么大的资源,只能想其他办法了,想起了前一阵从群友那里搞了Onedrive 5T的网盘,速度在国内还不错。然后就寻思着怎么把数据同步过去,找到了一个叫Rclone的东西,可以同步网盘资源,可惜的是不支持百度云网盘和其他网盘同步,不过对于我来说足够了。

安装RClone

准备一台Linux VPS用来同步数据,我用的国外的VPS进行同步的数据,900G+的资源需要流量大概是1900G左右,买国外主机需要注意一下了,主机系统CentOS 7.2

执行下面的命令进行安装

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

获取OneDrive授权码

找一台电脑下载rclone界面版,我这里是Windows,所以我下载的是Windows版,后面的操作都是Windows
下载地址:https://rclone.org/downloads/
下载后解压到文件夹到C盘根目录,重命名文件夹为rc,打开终端,我这里用的是Git Bash,你也可以选择用其他的

cd C:/rc
./rclone authorize "onedrive"

后面会打开浏览器,跳转到登录认证的地方,输入对应的OneDrive账号密码登录,等待浏览器上显示

Success!

    
All done. Please go back to rclone.

然后复制终端上的一长串的内容,先记录下来,复制的内容包括{}

{"access_token":"***************########################################################################################################################**************************************************************************************************************************************************************************************************************$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","expiry":"2018-09-01T01:43:55.5290909+08:00"}

连接Google Drive

连接 Google Drive,执行命令进入配置菜单:rclone config

初次进入会有如下菜单提示:

#~:rclone config
No remotes found - make a new one
n) New remote -> 连接新远程网盘
s) Set configuration password -> 设置密码保护配置信息
q) Quit config -> 退出
n/s/q>

需要加密码保护配置信息就按 s 进入设置密码,若不需要,按 n 进入连接网盘。

注意后面的过程中会有提示你复制连接打开浏览器登录Google账号获取授权,然后获取授权Code

n/s/q> n
name> gdrive -> 网盘名字,写一个方便自己识别的名字就好
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 / Alias for a existing remote
   \ "alias"
 2 / Amazon Drive
   \ "amazon cloud drive"
 3 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
   \ "s3"
 4 / Backblaze B2
   \ "b2"
 5 / Box
   \ "box"
 6 / Cache a remote
   \ "cache"
 7 / Dropbox
   \ "dropbox"
 8 / Encrypt/Decrypt a remote
   \ "crypt"
 9 / FTP Connection
   \ "ftp"
10 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
11 / Google Drive
   \ "drive"
12 / Hubic
   \ "hubic"
13 / JottaCloud
   \ "jottacloud"
14 / Local Disk
   \ "local"
15 / Mega
   \ "mega"
16 / Microsoft Azure Blob Storage
   \ "azureblob"
17 / Microsoft OneDrive
   \ "onedrive"
18 / OpenDrive
   \ "opendrive"
19 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
20 / Pcloud
   \ "pcloud"
21 / QingCloud Object Storage
   \ "qingstor"
22 / SSH/SFTP Connection
   \ "sftp"
23 / Webdav
   \ "webdav"
24 / Yandex Disk
   \ "yandex"
25 / http Connection
   \ "http"
Storage> 11  我这里 11 是 Google Drive

Google Application Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> 留空,按回车下一步就好

Google Application 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> 2  注意 1 是拥有所有权限,包括删除;2 是只能访问所有文件,不能删除,按需要选择吧

ID of the root folder
Leave blank normally.
Fill in to access "Computers" folders. (see docs).
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.
Enter a string value. Press Enter for the default ("").
service_account_file> -> 留空,按回车下一步就好

Edit advanced config? (y/n)
y) Yes
n) No
y/n> n -> 一般不需要高级设置,选择 n 就好

Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> n -> 如果是在 VPS 上连接,选 n 吧

If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=**************************************
Log in and authorize rclone for access
#这里需要访问提示的URL然后登陆账号获取授权的Code码,然后复制过来
Enter verification code> **************zN5****vd5*******************bwZethESs 

Configure this as a team drive?
y) Yes
n) No
y/n> n

--------------------
[remote]
client_id = 
client_secret = 
scope = drive
root_folder_id = 
service_account_file =
token = {"access_token":"XXX","token_type":"Bearer","refresh_token":"XXX","expiry":"2018-09-16T13:57:58.955387075Z"}
--------------------

y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

至此 Google Drive 连接完成,可以执行命令检查一下是否真的能连接上:

列出顶级文件夹,(gdrive 是前面第一步设置的名字,如果配置设置了密码会提示输入密码)

rclone lsd gdrive:

列出所有文件

rclone ls gdrive:

连接 OneDrive

连接 OneDrive,方法类似,命令进入配置:rclone config

#~:rclone config

No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/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
 1 / Alias for a existing remote
   \ "alias"
 2 / Amazon Drive
   \ "amazon cloud drive"
 3 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
   \ "s3"
 4 / Backblaze B2
   \ "b2"
 5 / Box
   \ "box"
 6 / Cache a remote
   \ "cache"
 7 / Dropbox
   \ "dropbox"
 8 / Encrypt/Decrypt a remote
   \ "crypt"
 9 / FTP Connection
   \ "ftp"
10 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
11 / Google Drive
   \ "drive"
12 / Hubic
   \ "hubic"
13 / JottaCloud
   \ "jottacloud"
14 / Local Disk
   \ "local"
15 / Mega
   \ "mega"
16 / Microsoft Azure Blob Storage
   \ "azureblob"
17 / Microsoft OneDrive
   \ "onedrive"
18 / OpenDrive
   \ "opendrive"
19 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
20 / Pcloud
   \ "pcloud"
21 / QingCloud Object Storage
   \ "qingstor"
22 / SSH/SFTP Connection
   \ "sftp"
23 / Webdav
   \ "webdav"
24 / Yandex Disk
   \ "yandex"
25 / http Connection
   \ "http"
Storage> 选择对应网盘 我这里是17

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> 填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":"$$$$$$$$$$$$$$","expiry":"2018-09-03T08:43:55.5290909+08:00"}
2018/09/03 07:47:11 ERROR : Failed to save new token in config file: section 'onedrive' not found
--------------------
[onedrive]
type = onedrive
token = {"access_token":"$$$$$$$$$$$$$$","expiry":"2018-09-01T08:43:55.5290909+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=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Chose drive to use:> 这里检测到你账户拥有的OneDrive,填0

Found drive 'root' of type 'business', URL: https://lookertbsteduau-my.sharepoint.com/personal/xxxxxxxxx/Documents
Is that okay?
y) Yes
n) No
y/n> 填y确认

[one]
type = onedrive
token = {"access_token":"xxxxxxxxxxx"}
drive_id = xxxxxxxxxxxx
drive_type = business

y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> 填y确认
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> q

同样,执行 ls 或者 lsd 命令检查是否连接成功:

列出顶级文件夹,(gdrive 是前面第一步设置的名字,如果配置设置了密码会提示输入密码)

rclone lsd onedrive:

列出所有文件

rclone ls onedrive:

然后我们再输入

rclone config

就能看到刚刚添加的网盘了

同步数据

两个网盘都添加完成后,就可以正式开始对拷了

解释一下命令

rclone copy 是复制,配合附加参数 --ignore-existing 可以假装增量备份;

rclone sync 是源目录同步到目标目录,使两者一致,会删除目标目录多余内容,测试时可以加上 --dry-run,检查会复制和删除那些文件。

接着上面的操作,然后退出 rclone,然后输入

yum install screen -y #避免关掉窗口进程关闭
screen rclone copy gdrive: onedrive: #拷贝GoogleDrive网盘内容到OneDrive

如果仅仅只是想同步目录,可以输入下面内容

screen rclone copy gdrive:A onedrive:B #拷贝Google Drive中的A目录内容到OneDrive中的B目录里

就能断开 ssh 让它后台备份了。(会出现假死状态,其实是在运行的)

最后
rclone 这东西不怎么占 cpu 和内存,可以放心使用。而且对小鸡的空间不会有很大影响。再加上 VPS 本身拥有很强大的上传和下载能力,备份效果非常棒!很快就能完成!

但!建议不要直接用 rclone copy gdrive: onedrive: 会占用空间很大

最后修改:2019 年 04 月 26 日
如果觉得我的文章对你有用,请随意赞赏