返回列表 發帖

[教學] Google Drive 遷移教學

Source : https://www.ptt.cc/bbs/Free_box/M.1615280338.A.6AB.html

因為教育號的無限空間即將取消了,目前要轉移到有無限空間的地方就只有 Google 或 M
icrosoft 的付費方案。

如果是 Google Drive 遷移 Google Drive 的話,建議開免費 GCP 來轉移,速度快流量
免費。
如果是 Google Drive 遷移 Microsoft 的話,開 GCP 有 300 美金可以使用,但是傳輸
到 Microsoft 要算流量費,注意不要超過 300 美金。

第一篇 使用 rclone

事先準備
一。針對申請 GCP 的部份,要有Google帳號與信用卡,超過流量才會扣款。當然也可以
使用自己的電腦。
二。需略懂 Linux,會盡量寫的新手也能看的懂。
三。教學的 rclone 版本為 v1.54.1


第一步 申請 Google Cloud Platform (gcp)
https://cloud.google.com/gcp/getting-started/?hl=zh-tw
免費試用
運用 $300 美元的免費抵免額和 20 項以上的一律免費產品,開始在 Google Cloud 中建
構內容。

點 [免費開始使用] 來申請帳號

1.登入
繼續使用 Google Cloud Platform,沒有帳號的話請點 [建立帳戶]
這裡我們直接登入現有的 google 帳號密碼登入

2.免費試用 Google Cloud Platform
步驟 2 之 1

服務條款 需要都勾選才能按下 [繼續]

步驟 2 之 2

帳戶類型 -> 個人
稅務資訊 -> 未登記稅籍的個人
填好必要的資料後按下 [開始免費試用]

3.XXX,歡迎使用!

感謝您提出申請。我們會在免費試用期間提供價值 $300 美元的抵免額,讓您在未來 90
天內使用。請放心,除非您啟用了自動計費功能,否則即便抵免額用盡也不會產生費用。
按下 [我知道了]
申請的時候我收到銀行簡訊扣款40元,但應該只是 Google 驗證用不會請款。
計畫啟動方式
。如要完成免費試用期的申請程序,請務必提供信用卡資訊或其他付款方式來設定帳單帳
戶及驗證身分。請放心,設定帳單帳戶並不會啟動收費機制。除非您升級為付費帳戶並明
確啟用計費功能,否則我們不會收費。您可以在試用期間隨時升級為付費帳戶。如在 90
天試用期間升級帳戶,仍可繼續使用剩餘的抵免額。
計畫涵蓋範圍
。免費試用期的抵免額適用於所有 Google Cloud 資源,包括 Google 地圖平台用量,唯
下列作業除外:
。同時執行超過 8 個核心 (或虛擬 CPU)。
。將 GPU 新增至 VM 執行個體。
。要求提高配額。如要查看 Compute Engine 配額總覽,請參閱資源配額一文。
。依據 Windows Server 映像檔建立 VM 執行個體。
。您必須升級為付費帳戶,才能執行上述各項操作。

4.開啟免費伺服器

https://cloud.google.com/free?hl=zh-tw
每個月可使用 1 個 f1-micro 執行個體,可彈性擴充的高效能虛擬機器。
每個月可以在下列其中一個美國區域中使用 1 個非先占 f1-micro VM 執行個體:
奧勒岡州:us-west1
愛荷華州:us-central1
南卡羅來納州:us-east1
每月 30 GB HDD

左上角 導覽選單 -> Compute Engine -> VM 執行個體

第一次開啟的時候要先等他一下
正在啟用 Compute Engine,這項作業可能需要幾分鐘的時間才能完成。「Compute Engin
e」說明文件
可能不會自動更新,建議可以點 [執行個體範本] 再點回 [VM 執行個體]

當可以使用的時候 VM 執行個體 的 [建立] 就可以點選了

。新增 VM 執行個體 ->
名稱:自訂
區域:us-central1 , us-central1-a
。機器設定 -> 機器系列 -> 一般用途
系列:N1
機器類型:f1-micro
。開機磁碟 -> [變更] -> 公開映像檔 ->
作業系統:CentOS
版本:CentOS 7
開機磁碟類型:標準永久磁碟
大小(GB):30
。安全性 -> 受防護的 VM
啟用 vTPM,啟用完整性監控功能 我都是取消勾選
右上角可以看到 本月使用「f1-micro」執行個體的前 744 小時完全免費。
按下 [建立]


