博主经常看到有人在论坛或者QQ/Telegram群组发问
必须是Rclone/AutoRclone啊!一直不想写关于AutoRclone的(中文)教程,因为其一直处于测试阶段,如果后面代码有大的更新那么前面的教程对于后面的人来说就是一个误导。但是现在应该不会有大的更新了,而且这么长时间的测试发现如果没有一个详细的教程的话,会让很多不会程序的小白错过这么好的工具 :)
AutoRclone是一个用Python写的小程序的集合,其
- 学习了folderclone利用service accounts来替代普通Google账号进行拷贝/上传;
- 通过rclone rc来做到对Rclone任务的监、控;
- 还可以用Google Groups的形式对成百上千的service accounts进行管理。
从而方便快速地
- 从本地到 Team Drive,
- 从公共分享目录到 Team Drive,
- 再或者从 Team Drive 到 Team Drive。
其食用方法极其简单!
步骤 1 下载代码
首先不管你是哪个操作系统,需要安装Python。对于Linux和Windows分别用以下方式安装相关脚本
Linux: 安装screen,git和最新的Rclone。如果是Debian/Ubuntu,直接输入以下命令
sudo apt-get install screen git && curl https://rclone.org/install.sh | sudo bash
然后从Github下载代码并安装相关Python依赖包
sudo git clone https://github.com/xyou365/AutoRclone && cd AutoRclone && sudo pip3 install -r requirements.txt
Windows: 安装最新的Rclone,直接从Github下载AutoRclone后在Windows的cmd或PowerShell中切换到AutoRclone的目录,输入以下命令安装相关Python依赖包
pip3 install -r requirements.txt
步骤 2 生成service accounts
首先开启Drive API并将credentials.json保存到你的AutoRclone目录下面
如果你之前没创建过项目, 直接运行
python3 gen_sa_accounts.py --quick-setup 5
- 创建6个项目(项目0到项目5)
- 开启相关的服务
- 创建600个service accounts(6个项目,每个项目100个)
- 将600个service accounts的授权文件下载到accounts文件夹下面
如果你已经有N个项目,现需要创建新的项目并在新的项目中创建service accounts,直接运行
python3 gen_sa_accounts.py --quick-setup 2 --new-only
- 额外创建2个项目(项目N+1到项目N+2)
- 开启相关的服务
- 创建200个service accounts(2个项目,每个项目100个)
- 将200个service accounts的授权文件下载到accounts文件夹下面
如果你想用已有的项目来创建service accounts(不创建新的项目),直接运行
python3 gen_sa_accounts.py --quick-setup -1
注意这会覆盖掉已有的service accounts
顺利完成后,AutoRclone文件下面的accounts文件夹下会有很多的json文件。
步骤 3 可选:将service accounts加入Google Groups
为了方便管理service accounts,也是为了让我们的Team Drive可以容纳更多的service accounts,我们这里用到了Google Groups。
Official limits to the members of Team Drive (Limit for individuals and groups directly added as members is 600).
对于G Suite管理员
- 按照官方步骤开启Directory API,将生成的json文件保存到credentials文件下。
- 在控制面版里面创建一个群组,创建好你会获得一个类似域名邮箱的地址[email protected]
- 利用API将service accounts加入Google Groups
python3 add_to_google_group.py -g [email protected]
如果想看参数的具体含义,直接运行python3 add_to_google_group.py -h
对于普通Google账号
直接创建一个Google Group然后手动地将service accounts对应的邮箱地址(可以在json认证文件中找到)挨个加进去。但每次只能加10个,每24小时只能加100个。
步骤 4 将service accounts或者Google Groups加入到Team Drive
- 如果你没有Team Drive,那可以找朋友帮你开一个或者去买一个,实在不嫌弃也可以留言找博主开一个
- 如果你已经在完成了步骤2中的用Google Groups来管理service accounts,那么直接将Google Groups地址[email protected]或者[email protected]加入你的源Team Drive(tdsrc)和目标Team Drive(tddst)
- 如果你在步骤2中没有生成并保存credentials.json那么再做一遍
将service accounts加入到源Team Drive
python3 add_to_team_drive.py -d SharedTeamDriveSrcID
将service accounts加入到目标Team Drive
python3 add_to_team_drive.py -d SharedTeamDriveDstID
步骤 5 开始拷贝/上传
准备工作都做好了,以后你只需要将项目文件夹拷贝到任何地方,进行此拷贝/上传步骤就可以啦
拷贝
python3 rclone_sa_magic.py -s SourceID -d DestinationID -dp DestinationPathName -b 1 -e 600
- 如果想看参数的具体含义,直接运行
python3 rclone_sa_magic.py -h
- 特别地,如果想多开,请用
-p
参数给不同的复制任务指定不同的端口 - 如果发现拷贝内容明显少于源Team Drive里面的内容,那么你可能碰到Bug了,请给上运行参数再加上
--disable_list_r
- 如果你一开始就碰到了Failed to rc: connection failed: Post http://localhost:5572/core/stats: dial tcp :5572: connectex: No connection could be made because the target machine actively refused it.那么可能是权限或者路径导致Rclone任务都没跑起来,请观察日志文件
log_rclone.txt
,并结合如下简单命令检查出原因rclone --config rclone.conf size --disable ListR src001:
,rclone --config rclone.conf size --disable ListR dst001:
上传
python3 rclone_sa_magic.py -sp YourLocalPath -d DestinationID -dp DestinationPathName -b 1 -e 600
不出意外应该就可以跑起来了。每个service account的总的时间消耗是校验时间+拷贝时间,如果你的拷贝任务比较大的话建议将其(按文件夹)稍微拆分,挨个或者并行完成,这样能极大减小每次切换service accounts后不必要的校验时间。另外关于拷贝速度,API调用限制了每秒不超过10次调用,每次拷贝固定数量的文件数目,所以如果你的任务中的文件比较小的话,拷贝速度可能是每秒几百MB,文件都比较大的话,拷贝速度可能是几十GB/s。
一些 Q & A
rclone --config rclone.conf size --disable ListR src001:源路径
rclone --config rclone.conf size --disable ListR dst001:目标路径
如果发现目标盘比源盘体积还要大,那么对目标盘进行去重;如果发现目标盘比源盘少文件了,那么再拷贝一次;如果还是少,那么就是源盘里面的有重复文件了,直接对其进行去重复。去重命令:
rclone --config rclone.conf dedupe src001:源路径
rclone --config rclone.conf dedupe dst001:目标路径
[...]https://gsuitems.com/index.php/archives/13/[...]
[...]https://gsuitems.com/index.php/archives/13/[...]
[...]}); 粉色的花瓣,美丽地缠绕在身上。依在风里。 檸檬茶 の 小站 登录首頁日常|分站友だち隱私權政策Windows下安裝gd-utils發布於 12 秒前 1 次閱讀安裝環境python:https://www.python.org/downloads/nodejs:https://nodejs.org/en/download/ Visual Stud[...]
[...]./validate-sa.js 目录ID # 此目录ID是任意一个你的sa拥有阅读权限的目录ID,例如在 rclone 绑定的谷歌团队盘的ID程序会读取sa目录下所有json文件,依次检查它们是否拥有对 你的目录ID 的阅读权限,如果最后发现了无效的SA,程序会提供选项允许用户将无效的 sa json 移动到特定目录。重启 PM2 进程所有改动后,必须重启PM2进程。pm2 reload ser[...]
[...]Rclone:https://rclone.orgGitHub:https://github.com/rclone/rcloneRclone中文站:https://www.rclone.cn缺点:每天每个账户限制750G流量Copy, URL to Google Drive™:https://softgateon.herokuapp.com/urltodrive/chrome扩展插件(谷歌chro[...]
[...]参考资料https://github.com/iwestlin/gd-utilshttps://www.ikarosone.top/archives/195.htmlhttps://gsuitems.com/index.php/archives/13https://p3terx.com/archives/goindex-google-drive-directory-index.html#toc_2[...]
[...]为了看起来不水发些别人的教程保命。 autorclone https://gsuitems.com/index.php/archives/13/ 可以用来创建服务号,推荐将帐号添加到群组。 gclone&bot gclone教程 这个好用,我用它来盘与盘对拷。 bot 这个是gclone的bot,省了很多麻烦。 fclone&bot fclone教程 这个非常[...]
[...]SourceID为在Wait For Sync中待转存文件夹的id(非Wait For Sync本身,1开头)DestinationID为Team Drive的id(0开头)dp为转存后的文件夹名字,可以之后改掉,随意-b 1 :从1号SA开始 -e 100 :到100号SA结束转存后文件会在Shared drive中出现,无限GD的直接拖到My Drive里面就行,非无限的直接在Shared D[...]
[...]SourceID为在Wait For Sync中待转存文件夹的id(非Wait For Sync本身,1开头)DestinationID为Team Drive的id(0开头)dp为转存后的文件夹名字,可以之后改掉,随意-b 1 :从1号SA开始 -e 100 :到100号SA结束转存后文件会在Shared drive中出现,无限GD的直接拖到My Drive里面就行,非无限的直接在Shared D[...]
[...]参考1 参考2[...]
[...]参考1 参考2[...]
[...]无限GD可以从Shared Drive拖到My Drive后与Mover.io联动,从Google Drive转存到Onedrive大佬的免费无限Shared Drive地址参考1 参考2需要无限GD的可以搜黄匹顾国际大学购买,25r一个 (黄屁股打钱[...]
[...]无限GD可以从Shared Drive拖到My Drive后与Mover.io联动,从Google Drive转存到Onedrive大佬的免费无限Shared Drive地址参考1 参考2需要无限GD的可以搜黄匹顾国际大学购买,25r一个 (黄屁股打钱[...]
[...]共产国际白求恩 : https://gsuitems.com/index.php/archives/13/[...]
第一个创建project就出错了,403 when requesting https://serviceusage.googleapis.com/v1/projects/gothic-concept-266812/services/drive.googleapis.com:enable?alt=json returned
源TD没有添加sa的权限,怎么破解?
请问这是什么原因
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connection.py", line 156, in _new_conn
conn = connection.create_connection(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn
conn.connect()
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connection.py", line 300, in connect
conn = self._new_conn()
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connection.py", line 168, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\util\retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "gen_sa_accounts.py", line 311, in
resp = serviceaccountfactory(
File "gen_sa_accounts.py", line 173, in serviceaccountfactory
creds = flow.run_console()
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\google_auth_oauthlib\flow.py", line 404, in run_console
self.fetch_token(code=code)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\google_auth_oauthlib\flow.py", line 280, in fetch_token
return self.oauth2session.fetch_token(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests_oauthlib\oauth2_session.py", line 336, in fetch_token
r = self.request(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests_oauthlib\oauth2_session.py", line 515, in request
return super(OAuth2Session, self).request(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝 试失败。'))
大佬 reading sourac/destination
经常卡这里 怎么办呢?
为啥脚本添加进团队盘的用户数和生成的json数差这么多呢,200个json,运行完api脚本只有75个用户
对,我也发现这个bug。我500个json,100个用户,幸亏key名和json名对应。我一开始尝试改rclone的conf,后来发现每运行一次重新生成conf,后来把对应key的json挑出来剩下的删了,才好的。多余的conf容易导致报错三次之后就停止了,非常操蛋
而且还是不对应名字的...
我生成600的导入才400多,挑起来不是蛋疼死...⌇●﹏●⌇
我的json和key的名字是对应的啊?和key的名字,不是和sa的名字
挑的话你可以见个excel文档把所有的key名全部列出来,然后通过合并单元格的方式弄出一个形如“copy 目录/key.json 目的地”的几百条命令,然后弄成bat批处理就可以挑出来了
但是盘里的成员都是邮箱形式,不打开json怎么对应里面的邮箱呢,几百个漏的我挑的太痛苦了...
盘里的成员的json是对应的key名,你可以在api后台看到sa菜单里一个表格,所有的sa和对应的key
那大佬是怎么知道哪些json导入了团队盘,我找不到更好的方法,只能一个个比对,上百个漏掉我是吃不消了...
这里没法粘贴图片,要不你去博主的电报群里找我?Google Drive 资源整理
小白没看懂...这个是linux用的还是win用的还是2个结合...
[root@localhost AutoRclone]# python2 gen_sa_accounts.py --quick-setup 5
Traceback (most recent call last):
File "gen_sa_accounts.py", line 5, in
from google_auth_oauthlib.flow import InstalledAppFlow
ImportError: No module named google_auth_oauthlib.flow
第二步运行创建项目的脚本时提示Traceback (most recent call last):
File "gen_sa_accounts.py", line 5, in
from google_auth_oauthlib.flow import InstalledAppFlow
ModuleNotFoundError: No module named 'google_auth_oauthlib'
这个怎么解啊大佬
你没有把那个requirements装好
你可以手动装一下pip install google_auth_oauthlib
我也是小白
请问本地电脑可以用吗
2020/02/12 00:25:32 Failed to rc: connection failed: Post http://localhost:5572/core/stats: dial tcp 127.0.0.1:5572: connect: connection refused
2020/02/12 00:25:32 Failed to rc: connection failed: Post http://localhost:5572/core/stats: dial tcp 127.0.0.1:5572: connect: connection refused
rclone日志
2020/02/12 00:28:49 ERROR : : error listing: directory not found
2020/02/12 00:28:49 Failed to size with 2 errors: last error was: directory not found
出现这种情况怎么办?
完整错误
2020/02/12 00:51:49 ERROR : : error listing: failed to get Team/Shared Drive info: googleapi: Error 404: Shared drive not found: xxx, notFound
2020/02/12 00:51:49 Failed to size with 2 errors: last error was: failed to get Team/Shared Drive info: googleapi: Error 404: Shared drive not found: xxx, notFound
未发现你的团队盘
你好。麻烦你看下我这是什么原因
2020/02/22 09:47:31 Failed to rc: connection failed: Post http://localhost:5572/
core/stats: dial tcp [::1]:5572: connectex: No connection could be made because
the target machine actively refused it.
ERROR : : error listing: couldn't list directory: Get https:
//www.googleapis.com/drive/v3/files?alt=json&corpora=drive&driveId=0ACflmF7V9qaJ
Uk9PVA&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CmodifiedTime%2C
createdTime%2CmimeType%2Cparents%2CwebViewLink%29%2CnextPageToken%2CincompleteSe
arch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3D
false+and+%28%270ACflmF7V9qaJUk9PVA%27+in+parents%29&supportsAllDrives=true: oau
th2: cannot fetch token: Post https://oauth2.googleapis.com/token: dial tcp 172.
217.160.74:443: connectex: A connection attempt failed because the connected par
ty did not properly respond after a period of time, or established connection fa
iled because connected host has failed to respond.
对了,博主。我用的是edu G suit ,在创建的组里添加邮箱会报错,说"Some users are outside the organization or are not valid accounts. Your organization or group is configured to allow only organization members to join. Please contact your group owner or domain administrator for help."
一些用户在组织外或者不是可用的账号,blablabla。
请问这种情况怎么解决?
cd accounts && grep -o '[[:alnum:]+\.\_\-]*@[[:alnum:]+\.\_\-]*' *.json > ../account_email.txt
you will get all e-mail address
写的什么东西啊,安装没写就直接跳过了。你这教程写给谁看的?
对不住了
第二步里运行了没有反应啊,也没有生成很多accounts,在目录里运行命令的,怎么回事呢
要配置rclone,博主都没写
谁说要配置rclone,rclone自动配置的
写的挺好的,对比github文档补充了一些解释,比如我原来用python3开头就没反应。Github没写,看到博主的文章,换成python开头顺利完成了。谢谢博主~