# gsutil

## 從storage下載檔案

```
sudo gsutil -m cp gs://[storage路徑] [下載存放位置]
```

## 上傳檔案至storage

```
sudo gsutil cp [file] gs://[storage路徑]

# 如果要上傳資料夾，請加上 -r 參數
```

參考連結：\
<https://coder.tw/?p=6981>

## 403 insufficient permission

表示執行命令的VM可能沒有讀寫storage的權限

1. 先關閉VM並開啟編輯，直接將**Cloud API 存取權範圍**設定為**允許所有 Cloud API 的完整存取權；**&#x6216;者只更改storage的權限設定
2. 打開防火牆

參考連結：\
<http://ps.hsuweni.idv.tw/?p=4751>

## vm與storage之間的資料夾傳輸

```
下列指令會將資料從 data 值區與所有子目錄複製到 /mnt/filer 目錄。
gsutil rsync -r gs://data /mnt/filer

下列指令會將資料從 /mnt/filer 目錄與所有子目錄複製到 archive 值區。
gsutil rsync -r /mnt/filer gs://archive
```

<https://cloud.google.com/filestore/docs/copying-data?hl=zh-tw>

## 指用指令操作vm

```
# 建立
gcloud compute instances create (VM名稱) 
--zone (區域) 
--image-project (image建立者) 
--image (image名稱) 
--tags (設定網路標記) 
--custom-cpu (數字, 設定cpu) 
--custom-memory (數字, 設定記憶體) 
--boot-disk-size (數字, 設定開機硬碟容量：容量沒給單位預設是 GB) 
--boot-disk-type (硬碟類型, 設定開機硬碟類型)
--boot-disk-device-name=(名稱)
--create-disk size=(數字單位),type=(硬碟類型),name=(名稱)   (設定掛載其他硬碟：容量沒給單位預設是 GB)
--no-boot-disk-auto-delete  (設定刪除 VM 開機硬碟會保留，預設是會刪除開機硬碟)
--service-account (服務帳戶)

--accelerator=type=(名稱),count=(數字)  (使用gpu加速器)
--labels=[KEY=VALUE]  (只能有小寫英文數字-_)
--description=[字串]  (vm簡述)
--machine-type=[字串]  (gcp的套裝機器類型，n1-highmem-16= cpu*16 + 104gb ram)
--maintenance-policy=[TERMINATE/MIGRATE]  (在主機維護期間Compute Engine 可以在執行定期基礎架構維護作業期間，將您的 VM 執行個體遷移至其他硬體，而不會發生服務中斷的情況。)
--scopes=[服務別名]  (加載gcp相關服務，如：default,sql-admin,storage-rw,useraccounts-rw)
```

<https://snoopy30485.github.io/2018/06/19/GCP-GoogleCloudPlatform-creat-vm-%E6%8C%87%E4%BB%A4/#%E8%A8%AD%E5%AE%9A%E8%A8%98%E6%86%B6%E9%AB%94%E8%B7%9F-cpu>

<https://cloud.google.com/sdk/gcloud/reference/compute/instances/create#--accelerator>

```
# 停止 (建議額外指定zone與project)
yes |  gcloud compute instances stop training-363-2019-12-27-17-46-32 --project ai-clerk-platform --zone asia-east1-b
```

<https://blog.taiker.space/gcp/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stb11816.gitbook.io/python_note/gcp/gsutil.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