我們把外部IP記錄下來,這裡使用 115.234.0.1 當範例
連結 -> SSH 按一下 往下的箭頭 有 在瀏覽器視窗中開啟 等等的選項 ->

在瀏覽器視窗中開啟會 自動帶 key 進去

因為是比較簡單的教學,我們使用 [在瀏覽器視窗中開啟] 的功能。
但大多時間建議使用 [使用其他 SSH 用戶端]
https://cloud.google.com/compute ... advanced#thirdparty
tools
並在 VPC網路 -> 防火牆 -> 限定 SSH 連線的來源位置
VPC網路 -> 外部 IP 位置 -> 類型 -> 改成 靜態


第二步 使用免費的 GCP CentOS 7 安裝 Rclone
在第一步的時候我們已經在 GCP 的 SSH 裡選擇  在瀏覽器視窗中開啟
接下來的步驟都在那個 SSH 的視窗裡執行
我們先安裝必要的 unzip 與 screen
輸入
sudo yum install -y unzip screen
他會開始自己安裝看到下面的字樣
Installed:
  screen.x86_64 0:4.1.0-0.26.20120314git3c2946.el7                    unzip.x8
6_64 0:6.0-21.el7
Complete!
就是安裝完成了
輸入
date
可以看到時間為 UTC
Tue Mar  9 06:35:15 UTC 2021
我們改成台灣時間比較好懂
輸入
sudo ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
date
可以看到時間為台灣的時間了
Tue Mar  9 14:35:21 CST 2021
接下來安裝 rclone 輸入
curl https://rclone.org/install.sh | sudo bash
看到下面的字樣
rclone v1.54.1 has successfully installed.
Now run "rclone config" for setup. Check https://rclone.org/docs/ for more det
ails.
就是安裝完成了


第三步 設定 rclone config
幾個方式都會寫第一個先
1.gd 個人盤 -> gd 個人盤
輸入
rclone config

新增的選項是
n) New remote
所以我們輸入 n
n/s/q> n

我們自訂名稱輸入 gd01
name> gd01

會列出目前有 42 個服務可以使用,我們要輸入 15 / Google Drive
Storage> 15

預設值按輸入鍵就好
client_id>
client_secret>

再來是權限通常來源我都是選 2 唯讀,目的地才選 1 最大權限
scope> 1

預設值按輸入鍵就好
root_folder_id>
service_account_file>

進階選項
Edit advanced config? (y/n)
y) Yes
n) No (default)
預設值按輸入鍵就好
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 (default)
n) No
y/n> n
Please go to the following link: 後面的連結點一下,登入你資料來源的帳號然後在
「rclone」想要存取您的 Google 帳戶 按下 [允許]
將那一串帶登入的 key 複製下來, ctrl+v 到下面的 code>
Enter verification code>
接下來是問要不要設定 Team Drive?請輸入 n
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n> n
確認資訊是否正確?預設值按輸入鍵就好
[gd01]
type = drive
scope = drive
token = {"access_token":"xxxxxx"}
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d>
可以看到 gd01 已經建立完畢,我們依上面的步驟按 n 再建立 gd02
Current remotes:

Name                 Type
====                 ====
gd01                 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

如果 gd01 gd02 都建立完畢後,我們再按 q 離開 rclone config
Current remotes:

Name                 Type
====                 ====
gd01                 drive
gd02                 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

我們先輸入
screen -S gd01togd02
建立多重視窗,視窗關閉或是下次要進來時輸入
screen -x gd01togd02
要看有開啟那些多重視窗可以輸入
screen -ls

如果要一個一個資料夾單獨複製可以使用 copy ,如果是整個目錄都複製可以使用 sync
如果我要將 gd01 我的雲端硬碟 > Music 整個複製到 gd02 我的雲端硬碟裡指令可以這
樣輸入
rclone -vv sync gd01:Music gd02:Music

