介紹
google drive 需要大量的複製備份到另一個雲端硬碟,例如有 A:Team Drive(共享雲端硬碟)複製到 B:Team Drive(共享雲端硬碟),使用 Autorclone 及 gclone 工具,以 Ubuntu 18.04 做為測試,如果是中國大陸使用者需要掛 VPN 或是使用 VPS 架設,此教學即使不董程式也可以學會 Auto rclone + gclone 安裝及設定。。
-
名詞
- Team Drive = 共享雲端硬碟 = 團隊盤
- Autorclone(在新分頁開啟):利用 google-api 建立多個帳號(service accounts) 一個 projec 建立 100 個帳號(service accounts),Autorclone 也可以 copy 資料
- gclone(在新分頁開啟):copy 資料使用及 rclone 所有功能
- rclone(在新分頁開啟):可掛載雲端硬碟,上傳,下載,更多功能..,請到官方看看
- service accounts,簡稱 sa(在新分頁開啟):用來突破單日帳號限制 750GB 流量
-
每日上傳檔案數量上限
- 個別使用者每天只能在「我的雲端硬碟」和所有共用雲端硬碟上傳 750 GB 的檔案。當使用者達到 750 GB 的上限或上傳大於 750 GB 的單一檔案,當天就無法再上傳其他檔案,不過上傳中的檔案仍可以完成上傳。可以上傳或同步處理的個別檔案大小上限則為 5 TB。
-
取得無限空間帳號 如果是教育或企業帳號可以選擇共享資料夾或是共享硬碟,如果是一般帳號只有 15GB 容量必須使用共享硬碟(團隊盤) 台灣大學專校都已經使用 G Suite 教育版,想要使用 google 教育帳號可以去自己學校網站看看,只要學校信箱是 google gmail 就可以使用 google 任何服務,共享雲端硬碟要看 G Suite 管理員有沒有開放權限使用,也可以使用教育帳號個人雲端,因為教育帳號已經是無限空間了,所以教育帳號使用共享雲端硬碟就不是很重要了。
-
其他取得方法可以到蝦皮、露天拍賣網站上看看 搜尋 google 教育(請不要買純新增共享雲端硬碟的這是很浪費錢的(找認識的朋友幫妳新增一個共享雲端硬碟或是往下看取得免費共享雲端硬碟),請購買 google 教育帳號,企業帳號也不要買萬一賣家不在付費 G Suite 也等於無限空間失效),以上個人的分析
取得免費的 Team Drive 共享雲端硬碟(團隊盤)
不要放重要的資料,建議申請 Team Drive 使用英文名稱
- Google TeamDrive:td.fastio.me(在新分頁開啟)
- YesYesxx.Me:gd.zxd.workers.dev(在新分頁開啟)
- 404 NOT FOUND:leon.educationhost.cloud(在新分頁開啟)
- 台灣中正大學:gd.404edu.workers.dev(在新分頁開啟)
- 英國老牌名校謝菲爾德大學:gdrive.zppcw.cn(在新分頁開啟)
- 洛杉磯加利福尼亞大學:ucla.ur.workers.dev(在新分頁開啟)
- 日本國際大學:iuj.ur.workers.dev
- 美國西南學院:teamdrive.xcpx.workers.dev(在新分頁開啟)
Ubuntu
前置安裝及設定
- Windows 10 也可以使用子系統 Ubuntu(微軟教學(在新分頁開啟))
- 如果你有 VPS Ubuntu 也可以使用,google cloud(在新分頁開啟)有 300 美金免費使用
更新及取得 root
更新及取得 root
apt update -y && apt upgrade -yapt install wget curl screen git sudo python3-distutils -ysudo -i安裝 python 3 及 pip 3
apt install python3 python3-pip -y#如果找不到pip請按以下命令操作curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"python3 get-pip.py安裝 AutoRlone 及設定
安裝 AutoRclone、pip 相關 python 套件 指令
cd ~git clone https://github.com/xyou365/AutoRclone && cd AutoRclone && sudo pip3 install -r requirements.txt安裝 Rclone
curl https://rclone.org/install.sh | sudo bash啟用 dirve api

上傳 credentials.json 檔案
credentials.json非常重要,如果沒有正確放到 AutoRclone 內是無法使用 api 的
複製credentials.json到 ubuntu
VPS 上傳檔案方法
scp 'PATH'/credentials.json 'SSH_USER_NAME'@'REMOTE_IP':'REMOTE_PATH'
'PATH' 本地 credentials.json 文件存放的路徑'SSH_USER_NAME' SSH 用戶名'REMOTE_IP' VPS的IP'REMOTE_PATH' VPS 中 AutoRclone 目錄 以上輸入時不要''引號- 使用 windows 10 子系統 ubuntu 18.04 ,windows 10 連接到 ubuntu 系統資料夾
開啟任何的資料夾,輸入
\\wsl$
路徑\\wsl$\Ubuntu-18.04\root\AutoRclone
放入credentials.json

