一、简介

gsutil is a Python application that lets you access Cloud Storage from the command line. You can use gsutil to do a wide range of bucket and object management tasks, including:

  • Creating and deleting buckets.
  • Uploading, downloading, and deleting objects.
  • Listing buckets and objects.
  • Moving, copying, and renaming objects.
  • Editing object and bucket ACLs.

gsutil performs all operations, including uploads and downloads, using HTTPS and transport-layer security (TLS).

二、实战

  1. Open a terminal window.
  2. 执行命令安装 Google Cloud SDK:

curl https://sdk.cloud.google.com | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   443  100   443    0     0    395      0  0:00:01  0:00:01 --:--:--   395
Downloading Google Cloud SDK install script: https://dl.google.com/dl/cloudsdk/channels/rapid/install_google_cloud_sdk.bash
######################################################################## 100.0%
Running install script from: /var/folders/yq/gzptf7bj5zv09crl9rtq2hsm0000gn/T/tmp.XXXXXXXXXX.uLN3qRZA/install_google_cloud_sdk.bash
which curl
curl -# -f https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz
######################################################################## 100.0%

3.  exec -l $SHELL
4. gcloud init
Welcome! This command will take you through the configuration of gcloud.

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.

Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

You must log in to continue. Would you like to log in (Y/n)? 此时选择Y

Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?code_challenge=r43_m7lU1Y3z0qA4TjPIsQzOWdAbVSD7pgJNUFCco9I&prompt=select_account&code_challenge_method=S256&access_type=offline&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&response_type=code&client_id=32555940559.apps.googleusercontent.com&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth

此时,如果本地有浏览器会直接打开浏览器,并弹出如下页面:

点击,"Allow"之后,

    如果会进入到一个页面,并有一串码可以提供复制,复制之粘贴到刚执行终端的提示即可,完成登录。

    如果本地有浏览器,那么无需复制粘贴就可以完成自动登录了。登录终端如下图:

You are logged in as: [****@gmail.com].

Pick cloud project to use:
 [1] ****-f90b1
 [2] sunny-sunbeam-293008
 [3] wide-gamma-294510
 [4] Create a new project
Please enter numeric choice or text value (must exactly match list
item):  1

Your current project has been set to: [****-f90b1].

5. 下一步就可以执行查询了,具体例子:

gsutil cp -r gs://pubsite_prod_************/sales/salesreport_202010* /root/google