下列是傳輸畫面,碎檔多的話速度就會變慢,單一大檔案的話速度會比較快
2021/03/09 15:27:06 INFO  :
Transferred:        1.580G / 212.132 GBytes, 1%, 27.301 MBytes/s, ETA 2h11m37s
Transferred:           20 / 4364, 0%
Elapsed time:       1m1.3s
Transferring:
* Magic/CD3/CD3.bin: 80% /738.661M, 6.792M/s, 21s
* Magic/CD1/CD1.bin: 62% /727.434M, 5.787M/s, 46s
* Magic/CD4/CD4.bin: 72% /645.177M, 6.422M/s, 27s
* Magic/CD2/CD2.bin: 13% /734.545M, 3.964M/s, 2m41s

如果你想先搬重要的資料夾而且資料夾有空格與非英文字的話,要用 "" 包起來,例如
rclone -vv copy gd01:Music/"我愛聽的歌 第一集" gd02:Music/"我愛聽的歌 第一集"


2.gd 共用雲端硬碟td -> gd 共用雲端硬碟td
剛剛的視窗已經用於 gdtogd 我們有開 screen 所以直接把視窗關閉就可以
我們回到左上角導覽選單 -> Compute Engine -> VM 執行個體 -> 連結 -> 在瀏覽器視
窗中開啟
我們輸入
screen -ls
可以看到 gd01togd02 的多重視窗還存在,隨時可以輸入 screen -x gd01togd02 登入
There is a screen on:
        10366.gd01togd02        (Attached)
1 Socket in /var/run/screen/S-dcshare.

不過這一次我們要設定 td 所以輸入
screen -S gd02tdtogd01td
一樣輸入
rclone config
e/n/d/r/c/s/q> n
name> gd01td
Storage> 15
client_id>
client_secret>
scope> 1
root_folder_id>
service_account_file>
y/n>
y/n> n
登入 gd01 帳號
Enter verification code> ctrl+v 貼上 code
Team Drive 這裡選 y
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n> y
他會列出你目前所有的 Team Drive ,我們這次範例輸入 2
Fetching Shared Drive list...
Choose a number from below, or type in your own value
1 / ttest
   \ "0Axxxx"
2 / test
   \ "0Axxx"
Enter a Shared Drive ID> 2
y/e/d>
就能看到 gd01td 建立完成囉~
Current remotes:

Name                 Type
====                 ====
gd01                 drive
gd01td               drive
gd02                 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 建立 gd02td 前面步驟都相同
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n> y
Fetching Shared Drive list...
Choose a number from below, or type in your own value
1 / abc001
   \ "0Axxx"
Enter a Shared Drive ID> 1
y/e/d>
就能看到 gd02td 建立完成囉~
Current remotes:

Name                 Type
====                 ====
gd01                 drive
gd01td               drive
gd02                 drive
gd02td               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

我們這次只要複製其中一個資料夾的話可以這樣下,目錄名稱不需要帶 Team Drive 的名
稱,因為我們已經設定到 Team Drive 資料夾內
rclone -vv copy gd02td:Music/"我愛聽的歌 第二集" gd01td:Music/"我愛聽的歌 第二
集"

就開始複製囉~這次範例是4GB 一個檔案,可以看到速率就飆上去了~
Transferred:       19.215G / 69.114 GBytes, 28%, 82.048 MBytes/s, ETA 10m22s
Transferred:            4 / 18, 22%
Elapsed time:       4m0.7s
Transferring:
* part04.rar: 25% /3.905G, 20.265M/s, 2m26s
* part05.rar: 23% /3.905G, 20.369M/s, 2m30s
* part06.rar: 24% /3.905G, 21.818M/s, 2m18s
* part07.rar: 18% /3.905G, 17.719M/s, 3m3s

剩下要怎麼使用就自由發揮囉~