檢查文件
ls ~/AutoRclone | grep 'credentials.json'自動建立 service 帳號
建立 100 個 service 帳號,每個 project 能建立 100 個 service 帳號 以指令是建立 6 個 project 有 600 個 service 帳號,計算一下 600 * 750GB = 450,000 GB,建議不要建立太多個 project
建立
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 資料夾下面
圖有 windows 10 的命令視窗,沒有特別截圖 ubuntu,方法都是一模一樣的
複製產生的網址


一路按下允許

複製授權碼到 CMD 視窗上,按下 ENTER

複製網址,啟用 Service Usage API,在回到 CMD 視窗按下 ENTER,會自動開啟建立 service 帳號



建立完成後,到accounts資料夾看到非常多的 json 檔,每個 json 檔都是一個 service 帳號

檢查 sa 文件
ls ~/AutoRclone/accounts加入 service 帳號到 team drive
-
成員限制說明:https://support.google.com/a/answer/7338880?hl=zh-Hant(在新分頁開啟)
-
有兩種方法,任選一種
- 第一種使用 python 腳本自動將所有的 service 帳號加入到 team drive,最多能加 600 個帳號,這是最快的方法,
- 第二種 使用 groups 論壇,建立群組並手動加入 service 帳號,一天最多加入 100 個,這種方法會比較慢,但是可以加入非常多個,之後只需要將 groups 論壇的管理員 email 加入到 team dirve 就可以了
- 注意:如果是請朋友幫你加入共享雲端硬碟,必須是管理員權限
-
使用 python 腳本自動將所有的 service 帳號加入到 team drive 指令, SharedTeamDriveSrcID 改成 team drive 的 ID
python3 add_to_team_drive.py -d SharedTeamDriveSrcID取得 team drive 的 ID,例如:0AL9kUqtQlodwUk9PVA

