本片讲述挂载Google Drive扩展你的VPS硬盘并把Aria2下载后的文件自动上传到Google Drive中等玩法。
##一、安装rclone
1
| curl https://rclone.org/install.sh | sudo bash
|
##二、初始化配置
按照下面选择走:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
| Current remotes:
Name Type
==== ====
gdrive 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 这里输入n,新建一个
name> test 输入一个名字,记住之后会用到
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 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> 1 输入1
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 输入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=xxxxxxxxxxxxxxxxxxxxxxxxxx
这里会给你一个链接,打开后用你的Google Drive授权就会得到下面一串代码填入即可
Log in and authorize rclone for access
Enter verification code> 4/rQDL5M58Dv_Mjwxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Configure this as a team drive?
y) Yes
n) No
y/n> y 输入y
Fetching team drive list...
No team drives found in your account--------------------
[test]
type = drive
scope = drive
token = {"access_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","token_type":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","expiry":"2018-12-08T14:45:49.328865767+08:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y 输入y
Current remotes:
Name Type
==== ====
gdrive drive
test 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> q 输入q退出
|
##三、挂载
###1.手动挂载
1
2
3
4
| #新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /root/GoogleDrive
#挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
|
###2.开机自动挂载
新建 /lib/systemd/system/rclone.service
1
| nano /lib/systemd/system/rclone.service
|
写入,注意 gdrive后最好跟盘内的文件夹
1
2
3
4
5
6
7
8
9
10
| [Unit]
Description = rclone
[Service]
User = root
ExecStart = /usr/bin/rclone mount gdrive: /mnt/gdrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
Restart = on-abort
[Install]
WantedBy = multi-user.target
|
重载daemon
1
| systemctl daemon-reload
|
启动Rclone
设置开机自启
1
| systemctl enable rclone
|
##二、Aria2下载完后自动上传
这里用到了Aria2的一个on-download-complete功能,这个功能可以做很多事情,这里只用到了自动上传
新建脚本文件gdupload.sh,并复制下面代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| #!/bin/bash
path="$3" #取原始路径
downloadpath='/data/wwwroot/dd.test.com/download' #下载目录
rclone='/data/wwwroot/dd.test.com/cloud' #rclone挂载的目录
if [ $2 -eq 0 ] #下载文件为0跳出脚本
then
exit 0
fi
while true; do #提取下载文件根路径
filepath=$path
path=${path%/*};
if [ "$path" = "$downloadpath" ] && [ $2 -eq 1 ]
then
rclone=${filepath/#$downloadpath/$rclone} #替换路径
cp -R "${filepath}" "${rclone}"
exit 0
elif [ "$path" = "$downloadpath" ] #文件夹
then
cp -R "${filepath}" "${rclone}"/
exit 0
fi
done
|
注意:本脚本上传下载文件后并没有删除原文件,因为rclone在上传多文件时,可能会丢文件,所以这个脚本并没有删除原文件
如果想要自动删除的话,可以改成下面这样子:
1
2
3
4
5
6
7
8
9
10
11
| .....................前面不变
rclone=${filepath/#$downloadpath/$rclone} #替换路径
mv -f "${filepath}" "${rclone}"
exit 0
elif [ "$path" = "$downloadpath" ] #文件夹
then
mv -f "${filepath}" "${rclone}"/
rm -rf "${filepath}"
exit 0
fi
done
|
###修改Aria2配置文件
首先授权chmod +x gdupload.sh然后再到Aria2配置文件中加上一行on-download-complete=/root/gdupload.sh即可,后面为脚本的路径。
##三、Nextcloud添加外置存储
由于我们已经把Google Drive挂载到本地了,所以我们直接添加外置存储即可
首先在Nextcloud中安装外部存储插件
选择应用-External storage support-启用即可
接着设置-外部存储按图所示添加即可

参考
使用Aira2下载文件后自动上传到Google Drive网盘