放了一天來看因為 SSH 允許所有人連入,只是要使用 key 才能登入。
輸入
sudo lastb
可以看到有人嘗試透過帳密登入但是都被擋下來了。
support  ssh:notty    141.98.80.85     Wed Mar 10 08:20 - 08:20  (00:00)
guest    ssh:notty    141.98.80.83     Wed Mar 10 08:20 - 08:20  (00:00)
ubnt     ssh:notty    141.98.80.82     Wed Mar 10 08:20 - 08:20  (00:00)
guest    ssh:notty    141.98.80.71     Wed Mar 10 08:20 - 08:20  (00:00)
test     ssh:notty    141.98.80.69     Wed Mar 10 08:20 - 08:20  (00:00)
admin    ssh:notty    141.98.80.82     Wed Mar 10 08:20 - 08:20  (00:00)
user     ssh:notty    141.98.80.71     Wed Mar 10 08:20 - 08:20  (00:00)
admin    ssh:notty    141.98.80.70     Wed Mar 10 08:20 - 08:20  (00:00)
admin    ssh:notty    141.98.80.69     Wed Mar 10 08:20 - 08:20  (00:00)
uploader ssh:notty    c-73-208-94-123. Wed Mar 10 06:31 - 06:31  (00:00)
pi       ssh:notty    93.51.127.23     Wed Mar 10 06:29 - 06:29  (00:00)
ubnt     ssh:notty    195.54.160.250   Wed Mar 10 03:25 - 03:25  (00:00)
admin    ssh:notty    185.220.102.4    Wed Mar 10 00:37 - 00:37  (00:00)
admin    ssh:notty    209.127.17.242   Wed Mar 10 00:37 - 00:37  (00:00)
admin    ssh:notty    23.129.64.210    Wed Mar 10 00:37 - 00:37  (00:00)
admin    ssh:notty    185.220.101.194  Wed Mar 10 00:37 - 00:37  (00:00)
odoo     ssh:notty    202.28.194.163   Wed Mar 10 00:01 - 00:01  (00:00)
ubnt     ssh:notty    31.210.22.2      Tue Mar  9 20:55 - 20:55  (00:00)
testuser ssh:notty    45.93.201.193    Tue Mar  9 18:55 - 18:55  (00:00)
zyfwp    ssh:notty    195.54.160.250   Tue Mar  9 15:29 - 15:29  (00:00)

輸入
last
可以看到成功登入的使用者都是我自己 與 screen
test     pts/2        35.235.241.16    Wed Mar 10 10:58   still logged in
test     pts/1        35.235.240.5     Wed Mar 10 07:02 - 07:57  (00:55)
test     pts/1        35.235.240.2     Wed Mar 10 01:21 - 02:08  (00:46)
test     pts/3        :pts/2:S.0       Tue Mar  9 15:44 - 17:29  (01:45)
test     pts/0        :pts/1:S.0       Tue Mar  9 15:23 - 15:46  (00:23)
test     pts/1        35.235.241.18    Tue Mar  9 14:13 - 15:46  (01:32)
test     pts/0        35.235.241.19    Tue Mar  9 14:05 - 14:27  (00:22)
reboot   system boot  3.10.0-1160.15.2 Tue Mar  9 14:01 - 10:58  (20:56)

用瀏覽器登入的 IP 落在 35.235.241.0/24 與 35.235.240.0/24
https://cloud.google.com/iap/docs/using-tcp-forwarding#console
這裡寫著 35.235.240.0/20 我們只開這個區段 SSH 連入就好

左上角 導覽選單 -> 網路 -> VPC 網路 -> 防火牆

點一下 [default-allow-ssh] -> 編輯 -> 我們把 0.0.0.0/0 刪除

增加 35.235.240.0/20 -> 儲存


第二篇 使用 rclone + --drive-server-side-across-configs=true

回到 VM 執行個體 -> 連結 -> SSH -> 在瀏覽器視窗開啟

PTT 網友 LeisCat 提供 --drive-server-side-across-configs 這個參數的使用範例
在 Server 端傳輸檔案,不會使用到 Client 流量

首先我先將檔案複製一份來測試
rclone -vv copy --drive-server-side-across-configs  gd01:test gd01:test2
可以看到是 server-side copy
2021/03/10 11:32:29 INFO  : xxxxx: Copied (server-side copy)
而且速度很快
Transferred:      206.508G / 1.901 TBytes, 11%, 1.739 GBytes/s, ETA 16m40s
Transferred:          157 / 7994, 2%
Elapsed time:       2m1.0s
不過複製到 1.2TB 時限流了
Transferred:        1.219T / 1.901 TBytes, 64%, 322.791 MBytes/s, ETA 36m56s
Transferred:         6007 / 7994, 75%
Elapsed time:     1h6m1.0s
2021/03/10 12:36:33 DEBUG : pacer: low level retry 10/10 (error googleapi: Err
or 403: User rate limit exceeded., userRateLimitExceeded)
2021/03/10 12:36:33 DEBUG : pacer: Rate limited, increasing sleep to 16.575937
443s