注意:一個 team drive 最多只能加入 600 個使用者
如果有 600 個 service 帳號卻沒有加入滿到 600,只需要多執行幾次就可以,直到加入到 600 個
到這裡就快完成啦
- 使用 groups 論壇,建立群組並手動加入 service 帳號
批量提取 SA email 文件: 提取 accounts 目錄內 sa json 中的 email
cat ~/AutoRclone/accounts/*.json | grep "client_email" | awk '{print $2}'| tr -d ',"' | sed 'N;N;N;N;N;N;N;N;N;/^$/d;G' > ~/email執行完上步驟後可以把 ’~/email’ 文件下載到本地自己保存
文件會放在 root
cd ~lsAutoRclone email查看 email 內容
cat email建立 群組論壇
- groups.google.com(在新分頁開啟)
注意:一天只能新增 100 個成員

取得群組 email (非常重要)

將群組 EMAIL 加入到 Team drive

GSuite Admin 加入成員方法 step-3-add-service-accounts-to-google-groups-optional-but-recommended-for-hassle-free-long-term-use(在新分頁開啟)
安裝 gclone 及 Rclone
- 安裝 Rclone 指令
cd ~curl https://rclone.org/install.sh | sudo bash- 安裝 gclone 指令
cd ~bash <(wget -qO- https://git.io/gclone.sh)gclone 建立設定檔
輸入命令獲取一個 sa json 文件名,隨機取得一個 sa json 檔名,設定時需要使用到一個 json 檔名
ls ~/AutoRclone/accounts | awk 'NR==1'輸入 gclone config
root@:~# gclone config2020/08/08 22:58:12 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaultsNo remotes found - make a new onen) New remote < 建立一個新的remotes) Set configuration passwordq) Quit confign/s/q> n < 輸入nname> gd_teamType 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" 3 / Amazon Drive \ "amazon cloud drive" 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc) \ "s3" 5 / Backblaze B2 \ "b2" 6 / Box \ "box" 7 / Cache a remote \ "cache" 8 / Citrix Sharefile \ "sharefile" 9 / Dropbox \ "dropbox"10 / Encrypt/Decrypt a remote \ "crypt"11 / FTP Connection \ "ftp"12 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage"13 / Google Drive < 因為要使用dirve 輸入13 \ "drive"14 / Google Photos \ "google photos"15 / Hubic \ "hubic"16 / In memory object storage system. \ "memory"17 / JottaCloud \ "jottacloud"18 / Koofr \ "koofr"19 / Local Disk \ "local"20 / Mail.ru Cloud \ "mailru"21 / Mega \ "mega"22 / Microsoft Azure Blob Storage \ "azureblob"23 / Microsoft OneDrive \ "onedrive"24 / OpenDrive \ "opendrive"25 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift"26 / Pcloud \ "pcloud"27 / Put.io \ "putio"28 / QingCloud Object Storage \ "qingstor"29 / SSH/SFTP Connection \ "sftp"30 / Sugarsync \ "sugarsync"31 / Transparently chunk/split large files \ "chunker"32 / Union merges the contents of several remotes \ "union"33 / Webdav \ "webdav"34 / Yandex Disk \ "yandex"35 / http Connection \ "http"36 / premiumize.me \ "premiumizeme"Storage> 13** See help for drive backend at: https://rclone.org/drive/ **
Google Application Client IdSetting 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> 留空白Google Application Client SecretSetting your own is recommended.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 < 輸入 1ID of the root folderLeave blank normally.
Fill in to access "Computers" folders (see docs), or for rclone to usea non root folder as its starting point.
Note that if this is blank, the first time rclone runs it will fill itin with the ID of the root folder.
Enter a string value. Press Enter for the default ("").root_folder_id> 留空白,默認一個資料夾為根目錄,沒有特別需求是不需要的Service Account Credentials JSON file pathLeave blank normally.Needed only if you want use SA instead of interactive login.Enter a string value. Press Enter for the default (""). < json不要與我一樣,從你的accounts隨便取得一個json檔名service_account_file> /root/AutoRclone/accounts/00af8bc13083978e5ad222c77380c3b6877fdeda.jsonService Account Credentials JSON file path .
Enter a string value. Press Enter for the default (""). < 重要必須輸入,讀取sa的路徑service_account_file_path> /root/AutoRclone/accounts/Edit advanced config? (y/n) 高級設定y) Yesn) No (default)y/n> n <輸入 nRemote configConfigure this as a team drive? 設定一個team drive,使用team drive需要輸入yy) Yesn) No (default)y/n> y < 輸入yFetching team drive list...Choose a number from below, or type in your own value 1 / share_gogogo < 每個人team drive都不一樣,選擇要使用team drive代號 \ "0AL9kUqtQlodwUk9PVA"Enter a Team Drive ID> 1--------------------[gd_team]type = driveclient_id =client_secret =scope = driveservice_account_file = /root/AutoRclone/accounts/00af8bc13083978e5ad222c77380c3b6877fdeda.jsonservice_account_file_path = /root/AutoRclone/accounts/team_drive = 0AL9kUqtQlodwUk9PVA--------------------y) Yes this is OK (default)e) Edit this remoted) Delete this remotey/e/d> yCurrent remotes:
Name Type==== ====gd_team drive
e) Edit existing remoten) New remoted) Delete remoter) Rename remotec) Copy remotes) Set configuration passwordq) Quit confige/n/d/r/c/s/q> q注意:指令需指定 Name,所以需要記得你的 Name 是叫什麼,例如我的是 gd_team,也可以使用 gclone config 或是 rclone config 兩種都吃同一個設定檔
指令使用方式
gclone 指令
gclone copy gd_team:{源} gd_team:my team name/資料夾1/資料夾2/ --drive-server-side-across-configs -v實際使用方法:
我的共享盤名稱是:share_gogogo
要 copy 的檔案:https://drive.google.com/uc?id=1l_dr7tqoNZja94b_AZ3LLmfLr8xk4g8x(在新分頁開啟)
取得網址的 ID,1l_dr7tqoNZja94b_AZ3LLmfLr8xk4g8x
因為設定時候已經設定好 team drive,所以不用再次輸入 team drive 名稱
gclone copy gd_team:{1l_dr7tqoNZja94b_AZ3LLmfLr8xk4g8x} gd_team:雷電模擬器 --drive-server-side-across-configs -v
資料夾結構

也可以指定其他 team drive,注意必須要加入權限帳號,有允許權限才能複製到指定的雲端硬碟
gclone copy gc:{folde_id1} gc:{folde_id2} --drive-server-side-across-configsAutorclone 指令
使用 Autorclone copy 資料
需求:rclone
- rclone 安裝指令
To install rclone on Linux/macOS/BSD systems, run:
輸入 rclone -h ,有顯示一推指令說明 代表安裝正常
Terminal window curl https://rclone.org/install.sh | sudo bash
SourceID = 源檔案,需 copy 的資料 ID DestinationID = 自己的 team drive id DestinationPathName = 路徑(資料夾) 會自動建立資料夾,不需要手動新增
python rclone_sa_magic.py -s SourceID -d DestinationID -dp DestinationPathName -b 1 -e 600取得自己 team drive id

檢查大小 如果沒有源路徑及目標路徑 不需輸入,路徑也就是資料夾意思 rclone —config rclone.conf size —disable ListR src001<源路徑>源路徑> rclone —config rclone.conf size —disable ListR dst001<目標路徑>目標路徑>
指令幫助說明
python3 rclone_sa_magic.py -hAutoRclone 作者的教學 https://gsuitems.com/index.php/archives/13/(在新分頁開啟)
建立自己的 client_id
-
使用自己的 client_id,可以使用任何帳號的 api,不影響使用的雲端硬碟帳號 https://github.com/rclone/rclone/blob/8d55367a6a2f47a1be7e360a872bd7e56f4353df/docs/content/drive.md#making-your-own-client_id(在新分頁開啟)
-
開啟此頁面 https://console.developers.google.com/apis/credentials(在新分頁開啟)

修改 client_id 及 client_secret
c:\AutoRclone-master>gclone configCurrent remotes:
Name Type==== ====gd_team drive
e) Edit existing remoten) New remoted) Delete remoter) Rename remotec) Copy remotes) Set configuration passwordq) Quit confige/n/d/r/c/s/q> eChoose a number from below, or type in an existing value 1 > gd_teamremote> 1--------------------[gd_team]type = drivescope = driveservice_account_file = /AutoRclone-master/accounts/00af8bc13083978e5ad222c77380c3b6877fdeda.jsonservice_account_file_path = /AutoRclone-master/accounts/team_drive = 0AL9kUqtQlodwUk9PVA--------------------Edit remote** See help for drive backend at: https://rclone.org/drive/ **
Value "client_id" = ""Edit? (y/n)>y) Yesn) No (default)y/n> yGoogle Application Client IdSetting 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> 75484848268-tr0lm3aoi6a6uuedv0bn2fnrsjqqvqep.apps.googleusercontent.comValue "client_secret" = ""Edit? (y/n)>y) Yesn) No (default)y/n> yGoogle Application Client SecretSetting your own is recommended.Enter a string value. Press Enter for the default ("").client_secret> dJty5bR1TXYVzRyuS9JmQ8u0Value "scope" = "drive"Edit? (y/n)>y) Yesn) No (default)y/n> nValue "root_folder_id" = ""Edit? (y/n)>y) Yesn) No (default)y/n> nValue "service_account_file" = "/AutoRclone-master/accounts/00af8bc13083978e5ad222c77380c3b6877fdeda.json"Edit? (y/n)>y) Yesn) No (default)y/n> nValue "service_account_file_path" = "/AutoRclone-master/accounts/"Edit? (y/n)>y) Yesn) No (default)y/n> nEdit advanced config? (y/n)y) Yesn) No (default)y/n> n--------------------[gd_team]type = drivescope = driveservice_account_file = /AutoRclone-master/accounts/00af8bc13083978e5ad222c77380c3b6877fdeda.jsonservice_account_file_path = /AutoRclone-master/accounts/team_drive = 0AL9kUqtQlodwUk9PVAclient_id = 75484848268-tr0lm3aoi6a6uuedv0bn2fnrsjqqvqep.apps.googleusercontent.comclient_secret = dJty5bR1TXYVzRyuS9JmQ8u0--------------------y) Yes this is OK (default)e) Edit this remoted) Delete this remotey/e/d> yRemote configChange current team drive ID "0AL9kUqtQlodwUk9PVA"?y) Yesn) No (default)y/n> nCurrent remotes:
Name Type==== ====gd_team drive
e) Edit existing remoten) New remoted) Delete remoter) Rename remotec) Copy remotes) Set configuration passwordq) Quit confige/n/d/r/c/s/q>問題
使用 gclone 可以傳送幾個檔案之後會有錯誤訊息
panic: runtime error: invalid memory address or nil pointer dereference
為了快速解決問題,不使用 gclone 指令,建議直接使用 Autorclone 指令處理
問題除錯
編輯設定指令:gclone config root_folder_id 有錯誤的話,無法複製到你指定的共享資料夾及團隊盤 確定 root_folder_id 是否為""(空) 或是 輸入正確資料夾 ID
參考文章
若此篇文章你還是看不懂,請看下列的文章及影片
- http://fxxkr.com/2020/03/27/autorclone-gclone-googledrive/(在新分頁開啟)
- https://github.com/donwa/gclone/blob/master/README_zh.md(在新分頁開啟)
- https://www.youtube.com/watch?v=EJMZCnGIEVY(在新分頁開啟)
- https://gsuitems.com/index.php/archives/13/(在新分頁開啟)
- https://zhuanlan.zhihu.com/p/124305044(在新分頁開啟)
- https://github.com/iwestlin/gd-utils#%E6%90%AD%E5%BB%BA%E8%BF%87%E7%A8%8B(在新分頁開啟)
- https://www.stevenz.tech/gd-750g/#gd-utils(在新分頁開啟)
- https://shikey.com/2020/05/22/win10-gclone-autoclone-750g.html(在新分頁開啟)
- http://blog.jialezi.net/?post=153(在新分頁開啟)