我們就先用這一份 1.2 TB 的資料來做測試吧。
首先 gd01 的資料在 [我的雲端硬碟] -> [test2] 裡,我們要轉移到 gd02 [共用雲端硬
碟] -> [test2] 裡。

gd02 -> 共用雲端硬碟 -> test2 -> 管理成員 -> 將你 gd01 的帳號輸入並設定為 [管
理員] -> [共用]
要與機構外的使用者共用嗎?
共用對象 xxx@xxx.xx 不在這個項目所屬的 Google Workspace 機構中。
選擇 [一律共用]

到 gd01 -> 共用雲端硬碟 -> test2 可以看到擁有者是 gd02 的組織

接下來我們建立 gd01tdtest2
rclone config
e/n/d/r/c/s/q> n
name> gd01tdtest2
Storage> 15
client_id>
client_secret>
scope> 1
root_folder_id>
service_account_file>
y/n>
y/n> n
按連結登入 gd01 帳號 -> 允許 -> 複製 code
Enter verification code> 貼上複製的 code
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n> y
Fetching Shared Drive list...
Choose a number from below, or type in your own value
1 / test
   \ "0Axxx"
2 / test2
   \ "0Axxx"
Enter a Shared Drive ID> 2
y/e/d>
e/n/d/r/c/s/q> q

接下來我們將 gd01 test2 移動到 gd01 Team Drive test2 裡的 test2 目錄,擁有者是
gd02 的網域不是 gd01 的。
rclone -vv move --drive-server-side-across-configs      gd01:test2 gd01tdtest2
:test2
可以看到是 server-side
2021/03/10 15:03:02 INFO  : xxxxx: Moved (server-side)
2021/03/10 15:03:03 INFO  :
Transferred:             0 / 1.139 TBytes, 0%, 0 Bytes/s, ETA -
Checks:                80 / 84, 95%
Renamed:               80
Transferred:            0 / 5940, 0%
Elapsed time:       1m0.8s

等他跑完就完成將 gd01 [我的雲端硬碟] 搬移到 gd02 擁有者的 [共用雲端硬碟] 裡了



第三篇 使用 rclone + --drive-server-side-across-configs + sa(Service Accounts)

我想使用 copy 的方式轉移,不想使用 move 的方式轉移,但是一個帳號有一天上傳 750
GB 的限制該如何突破?
Rclone 750G自動換號– AutoRclone使用教程
https://gsuitems.com/index.php/archives/13/
https://github.com/xyou365/AutoRclone


第一步 安裝必要軟體

我們依我們從第一篇開始建立的 GCP centos7 來教學
回到 ssh 視窗
安裝 git python36 輸入
screen -S testsa
sudo yum install -y git python36
看到 Complete! 資料就是安裝完成囉~

然後從 Github 下載代碼並安裝相關 Python 依賴包,輸入
sudo git clone https://github.com/xyou365/AutoRclone && cd AutoRclone && sudo
pip3 install -r requirements.txt

安裝完畢後到這個網站

https://developers.google.com/drive/api/v3/quickstart/python
按下 [Enable the Drive API] 此時需要登入 google 帳號請登入 GCP 的帳號,登入完
畢後再按一次 [Enable the Drive API]
Enter new project name:自訂我們輸入satest
協議請選 Yes
按下 [NEXT]

Confi your OAuth client
預設的 Desktop app 即可
按下 [CREATE]

You're all set!
You're ready to start developing!
按下 [DOWNLOAD CLIENT CONFIGURATION]
將下載的 credentials.json 存到硬碟裡

利用右上角的齒輪 -> 上傳檔案 -> 將剛剛下載的 credentials.json 上傳
檔案是傳在 user home 裡,所以輸入
cd ~/AutoRclone
sudo mv ../credentials.json ./
ll
可以看到我們需要的 credentials.json 已經建立完畢
total 100
drwxr-xr-x. 2 root    root       19 Mar 11 15:38 accounts
-rw-r--r--. 1 root    root     2821 Mar 11 15:38 add_to_google_group.py
-rw-r--r--. 1 root    root     3122 Mar 11 15:38 add_to_team_drive.py
-rw-r--r--. 1 root    root    37075 Mar 11 15:38 AutoRclone.jpg
drwxr-xr-x. 2 root    root       43 Mar 11 15:38 credentials
-rw-rw-r--. 1 dcshare dcshare   430 Mar 12 16:48 credentials.json
-rw-r--r--. 1 root    root    13310 Mar 11 15:38 gen_sa_accounts.py
-rw-r--r--. 1 root    root    18166 Mar 11 15:38 rclone_sa_magic.py
-rw-r--r--. 1 root    root     7377 Mar 11 15:38 Readme.md
-rw-r--r--. 1 root    root       93 Mar 11 15:38 requirements.txt


第二步 建立 Service Accounts 帳號

我們只需要建立一個項目,建立100個 Service Accounts 一天 75TB 就足夠了。
輸入
sudo python3 gen_sa_accounts.py --quick-setup 1 --new-only

如果你遇到這個錯誤

Traceback (most recent call last):
  File "gen_sa_accounts.py", line 323, in <module> download_keys=args.download
_keys
  File "gen_sa_accounts.py", line 161, in serviceaccountfactory
    proj_id = loads(open(credentials,'r').read())['installed']['project_id']
  File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.6/json/decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quote
s: line 1 column 2 (char 1
代表你 credentials.json 不是用上傳的方式,格式跑掉了~用這個方式傳入 sudo bash
-c "echo '[ctrl]+[v]' > credentials.json" 是不行的喔!

點一下 Please visit this URL to authorize this application: 後面的連結。

使用 Google 帳戶登入 -> 我們剛剛用 GCP 的帳號登入這裡相同 -> 允許 -> 複製授權

貼到 Enter the authorization code: 裡
如果出現下列字樣
Service Usage API has not been used in project 123442485074 before or it is di
sabled. Enable it by visiting https://console.developers.google.com/apis/api/s
erviceusage.googleapis.com/overview?project=xxxxx then retry. If you enabled t
his API recently, wait a few minutes for the action to propagate to our system
s and retry.
Press Enter to retry.
請點一下他給的連結記得登入的帳號是 GCP 的帳號才看的到。

Service Usage API -> 啟用

在建立的時候會出現錯誤訊息
<HttpError 403 when requesting https://iam.googleapis.com/v1/projects/xxxxxxxx
/serviceAccounts?pageSize=100&alt=json returned "Identity and Access Managemen
t (IAM) API has not been used in project 379544142899 before or it is disabled
. Enable it by visiting https://console.developers.google.com/apis/api/iam.goo
gleapis.com/overview?project=xxxxx then retry. If you enabled this API recentl
y, wait a few minutes for the action to propagate to our systems and retry.".
我們點一下那個連結
https://console.developers.googl ... is.com/overview?pro
ject=xxxxx

Identity and Access Management (IAM) API -> 啟用
重新輸入
sudo python3 gen_sa_accounts.py --quick-setup 1 --new-only
給他一點時間建立帳號

creat projects: 1
Creating 1 projects
Enabling services
Creating accounts in saf-18sxxxxx
Downloading keys from saf-18sxxxxx

輸入
cd ~/AutoRclone/accounts
ll
可以看到一堆建立好的 json 檔

批量提取 Service Accounts 參考
https://www.uud.me/qiwenzalun/au ... html/comment-page-1
輸入
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.txt
底下的 user 請取代為你的使用者名稱
這樣在 /home/user 裡就建立好 accounts 裡的 email 清單並且 10 個分隔。
右上角 齒輪 -> 下載檔案 -> 完整檔案路徑: /home/user/email.txt
確定下載 "email.txt" -> 另存新檔


第三步 將 Service Accounts 帳號加入 Group 方便管理

對於普通 Google 帳號
直接建立一個 Google Group 然後手動將 service accounts 對應的信箱一個一個加進去
,但每次只能加10個,每24小時只能加100個。
https://groups.google.com/

網路論壇 -> 建立群組 -> 步驟 1 (共 3 步) 輸入群組資訊
群組名稱:dcsatest20210313
群組電子郵件:會自動帶入我們填的群組名稱
信箱的部分改為 @googlegroups.com
建立外部群組
-> 下一個
步驟 2 (共 3 步) -> 選擇隱私權設定
誰可以搜尋群組 -> 群組成員
誰可以加入群組 -> 所有人皆可加入 我們加完後再來改
誰可以查看會話群組 -> 版主
誰可以張貼內容 -> 版主
誰可以查看成員 -> 版主
-> 下一個
步驟 3 (共 3 步) -> 新增成員
群組成員 -> 把 email.txt 前 10 個填進去
訂閱 -> 不要接收電子郵件
預設開啟 -> 直接新增成員,將成員直接新增到群組
-> 建立群組
須經人機驗證 (Captcha) -> 我不是機器人 -> 建立群組 -> 前往群組 -> 成員 -> 成員
-> 新增成員
把 email.txt 剩下的 9組 10 個帳號陸續 新增成員
都加完後 -> 群組設定 -> 誰可以加入群組 -> 僅受邀的使用者 -> 儲存變更


第四步 將來源與目的資料夾ID 加入群組信箱 dcsatest20210313@googlegroups.com
權限

gd02 -> 共用雲端硬碟 -> test2 -> 管理成員 -> 將你群組信箱 dcsatest20210313@goo
glegroups.com  的帳號輸入並設定為 [管理員] -> [共用]
資料來源的資料夾也要加,如果來源不是 Team Drive 也可以開共用把群組信箱加為檢視



第五步 開始複製遇到750GB 流量上限自動切換帳號

複製的用法為 SourceID=來源ID DestinationID=目的ID DestinationPathName=目的資料
夾名稱 後面的 100 是我們建立的帳號數
python3 rclone_sa_magic.py -s SourceID -d DestinationID -dp DestinationPathNam
e -b 1 -e 100

SourceID 為你資料來源的網址 folders/ 後面那一段,我們假設為 hijklm
https://drive.google.com/drive/u/2/folders/hijklm

DestinationID 為你資料目的網址,我們用團隊盤 folders/後面這串ID 我們假如是 abc
defg
https://drive.google.com/drive/u/1/folders/abcdefg

輸入
cd ~/AutoRclone
sudo python3 rclone_sa_magic.py -s hijklm -d abcdefg -dp abcdefg -b 1 -e 100
就會如下開始開始複製囉
rclone is detected: /bin/rclone
generating rclone config file.
rclone config file generated.
Start: 07:02:58
rclone --config ./rclone.conf copy --drive-server-side-across-configs --rc --r
c-addr="localhost:5572" -vv --ignore-existing --tpslimit 3 --transfers 3 --dri
ve-chunk-size 32M --drive-acknowledge-abuse --log-file=log_rclone.txt "src001:
" "dst001:bd001" &
>> Let us go dst001: 07:02:58
dst001: 226GB Done @ 3245.456424MB/s | checks: 0 files

假如遇到
Failed to rc: connection failed: Post "http://localhost:5572/core/pid": dial t
cp [::1]:5572: connect: connection refused
可能是權限或是路徑的關係
看來源
rclone --config rclone.conf size --disable ListR src001:
沒資料
Total objects: 0
Total size: 0 Bytes (0 Bytes)
有可能是新增的共用權限還沒有完全同步完畢,資料越多同步需要越久。
再輸入一次
rclone --config rclone.conf size --disable ListR src001:
權限有慢慢增加了
Total objects: 873
Total size: 3.192 TBytes (3509160308933 Bytes)
再次輸入
cd ~/AutoRclone
sudo python3 rclone_sa_magic.py -s hijklm -d abcdefg -dp abcdefg -b 1 -e 100


當複製完成後做一下檢查輸入
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:目標路徑

複製本地端的語法如下
cd ~/AutoRclone
sudo python3 rclone_sa_magic.py -sp YourLocalPath -d DestinationID -dp Destina
tionPathName -b 1 -e 100


之後大家再努力搬資料吧~

返回列表