๋ณด๊ด€์ฒ˜๋ฆฌ ์Šค๋ƒ…์ƒท ๋ฐ ํ‘œ์ค€ ๋””์Šคํฌ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ


ํ‘œ์ค€ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค์–ด ์˜์—ญ ๋ฐ ๋ฆฌ์ „ Persistent Disk์™€ Google Cloud Hyperdisk ๋ณผ๋ฅจ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ธฐ์ ์œผ๋กœ ๋ฐฑ์—…ํ•ฉ๋‹ˆ๋‹ค.

์‹คํ–‰ ์ค‘์ธ ์ธ์Šคํ„ด์Šค์— ์—ฐ๊ฒฐ๋œ ์ƒํƒœ์—์„œ๋„ ๋””์Šคํฌ์—์„œ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์Šค๋ƒ…์ƒท์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ „์—ญ ๋ฆฌ์†Œ์Šค์ด๋ฏ€๋กœ ๋™์ผํ•œ ํ”„๋กœ์ ํŠธ ๋‚ด์˜ ์ƒˆ๋กœ์šด ๋””์Šคํฌ ๋˜๋Š” VM์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณต์›ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ถ”๊ฐ€์ ์ธ ๋ฐ์ดํ„ฐ ๋ณดํ˜ธ ๋ฐ ๋น„์šฉ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•ด ์Šค๋ƒ…์ƒท์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒˆ ๋””์Šคํฌ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์œ„์น˜๋ฅผ ์ œ์–ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์Šค๋ƒ…์ƒท์ด ๋ฐ์ดํ„ฐ๋ฅผ ๋ณต์›ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฆฌ์ „์„ ์ œํ•œํ•˜๋ ค๋ฉด ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๊ณ  ํ—ˆ์šฉ๋œ ์•ก์„ธ์Šค ์œ„์น˜๋ฅผ ์„ค์ •(ํ”„๋ฆฌ๋ทฐ)ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ํ”„๋กœ์ ํŠธ ๊ฐ„์— ์Šค๋ƒ…์ƒท์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—

  • (ํ”„๋ฆฌ๋ทฐ) ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด ์ด ํŽ˜์ด์ง€์˜ ๋‹จ๊ณ„๋ฅผ ์™„๋ฃŒํ•˜๊ธฐ ์ „์— ๊ธฐ๋ณธ ์Šค๋ƒ…์ƒท ์ƒ์„ฑ ๋ฐ ๋ณต์› ์œ„์น˜๋ฅผ ์„ค์ •ํ•˜์„ธ์š”.
  • ์•„์ง ์ธ์ฆ์„ ์„ค์ •ํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ธ์ฆ์€ Google Cloud ์„œ๋น„์Šค ๋ฐ API์— ์•ก์„ธ์Šคํ•˜๊ธฐ ์œ„ํ•ด ID๋ฅผ ํ™•์ธํ•˜๋Š” ํ”„๋กœ์„ธ์Šค์ž…๋‹ˆ๋‹ค. ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์ฝ”๋“œ ๋˜๋Š” ์ƒ˜ํ”Œ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ๋‹ค์Œ ์˜ต์…˜ ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•˜์—ฌ Compute Engine์— ์ธ์ฆํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

      1. After installing the Google Cloud CLI, initialize it by running the following command:

        gcloud init

        If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

      2. Set a default region and zone.
      3. Terraform

        ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์ด ํŽ˜์ด์ง€์˜ Terraform ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด gcloud CLI๋ฅผ ์„ค์น˜ ๋ฐ ์ดˆ๊ธฐํ™”ํ•œ ๋‹ค์Œ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•˜์„ธ์š”.

        1. Install the Google Cloud CLI.

        2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        3. To initialize the gcloud CLI, run the following command:

          gcloud init
        4. If you're using a local shell, then create local authentication credentials for your user account:

          gcloud auth application-default login

          You don't need to do this if you're using Cloud Shell.

          If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

        ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ์„ ์ฐธ์กฐํ•˜์„ธ์š”: Set up authentication for a local development environment.

        Go

        ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์ด ํŽ˜์ด์ง€์˜ Go ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด gcloud CLI๋ฅผ ์„ค์น˜ ๋ฐ ์ดˆ๊ธฐํ™”ํ•œ ๋‹ค์Œ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•˜์„ธ์š”.

        1. Install the Google Cloud CLI.

        2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        3. To initialize the gcloud CLI, run the following command:

          gcloud init
        4. If you're using a local shell, then create local authentication credentials for your user account:

          gcloud auth application-default login

          You don't need to do this if you're using Cloud Shell.

          If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

        ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ์„ ์ฐธ์กฐํ•˜์„ธ์š”: Set up authentication for a local development environment.

        Java

        ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์ด ํŽ˜์ด์ง€์˜ Java ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด gcloud CLI๋ฅผ ์„ค์น˜ ๋ฐ ์ดˆ๊ธฐํ™”ํ•œ ๋‹ค์Œ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•˜์„ธ์š”.

        1. Install the Google Cloud CLI.

        2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        3. To initialize the gcloud CLI, run the following command:

          gcloud init
        4. If you're using a local shell, then create local authentication credentials for your user account:

          gcloud auth application-default login

          You don't need to do this if you're using Cloud Shell.

          If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

        ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ์„ ์ฐธ์กฐํ•˜์„ธ์š”: Set up authentication for a local development environment.

        Node.js

        ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์ด ํŽ˜์ด์ง€์˜ Node.js ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด gcloud CLI๋ฅผ ์„ค์น˜ ๋ฐ ์ดˆ๊ธฐํ™”ํ•œ ๋‹ค์Œ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•˜์„ธ์š”.

        1. Install the Google Cloud CLI.

        2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        3. To initialize the gcloud CLI, run the following command:

          gcloud init
        4. If you're using a local shell, then create local authentication credentials for your user account:

          gcloud auth application-default login

          You don't need to do this if you're using Cloud Shell.

          If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

        ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ์„ ์ฐธ์กฐํ•˜์„ธ์š”: Set up authentication for a local development environment.

        Python

        ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์ด ํŽ˜์ด์ง€์˜ Python ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด gcloud CLI๋ฅผ ์„ค์น˜ ๋ฐ ์ดˆ๊ธฐํ™”ํ•œ ๋‹ค์Œ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•˜์„ธ์š”.

        1. Install the Google Cloud CLI.

        2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        3. To initialize the gcloud CLI, run the following command:

          gcloud init
        4. If you're using a local shell, then create local authentication credentials for your user account:

          gcloud auth application-default login

          You don't need to do this if you're using Cloud Shell.

          If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

        ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ์„ ์ฐธ์กฐํ•˜์„ธ์š”: Set up authentication for a local development environment.

        REST

        ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์ด ํŽ˜์ด์ง€์˜ REST API ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด gcloud CLI์— ์ œ๊ณตํ•œ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

          After installing the Google Cloud CLI, initialize it by running the following command:

          gcloud init

          If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        ์ž์„ธํ•œ ๋‚ด์šฉ์€ Google Cloud ์ธ์ฆ ๋ฌธ์„œ์˜ REST ์‚ฌ์šฉ์„ ์œ„ํ•œ ์ธ์ฆ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

ํ•„์ˆ˜ ์—ญํ•  ๋ฐ ๊ถŒํ•œ

ํ‘œ์ค€ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ถŒํ•œ์„ ์–ป์œผ๋ ค๋ฉด ๊ด€๋ฆฌ์ž์—๊ฒŒ ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ ๋‹ค์Œ IAM ์—ญํ• ์„ ๋ถ€์—ฌํ•ด ๋‹ฌ๋ผ๊ณ  ์š”์ฒญํ•˜์„ธ์š”.

์—ญํ•  ๋ถ€์—ฌ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํ”„๋กœ์ ํŠธ, ํด๋”, ์กฐ์ง์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ๊ด€๋ฆฌ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

์ด๋Ÿฌํ•œ ์‚ฌ์ „ ์ •์˜๋œ ์—ญํ• ์—๋Š” ํ‘œ์ค€ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ถŒํ•œ์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•„์š”ํ•œ ์ •ํ™•ํ•œ ๊ถŒํ•œ์„ ๋ณด๋ ค๋ฉด ํ•„์ˆ˜ ๊ถŒํ•œ ์„น์…˜์„ ํŽผ์น˜์„ธ์š”.

ํ•„์ˆ˜ ๊ถŒํ•œ

ํ‘œ์ค€ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด ๋‹ค์Œ ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

  • ์˜์—ญ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ:
    • ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ compute.snapshots.create ๊ถŒํ•œ
    • ๋””์Šคํฌ์— ๋Œ€ํ•œ compute.disks.createSnapshot ๊ถŒํ•œ
  • ๋””์Šคํฌ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์ „ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ:
    • ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ compute.snapshots.create ๊ถŒํ•œ
    • ์†Œ์Šค VM์— ๋Œ€ํ•œ compute.instances.useReadOnly ๊ถŒํ•œ
    • ๋””์Šคํฌ์— ๋Œ€ํ•œ compute.disks.createSnapshot ๊ถŒํ•œ
  • ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ์—์„œ ๋ฆฌ์ „ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ:
    • ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ compute.snapshots.create ๊ถŒํ•œ
    • ๋””์Šคํฌ์— ๋Œ€ํ•œ compute.disks.createSnapshot ๊ถŒํ•œ
  • (ํ”„๋ฆฌ๋ทฐ) ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ:
    • ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ compute.snapshots.create ๊ถŒํ•œ
    • ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ compute.regionSnapshots.create ๊ถŒํ•œ
    • ๋””์Šคํฌ์— ๋Œ€ํ•œ compute.disks.useReadOnly ๊ถŒํ•œ

์ปค์Šคํ…€ ์—ญํ• ์ด๋‚˜ ๋‹ค๋ฅธ ์‚ฌ์ „ ์ •์˜๋œ ์—ญํ• ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด ๊ถŒํ•œ์„ ๋ถ€์—ฌ๋ฐ›์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์Šค๋ƒ…์ƒท ์ƒ์„ฑ ์ค€๋น„

Persistent Disk ๋˜๋Š” Hyperdisk ๋ณผ๋ฅจ์˜ ์Šค๋ƒ…์ƒท ์ƒ์„ฑ์„ ์ค€๋น„ํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท์„ ์ค€๋น„ํ•˜๋ ค๋ฉด Compute Engine ๋””์Šคํฌ ์Šค๋ƒ…์ƒท์— ๋Œ€ํ•œ ๊ถŒ์žฅ์‚ฌํ•ญ์„ ๊ฒ€ํ† ํ•˜์„ธ์š”.

  • ๋ชจ๋“  ์ƒˆ ์ „์—ญ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ๋งž์ถค์„ค์ •ํ•˜๋ ค๋ฉด ํ”„๋กœ์ ํŠธ์˜ ์Šค๋ƒ…์ƒท ์„ค์ •์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.Google Cloud ๋Š” ์Šค๋ƒ…์ƒท ์„ค์ •์„ ์ฒ˜์Œ ์—…๋ฐ์ดํŠธํ•  ๋•Œ๊นŒ์ง€ ์‚ฌ์ „ ์ •์˜๋œ ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ๊ฐ’์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค. ์ด ์‚ฌ์ „ ์ •์˜๋œ ์œ„์น˜๋Š” ์†Œ์Šค ๋””์Šคํฌ์— ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ฉ€ํ‹ฐ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค.

  • ์Šค๋ƒ…์ƒท ์ผ์ •์„ ๋งŒ๋“ค๊ณ  ๋””์Šคํฌ์— ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋ ค๋ฉด ๋””์Šคํฌ ์Šค๋ƒ…์ƒท ์ผ์ • ๋งŒ๋“ค๊ธฐ๋ฅผ ๊ฒ€ํ† ํ•˜์„ธ์š”. ๋””์Šคํฌ๋ฅผ ์˜ˆ์•ฝ๋œ ์Šค๋ƒ…์ƒท์œผ๋กœ ์ •๊ธฐ์ ์œผ๋กœ ๋ฐฑ์—…ํ•˜๋ฉด ์˜ˆ๊ธฐ์น˜ ์•Š์€ ๋ฐ์ดํ„ฐ ์†์‹ค ์œ„ํ—˜์„ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Persistent Disk ๋˜๋Š” Hyperdisk ๋ณผ๋ฅจ์˜ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ

๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋‹จ๊ณ„๋Š” ์˜์—ญ ๋””์Šคํฌ ๋˜๋Š” ๋ฆฌ์ „ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š”์ง€ ์—ฌ๋ถ€์— ๋”ฐ๋ผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

์˜์—ญ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ

์ฝ˜์†”

  1. Google Cloud ์ฝ˜์†”์—์„œ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

    ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ ํŽ˜์ด์ง€๋กœ ์ด๋™
  2. ์Šค๋ƒ…์ƒท ์ด๋ฆ„์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  3. ์Šค๋ƒ…์ƒท ์œ ํ˜•์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ ์žฅ๊ธฐ ๋ฐฑ์—… ๋ฐ ์žฌํ•ด ๋ณต๊ตฌ์— ๊ฐ€์žฅ ์ ํ•ฉํ•œ STANDARD ์Šค๋ƒ…์ƒท์ž…๋‹ˆ๋‹ค.

    ๋น„์šฉ ํšจ์œจ์ ์ธ ๋ฐ์ดํ„ฐ ๋ณด๊ด€์„ ์œ„ํ•ด์„œ๋Š” ๋ณด๊ด€์ฒ˜๋ฆฌ ์Šค๋ƒ…์ƒท์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  4. (์„ ํƒ์‚ฌํ•ญ) ์Šค๋ƒ…์ƒท์— ๋Œ€ํ•œ ์„ค๋ช…์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  5. ์†Œ์Šค ๋””์Šคํฌ์—์„œ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” ๊ธฐ์กด ๋””์Šคํฌ๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  6. ์œ„์น˜ ์„น์…˜์—์„œ ์Šค๋ƒ…์ƒท ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

    ์Šค๋ƒ…์ƒท ์„ค์ •์— ์ •์˜๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค์„ค์ •๋œ ๊ธฐ๋ณธ ์œ„์น˜๊ฐ€ ์ž๋™์œผ๋กœ ์„ ํƒ๋ฉ๋‹ˆ๋‹ค. ์„ ํƒ์ ์œผ๋กœ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ด์„œ ์Šค๋ƒ…์ƒท ์„ค์ •์„ ์žฌ์ •์˜ํ•˜๊ณ  ์ปค์Šคํ…€ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    1. ์Šค๋ƒ…์ƒท์— ๋Œ€ํ•ด ์›ํ•˜๋Š” ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์œ ํ˜•์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

      • ๋” ๋†’์€ ๊ฐ€์šฉ์„ฑ์„ ์œ„ํ•ด์„œ๋Š” ๋” ๋†’์€ ๋น„์šฉ์˜ ๋ฉ€ํ‹ฐ ๋ฆฌ์ „์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
      • ๋” ์ €๋ ดํ•œ ๋น„์šฉ์œผ๋กœ ๋ฐ์ดํ„ฐ์˜ ๋ฌผ๋ฆฌ์  ์œ„์น˜๋ฅผ ๋” ์„ธ๋ถ€์ ์œผ๋กœ ์ œ์–ดํ•˜๋ ค๋ฉด ๋ฆฌ์ „ ์Šค๋ƒ…์ƒท์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
    2. ์œ„์น˜ ์„ ํƒ ํ•„๋“œ์—์„œ ์‚ฌ์šฉํ•˜๋ ค๋Š” ํŠน์ • ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. ์†Œ์Šค ๋””์Šคํฌ์— ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋””์Šคํฌ ์œ„์น˜ ๊ธฐ์ค€์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  7. ๋งŒ๋“ค๊ธฐ๋ฅผ ํด๋ฆญํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

gcloud

์Šค๋ƒ…์ƒท ์„ค์ •์— ๋”ฐ๋ผ ๋˜๋Š” ์„ ํƒํ•œ ๋Œ€์ฒด ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ •์˜๋œ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์ •์ฑ…์œผ๋กœ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์Šค๋ƒ…์ƒท ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์„ ํƒ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

  • ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค์„ค์ •๋œ ๊ธฐ๋ณธ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด gcloud compute snapshots create ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk-zone=SOURCE_ZONE \
        --source-disk=SOURCE_DISK_NAME \
        --snapshot-type=SNAPSHOT_TYPE
    
  • ๋˜๋Š” ์Šค๋ƒ…์ƒท ์„ค์ •์„ ์žฌ์ •์˜ํ•˜๊ณ  ์ปค์Šคํ…€ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด ์Šค๋ƒ…์ƒท ์ €์žฅ ์œ„์น˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” --storage-location ํ”Œ๋ž˜๊ทธ๋ฅผ ํฌํ•จํ•˜์„ธ์š”.

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk-zone=SOURCE_ZONE \
        --source-disk=SOURCE_DISK_NAME \
        --snapshot-type=SNAPSHOT_TYPE \
        --storage-location=STORAGE_LOCATION
    
  • (๋ฏธ๋ฆฌ๋ณด๊ธฐ) ํ—ˆ์šฉ๋œ ๋ฆฌ์ „์—์„œ ๋ฆฌ์ „ ๋ฒ”์œ„์˜ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด --region ํ”Œ๋ž˜๊ทธ๋ฅผ ํฌํ•จํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์œ„์น˜๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    gcloud beta compute snapshots create SNAPSHOT_NAME \
        --region=SNAPSHOT_SCOPE_REGION
        --source-disk=SOURCE_DISK_NAME \
        --source-disk-zone=SOURCE_ZONE \
        --snapshot-type=SNAPSHOT_TYPE
    

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • SNAPSHOT_NAME: ์Šค๋ƒ…์ƒท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SOURCE_ZONE: ์†Œ์Šค ๋””์Šคํฌ์˜ ์˜์—ญ์ž…๋‹ˆ๋‹ค.
  • SOURCE_DISK_NAME: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” Persistent Disk ๋ณผ๋ฅจ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SNAPSHOT_TYPE: ์Šค๋ƒ…์ƒท ์œ ํ˜•์ž…๋‹ˆ๋‹ค(STANDARD ๋˜๋Š” ARCHIVE). ์Šค๋ƒ…์ƒท ์œ ํ˜•์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด STANDARD ์Šค๋ƒ…์ƒท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • STORAGE_LOCATION: (์„ ํƒ์‚ฌํ•ญ) ์ „์—ญ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ฒฝ์šฐ ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•  Cloud Storage ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ๋˜๋Š” Cloud Storage ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋Š” ํ•˜๋‚˜๋งŒ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค ์„ค์ •๋œ ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์žฌ์ •์˜ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ์—๋งŒ --storage-location ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • SNAPSHOT_SCOPE_REGION: (์„ ํƒ์‚ฌํ•ญ) ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ฒฝ์šฐ ์Šค๋ƒ…์ƒท ๋ฒ”์œ„๊ฐ€ ์ง€์ •๋œ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํฌํ•จํ•˜๋ฉด --storage-location ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. STORAGE_LOCATION์€ SNAPSHOT_SCOPE_REGION์œผ๋กœ ์ž๋™ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.

Terraform

์˜์—ญ Persistent Disk์˜ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด google_compute_snapshot ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.

resource "google_compute_snapshot" "snapdisk" {
  name        = "snapshot-name"
  source_disk = google_compute_disk.default.name
  zone        = "us-central1-a"
}

Terraform ๊ตฌ์„ฑ์„ ์ ์šฉํ•˜๊ฑฐ๋‚˜ ์‚ญ์ œํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๊ธฐ๋ณธ Terraform ๋ช…๋ น์–ด๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

Go

Go

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Compute Engine ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Go ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Compute Engine Go API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Compute Engine์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import (
	"context"
	"fmt"
	"io"

	compute "cloud.google.com/go/compute/apiv1"
	computepb "cloud.google.com/go/compute/apiv1/computepb"
	"google.golang.org/protobuf/proto"
)

// createSnapshot creates a snapshot of a disk.
func createSnapshot(
	w io.Writer,
	projectID, diskName, snapshotName, zone, region, location, diskProjectID string,
) error {
	// projectID := "your_project_id"
	// diskName := "your_disk_name"
	// snapshotName := "your_snapshot_name"
	// zone := "europe-central2-b"
	// region := "eupore-central2"
	// location = "eupore-central2"
	// diskProjectID = "YOUR_DISK_PROJECT_ID"

	ctx := context.Background()

	snapshotsClient, err := compute.NewSnapshotsRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewSnapshotsRESTClient: %w", err)
	}
	defer snapshotsClient.Close()

	if zone == "" && region == "" {
		return fmt.Errorf("you need to specify `zone` or `region` for this function to work")
	}

	if zone != "" && region != "" {
		return fmt.Errorf("you can't set both `zone` and `region` parameters")
	}

	if diskProjectID == "" {
		diskProjectID = projectID
	}

	disk := &computepb.Disk{}
	locations := []string{}
	if location != "" {
		locations = append(locations, location)
	}

	if zone != "" {
		disksClient, err := compute.NewDisksRESTClient(ctx)
		if err != nil {
			return fmt.Errorf("NewDisksRESTClient: %w", err)
		}
		defer disksClient.Close()

		getDiskReq := &computepb.GetDiskRequest{
			Project: projectID,
			Zone:    zone,
			Disk:    diskName,
		}

		disk, err = disksClient.Get(ctx, getDiskReq)
		if err != nil {
			return fmt.Errorf("unable to get disk: %w", err)
		}
	} else {
		regionDisksClient, err := compute.NewRegionDisksRESTClient(ctx)
		if err != nil {
			return fmt.Errorf("NewRegionDisksRESTClient: %w", err)
		}
		defer regionDisksClient.Close()

		getDiskReq := &computepb.GetRegionDiskRequest{
			Project: projectID,
			Region:  region,
			Disk:    diskName,
		}

		disk, err = regionDisksClient.Get(ctx, getDiskReq)
		if err != nil {
			return fmt.Errorf("unable to get disk: %w", err)
		}
	}

	req := &computepb.InsertSnapshotRequest{
		Project: projectID,
		SnapshotResource: &computepb.Snapshot{
			Name:             proto.String(snapshotName),
			SourceDisk:       proto.String(disk.GetSelfLink()),
			StorageLocations: locations,
		},
	}

	op, err := snapshotsClient.Insert(ctx, req)
	if err != nil {
		return fmt.Errorf("unable to create snapshot: %w", err)
	}

	if err = op.Wait(ctx); err != nil {
		return fmt.Errorf("unable to wait for the operation: %w", err)
	}

	fmt.Fprintf(w, "Snapshot created\n")

	return nil
}

์ž๋ฐ”

Java

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Compute Engine ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Java ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Compute Engine Java API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Compute Engine์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.


import com.google.cloud.compute.v1.Disk;
import com.google.cloud.compute.v1.DisksClient;
import com.google.cloud.compute.v1.Operation;
import com.google.cloud.compute.v1.RegionDisksClient;
import com.google.cloud.compute.v1.Snapshot;
import com.google.cloud.compute.v1.SnapshotsClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateSnapshot {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    // You need to pass `zone` or `region` parameter relevant to the disk you want to
    // snapshot, but not both. Pass `zone` parameter for zonal disks and `region` for
    // regional disks.

    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";

    // Name of the disk you want to create.
    String diskName = "YOUR_DISK_NAME";

    // Name of the snapshot that you want to create.
    String snapshotName = "YOUR_SNAPSHOT_NAME";

    // The zone of the source disk from which you create the snapshot (for zonal disks).
    String zone = "europe-central2-b";

    // The region of the source disk from which you create the snapshot (for regional disks).
    String region = "your-disk-region";

    // The Cloud Storage multi-region or the Cloud Storage region where you
    // want to store your snapshot.
    // You can specify only one storage location. Available locations:
    // https://cloud.google.com/storage/docs/locations#available-locations
    String location = "europe-central2";

    // Project ID or project number of the Cloud project that
    // hosts the disk you want to snapshot. If not provided, the value will be defaulted
    // to 'projectId' value.
    String diskProjectId = "YOUR_DISK_PROJECT_ID";

    createSnapshot(projectId, diskName, snapshotName, zone, region, location, diskProjectId);
  }

  // Creates a snapshot of a disk.
  public static void createSnapshot(String projectId, String diskName, String snapshotName,
      String zone, String region, String location, String diskProjectId)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `snapshotsClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {

      if (zone.isEmpty() && region.isEmpty()) {
        throw new Error("You need to specify 'zone' or 'region' for this function to work");
      }

      if (!zone.isEmpty() && !region.isEmpty()) {
        throw new Error("You can't set both 'zone' and 'region' parameters");
      }

      // If Disk's project id is not specified, then the projectId parameter will be used.
      if (diskProjectId.isEmpty()) {
        diskProjectId = projectId;
      }

      // If zone is not empty, use the DisksClient to create a disk.
      // Else, use the RegionDisksClient.
      Disk disk;
      if (!zone.isEmpty()) {
        DisksClient disksClient = DisksClient.create();
        disk = disksClient.get(projectId, zone, diskName);
      } else {
        RegionDisksClient regionDisksClient = RegionDisksClient.create();
        disk = regionDisksClient.get(diskProjectId, region, diskName);
      }

      // Set the snapshot properties.
      Snapshot snapshotResource;
      if (!location.isEmpty()) {
        snapshotResource = Snapshot.newBuilder()
            .setName(snapshotName)
            .setSourceDisk(disk.getSelfLink())
            .addStorageLocations(location)
            .build();
      } else {
        snapshotResource = Snapshot.newBuilder()
            .setName(snapshotName)
            .setSourceDisk(disk.getSelfLink())
            .build();
      }

      // Wait for the operation to complete.
      Operation operation = snapshotsClient.insertAsync(projectId, snapshotResource)
          .get(3, TimeUnit.MINUTES);

      if (operation.hasError()) {
        System.out.println("Snapshot creation failed!" + operation);
        return;
      }

      // Retrieve the created snapshot.
      Snapshot snapshot = snapshotsClient.get(projectId, snapshotName);
      System.out.printf("Snapshot created: %s", snapshot.getName());

    }
  }
}

Node.js

Node.js

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Compute Engine ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Node.js ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Compute Engine Node.js API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Compute Engine์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const diskName = 'YOUR_DISK_NAME';
// const snapshotName = 'YOUR_SNAPSHOT_NAME';
// const zone = 'europe-central2-b';
// const region = '';
// const location = 'europe-central2';
// let diskProjectId = 'YOUR_DISK_PROJECT_ID';

const compute = require('@google-cloud/compute');

async function createSnapshot() {
  const snapshotsClient = new compute.SnapshotsClient();

  let disk;

  if (!zone && !region) {
    throw new Error(
      'You need to specify `zone` or `region` for this function to work.'
    );
  }

  if (zone && region) {
    throw new Error("You can't set both `zone` and `region` parameters");
  }

  if (!diskProjectId) {
    diskProjectId = projectId;
  }

  if (zone) {
    const disksClient = new compute.DisksClient();
    [disk] = await disksClient.get({
      project: diskProjectId,
      zone,
      disk: diskName,
    });
  } else {
    const regionDisksClient = new compute.RegionDisksClient();
    [disk] = await regionDisksClient.get({
      project: diskProjectId,
      region,
      disk: diskName,
    });
  }

  const snapshotResource = {
    name: snapshotName,
    sourceDisk: disk.selfLink,
  };

  if (location) {
    snapshotResource.storageLocations = [location];
  }

  const [response] = await snapshotsClient.insert({
    project: projectId,
    snapshotResource,
  });
  let operation = response.latestResponse;
  const operationsClient = new compute.GlobalOperationsClient();

  // Wait for the create snapshot operation to complete.
  while (operation.status !== 'DONE') {
    [operation] = await operationsClient.wait({
      operation: operation.name,
      project: projectId,
    });
  }

  console.log('Snapshot created.');
}

createSnapshot();

Python

Python

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Compute Engine ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Python ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Compute Engine Python API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Compute Engine์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

from __future__ import annotations

import sys
from typing import Any

from google.api_core.extended_operation import ExtendedOperation
from google.cloud import compute_v1


def wait_for_extended_operation(
    operation: ExtendedOperation, verbose_name: str = "operation", timeout: int = 300
) -> Any:
    """
    Waits for the extended (long-running) operation to complete.

    If the operation is successful, it will return its result.
    If the operation ends with an error, an exception will be raised.
    If there were any warnings during the execution of the operation
    they will be printed to sys.stderr.

    Args:
        operation: a long-running operation you want to wait on.
        verbose_name: (optional) a more verbose name of the operation,
            used only during error and warning reporting.
        timeout: how long (in seconds) to wait for operation to finish.
            If None, wait indefinitely.

    Returns:
        Whatever the operation.result() returns.

    Raises:
        This method will raise the exception received from `operation.exception()`
        or RuntimeError if there is no exception set, but there is an `error_code`
        set for the `operation`.

        In case of an operation taking longer than `timeout` seconds to complete,
        a `concurrent.futures.TimeoutError` will be raised.
    """
    result = operation.result(timeout=timeout)

    if operation.error_code:
        print(
            f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
            file=sys.stderr,
            flush=True,
        )
        print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
        raise operation.exception() or RuntimeError(operation.error_message)

    if operation.warnings:
        print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
        for warning in operation.warnings:
            print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)

    return result


def create_snapshot(
    project_id: str,
    disk_name: str,
    snapshot_name: str,
    *,
    zone: str | None = None,
    region: str | None = None,
    location: str | None = None,
    disk_project_id: str | None = None,
) -> compute_v1.Snapshot:
    """
    Create a snapshot of a disk.

    You need to pass `zone` or `region` parameter relevant to the disk you want to
    snapshot, but not both. Pass `zone` parameter for zonal disks and `region` for
    regional disks.

    Args:
        project_id: project ID or project number of the Cloud project you want
            to use to store the snapshot.
        disk_name: name of the disk you want to snapshot.
        snapshot_name: name of the snapshot to be created.
        zone: name of the zone in which is the disk you want to snapshot (for zonal disks).
        region: name of the region in which is the disk you want to snapshot (for regional disks).
        location: The Cloud Storage multi-region or the Cloud Storage region where you
            want to store your snapshot.
            You can specify only one storage location. Available locations:
            https://cloud.google.com/storage/docs/locations#available-locations
        disk_project_id: project ID or project number of the Cloud project that
            hosts the disk you want to snapshot. If not provided, will look for
            the disk in the `project_id` project.

    Returns:
        The new snapshot instance.
    """
    if zone is None and region is None:
        raise RuntimeError(
            "You need to specify `zone` or `region` for this function to work."
        )
    if zone is not None and region is not None:
        raise RuntimeError("You can't set both `zone` and `region` parameters.")

    if disk_project_id is None:
        disk_project_id = project_id

    if zone is not None:
        disk_client = compute_v1.DisksClient()
        disk = disk_client.get(project=disk_project_id, zone=zone, disk=disk_name)
    else:
        regio_disk_client = compute_v1.RegionDisksClient()
        disk = regio_disk_client.get(
            project=disk_project_id, region=region, disk=disk_name
        )

    snapshot = compute_v1.Snapshot()
    snapshot.source_disk = disk.self_link
    snapshot.name = snapshot_name
    if location:
        snapshot.storage_locations = [location]

    snapshot_client = compute_v1.SnapshotsClient()
    operation = snapshot_client.insert(project=project_id, snapshot_resource=snapshot)

    wait_for_extended_operation(operation, "snapshot creation")

    return snapshot_client.get(project=project_id, snapshot=snapshot_name)

REST

์Šค๋ƒ…์ƒท ์„ค์ •์— ๋”ฐ๋ผ ๋˜๋Š” ์„ ํƒํ•œ ๋Œ€์ฒด ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ •์˜๋œ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์ •์ฑ…์œผ๋กœ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์Šค๋ƒ…์ƒท ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์„ ํƒ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

  • ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค์„ค์ •๋œ ๊ธฐ๋ณธ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด snapshots.insert ๋ฉ”์„œ๋“œ์— POST ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•˜์„ธ์š”.

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    {
        "name": "SNAPSHOT_NAME",
        "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME",
        "snapshotType": "SNAPSHOT_TYPE"
    }
    
  • ๋˜๋Š” ์Šค๋ƒ…์ƒท ์„ค์ •์„ ์žฌ์ •์˜ํ•˜๊ณ  ์ปค์Šคํ…€ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด snapshots.insert ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด POST ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์š”์ฒญ์— storageLocations ์†์„ฑ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    {
        "name": "SNAPSHOT_NAME",
        "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME",
        "snapshotType": "SNAPSHOT_TYPE",
        "storageLocations": [
            "STORAGE_LOCATION"
        ],
    }
    
  • (๋ฏธ๋ฆฌ๋ณด๊ธฐ) ํ—ˆ์šฉ๋œ ๋ฆฌ์ „์—์„œ ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด snapshots.insert ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด POST ์š”์ฒญ์„ ์‹คํ–‰ํ•˜๊ณ  ์ƒ์„ฑ ๋ฆฌ์ „์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

    POST https://compute.googleapis.com/compute/beta/projects/DESTINATION_PROJECT_ID/regions/SNAPSHOT_SCOPE_REGION/snapshots
    {
        "name": "SNAPSHOT_NAME",
        "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME",
        "snapshotType": "SNAPSHOT_TYPE"
    }
    

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • DESTINATION_PROJECT_ID: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” ํ”„๋กœ์ ํŠธ์˜ ID์ž…๋‹ˆ๋‹ค.
  • SNAPSHOT_NAME: ์Šค๋ƒ…์ƒท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SOURCE_PROJECT_ID: ์†Œ์Šค ๋””์Šคํฌ ํ”„๋กœ์ ํŠธ์˜ ID์ž…๋‹ˆ๋‹ค.
  • SOURCE_ZONE: ์†Œ์Šค ๋””์Šคํฌ์˜ ์˜์—ญ์ž…๋‹ˆ๋‹ค.
  • SOURCE_DISK_NAME: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” Persistent Disk ๋ณผ๋ฅจ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SNAPSHOT_TYPE: ์Šค๋ƒ…์ƒท ์œ ํ˜•์ž…๋‹ˆ๋‹ค(STANDARD ๋˜๋Š” ARCHIVE). ์Šค๋ƒ…์ƒท ์œ ํ˜•์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด STANDARD ์Šค๋ƒ…์ƒท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • STORAGE_LOCATION: (์„ ํƒ์‚ฌํ•ญ) ์ „์—ญ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ฒฝ์šฐ ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•  Cloud Storage ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ๋˜๋Š” Cloud Storage ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋Š” ํ•˜๋‚˜๋งŒ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค ์„ค์ •๋œ ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์žฌ์ •์˜ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ์—๋งŒ storageLocations ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • SNAPSHOT_SCOPE_REGION: (์„ ํƒ์‚ฌํ•ญ) ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ฒฝ์šฐ ์Šค๋ƒ…์ƒท ๋ฒ”์œ„๊ฐ€ ์ง€์ •๋œ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํฌํ•จํ•˜๋ฉด storageLocations ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. STORAGE_LOCATION์€ SNAPSHOT_SCOPE_REGION์œผ๋กœ ์ž๋™ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.

๋ฆฌ์ „ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ

๋‹ค์Œ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜๋กœ ๋ฆฌ์ „ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์†Œ์Šค ๋””์Šคํฌ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ์Šค๋ƒ…์ƒท ์ƒ์„ฑ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋™๊ธฐํ™”๋œ ์˜์—ญ ๋ณต์ œ๋ณธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์„ฑ๋Šฅ ์ €ํ•˜๋œ ๋””์Šคํฌ์˜ ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Google Cloud CLI ๋˜๋Š” REST๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฒดํฌํฌ์ธํŠธ์—์„œ๋งŒ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋””์Šคํฌ๊ฐ€ ์ค€๋น„๋˜๋ฉด ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฆฌ์ „ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท์„ ์ƒ์„ฑํ•  ๋•Œ ์†Œ์Šค ๋””์Šคํฌ๊ฐ€ ์žˆ๋Š” ๋ฆฌ์ „์„ ์ง€์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ฝ˜์†”

  1. Google Cloud ์ฝ˜์†”์—์„œ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

    ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ ํŽ˜์ด์ง€๋กœ ์ด๋™
  2. ์Šค๋ƒ…์ƒท ์ด๋ฆ„์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  3. ์Šค๋ƒ…์ƒท ์œ ํ˜•์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ ์žฅ๊ธฐ ๋ฐฑ์—… ๋ฐ ์žฌํ•ด ๋ณต๊ตฌ์— ๊ฐ€์žฅ ์ ํ•ฉํ•œ STANDARD ์Šค๋ƒ…์ƒท์ž…๋‹ˆ๋‹ค.

    ๋น„์šฉ ํšจ์œจ์ ์ธ ๋ฐ์ดํ„ฐ ๋ณด๊ด€์„ ์œ„ํ•ด์„œ๋Š” ๋ณด๊ด€์ฒ˜๋ฆฌ ์Šค๋ƒ…์ƒท์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  4. (์„ ํƒ์‚ฌํ•ญ) ์Šค๋ƒ…์ƒท์— ๋Œ€ํ•œ ์„ค๋ช…์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  5. ์†Œ์Šค ๋””์Šคํฌ์—์„œ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” ๊ธฐ์กด ๋””์Šคํฌ๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  6. ์œ„์น˜ ์„น์…˜์—์„œ ์Šค๋ƒ…์ƒท ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

    ์Šค๋ƒ…์ƒท ์„ค์ •์— ์ •์˜๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค์„ค์ •๋œ ๊ธฐ๋ณธ ์œ„์น˜๊ฐ€ ์ž๋™์œผ๋กœ ์„ ํƒ๋ฉ๋‹ˆ๋‹ค. ์„ ํƒ์ ์œผ๋กœ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ด์„œ ์Šค๋ƒ…์ƒท ์„ค์ •์„ ์žฌ์ •์˜ํ•˜๊ณ  ์ปค์Šคํ…€ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    1. ์Šค๋ƒ…์ƒท์— ๋Œ€ํ•ด ์›ํ•˜๋Š” ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์œ ํ˜•์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

      • ๋” ๋†’์€ ๊ฐ€์šฉ์„ฑ์„ ์œ„ํ•ด์„œ๋Š” ๋” ๋†’์€ ๋น„์šฉ์˜ ๋ฉ€ํ‹ฐ ๋ฆฌ์ „์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
      • ๋” ์ €๋ ดํ•œ ๋น„์šฉ์œผ๋กœ ๋ฐ์ดํ„ฐ์˜ ๋ฌผ๋ฆฌ์  ์œ„์น˜๋ฅผ ๋” ์„ธ๋ถ€์ ์œผ๋กœ ์ œ์–ดํ•˜๋ ค๋ฉด ๋ฆฌ์ „ ์Šค๋ƒ…์ƒท์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
    2. ์œ„์น˜ ์„ ํƒ ํ•„๋“œ์—์„œ ์‚ฌ์šฉํ•˜๋ ค๋Š” ํŠน์ • ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. ์†Œ์Šค ๋””์Šคํฌ์— ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋””์Šคํฌ ์œ„์น˜ ๊ธฐ์ค€์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  7. ๋งŒ๋“ค๊ธฐ๋ฅผ ํด๋ฆญํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

gcloud

์†Œ์Šค ๋””์Šคํฌ์˜ ๋ฐ์ดํ„ฐ ๋˜๋Š” ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋””์Šคํฌ ๋ฐ์ดํ„ฐ

์Šค๋ƒ…์ƒท ์„ค์ •์— ์ •์˜๋œ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์ •์ฑ… ๋˜๋Š” ์ž์‹ ์ด ์„ ํƒํ•œ ๋‹ค๋ฅธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์‚ฌ์šฉํ•ด ๋””์Šคํฌ์˜ ๋ฐ์ดํ„ฐ์—์„œ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์Šค๋ƒ…์ƒท ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์„ ํƒ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

  • ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค์„ค์ •๋œ ๊ธฐ๋ณธ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด gcloud compute snapshots create ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk-region=SOURCE_REGION \
        --source-disk=SOURCE_DISK_NAME \
        --snapshot-type=SNAPSHOT_TYPE
    
  • ๋˜๋Š” ์Šค๋ƒ…์ƒท ์„ค์ •์„ ์žฌ์ •์˜ํ•˜๊ณ  ์ปค์Šคํ…€ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด ์Šค๋ƒ…์ƒท ์ €์žฅ ์œ„์น˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” --storage-location ํ”Œ๋ž˜๊ทธ๋ฅผ ํฌํ•จํ•˜์„ธ์š”.

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk-region=SOURCE_REGION \
        --source-disk=SOURCE_DISK_NAME \
        --snapshot-type=SNAPSHOT_TYPE \
        --storage-location=STORAGE_LOCATION
    
  • (๋ฏธ๋ฆฌ๋ณด๊ธฐ) ํ—ˆ์šฉ๋œ ๋ฆฌ์ „์—์„œ ๋ฆฌ์ „ ๋ฒ”์œ„์˜ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด --region ํ”Œ๋ž˜๊ทธ๋ฅผ ํฌํ•จํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์œ„์น˜๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    gcloud beta compute snapshots create SNAPSHOT_NAME \
        --region=SNAPSHOT_SCOPE_REGION \
        --source-disk=SOURCE_DISK_NAME \
        --source-disk-region=SOURCE_REGION \
        --snapshot-type=SNAPSHOT_TYPE
    

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • SNAPSHOT_NAME: ์Šค๋ƒ…์ƒท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SOURCE_REGION: ์†Œ์Šค ๋””์Šคํฌ์˜ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค.
  • SOURCE_DISK_NAME: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” ๋ฆฌ์ „ Persistent Disk ๋˜๋Š” Hyperdisk Balanced ๊ณ ๊ฐ€์šฉ์„ฑ ๋ณผ๋ฅจ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SNAPSHOT_TYPE: ์Šค๋ƒ…์ƒท ์œ ํ˜•์ž…๋‹ˆ๋‹ค(STANDARD ๋˜๋Š” ARCHIVE). ์Šค๋ƒ…์ƒท ์œ ํ˜•์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด STANDARD ์Šค๋ƒ…์ƒท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • STORAGE_LOCATION: (์„ ํƒ์‚ฌํ•ญ) ์ „์—ญ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ฒฝ์šฐ ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•  Cloud Storage ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ๋˜๋Š” Cloud Storage ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋Š” ํ•˜๋‚˜๋งŒ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค ์„ค์ •๋œ ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์žฌ์ •์˜ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ์—๋งŒ --storage-location ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • SNAPSHOT_SCOPE_REGION: (์„ ํƒ์‚ฌํ•ญ) ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ฒฝ์šฐ ์Šค๋ƒ…์ƒท ๋ฒ”์œ„๊ฐ€ ์ง€์ •๋œ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํฌํ•จํ•˜๋ฉด --storage-location ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. STORAGE_LOCATION์€ SNAPSHOT_SCOPE_REGION์œผ๋กœ ์ž๋™ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.

์ฒดํฌํฌ์ธํŠธ

์„ฑ๋Šฅ ์ €ํ•˜๋œ ๋””์Šคํฌ์˜ ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ถˆ์™„์ „ํ•œ ๋ณต์ œ๋ณธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ•œ ์Šค๋ƒ…์ƒท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด gcloud compute snapshots create ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋„๋ก ์ง€์ •ํ•˜๋ ค๋ฉด --source-disk-for-recovery-checkpoint ํ”Œ๋ž˜๊ทธ๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. --source-disk ๋ฐ --source-disk-region ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์ œ์™ธํ•ฉ๋‹ˆ๋‹ค.

gcloud compute snapshots create SNAPSHOT_NAME \
    --source-disk-for-recovery-checkpoint=SOURCE_DISK \
    --source-disk-for-recovery-checkpoint-region=SOURCE_REGION \
    --storage-location=STORAGE_LOCATION \
    --snapshot-type=SNAPSHOT_TYPE

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • DESTINATION_PROJECT_ID: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” ํ”„๋กœ์ ํŠธ์˜ ID์ž…๋‹ˆ๋‹ค.
  • SNAPSHOT_NAME: ์Šค๋ƒ…์ƒท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SOURCE_PROJECT_ID: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์†Œ์Šค ๋””์Šคํฌ์˜ ํ”„๋กœ์ ํŠธ ID์ž…๋‹ˆ๋‹ค.
  • SOURCE_REGION: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์†Œ์Šค ๋””์Šคํฌ์˜ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค.
  • SOURCE_DISK_NAME: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์†Œ์Šค ๋””์Šคํฌ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • STORAGE_LOCATION: (์„ ํƒ์‚ฌํ•ญ) ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•  Cloud Storage ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ๋˜๋Š” Cloud Storage ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋Š” ํ•˜๋‚˜๋งŒ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค ์„ค์ •๋œ ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์žฌ์ •์˜ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ์—๋งŒ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • SNAPSHOT_TYPE: ์Šค๋ƒ…์ƒท ์œ ํ˜•์ž…๋‹ˆ๋‹ค(STANDARD ๋˜๋Š” ARCHIVE). ์Šค๋ƒ…์ƒท ์œ ํ˜•์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด STANDARD ์Šค๋ƒ…์ƒท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ฑ๋Šฅ ์ €ํ•˜๋œ ๋””์Šคํฌ์—์„œ๋งŒ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ๊ธฐ๊ฐ€ ์™„์ „ํžˆ ๋ณต์ œ๋˜์—ˆ์„ ๋•Œ ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ์—์„œ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๊ณ  ์‹œ๋„ํ•˜๋ฉด ๋‹ค์Œ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

The device is fully replicated and should not create snapshots out of a recovery checkpoint. Please
create regular snapshots instead.

Google Cloud CLI๋Š” ์ž‘์—…์ด READY ๋˜๋Š” FAILED ์ƒํƒœ๋ฅผ ๋ฐ˜ํ™˜ํ•  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ƒํƒœ๊ฐ€ ๋ฐ˜ํ™˜๋˜์ง€ ์•Š๊ณ  ์ตœ๋Œ€ ์ œํ•œ ์‹œ๊ฐ„์— ๋„๋‹ฌํ•˜๋ฉด ์Šค๋ƒ…์ƒท์— ๋Œ€ํ•ด ๋งˆ์ง€๋ง‰์œผ๋กœ ์•Œ๋ ค์ง„ ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Terraform

Google Cloud ์šฉ Terraform ์ œ๊ณต์—…์ฒด๋Š” ๋ฆฌ์ „ ๋””์Šคํฌ์˜ ์Šค๋ƒ…์ƒท ๋งŒ๋“ค๊ธฐ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด ์ œํ•œ์‚ฌํ•ญ์„ ์ถ”์ ํ•˜๋ ค๋ฉด GitHub์˜ ๋ฌธ์ œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

Go

Go

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Compute Engine ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Go ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Compute Engine Go API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Compute Engine์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import (
	"context"
	"fmt"
	"io"

	compute "cloud.google.com/go/compute/apiv1"
	computepb "cloud.google.com/go/compute/apiv1/computepb"
	"google.golang.org/protobuf/proto"
)

// createSnapshot creates a snapshot of a disk.
func createSnapshot(
	w io.Writer,
	projectID, diskName, snapshotName, zone, region, location, diskProjectID string,
) error {
	// projectID := "your_project_id"
	// diskName := "your_disk_name"
	// snapshotName := "your_snapshot_name"
	// zone := "europe-central2-b"
	// region := "eupore-central2"
	// location = "eupore-central2"
	// diskProjectID = "YOUR_DISK_PROJECT_ID"

	ctx := context.Background()

	snapshotsClient, err := compute.NewSnapshotsRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewSnapshotsRESTClient: %w", err)
	}
	defer snapshotsClient.Close()

	if zone == "" && region == "" {
		return fmt.Errorf("you need to specify `zone` or `region` for this function to work")
	}

	if zone != "" && region != "" {
		return fmt.Errorf("you can't set both `zone` and `region` parameters")
	}

	if diskProjectID == "" {
		diskProjectID = projectID
	}

	disk := &computepb.Disk{}
	locations := []string{}
	if location != "" {
		locations = append(locations, location)
	}

	if zone != "" {
		disksClient, err := compute.NewDisksRESTClient(ctx)
		if err != nil {
			return fmt.Errorf("NewDisksRESTClient: %w", err)
		}
		defer disksClient.Close()

		getDiskReq := &computepb.GetDiskRequest{
			Project: projectID,
			Zone:    zone,
			Disk:    diskName,
		}

		disk, err = disksClient.Get(ctx, getDiskReq)
		if err != nil {
			return fmt.Errorf("unable to get disk: %w", err)
		}
	} else {
		regionDisksClient, err := compute.NewRegionDisksRESTClient(ctx)
		if err != nil {
			return fmt.Errorf("NewRegionDisksRESTClient: %w", err)
		}
		defer regionDisksClient.Close()

		getDiskReq := &computepb.GetRegionDiskRequest{
			Project: projectID,
			Region:  region,
			Disk:    diskName,
		}

		disk, err = regionDisksClient.Get(ctx, getDiskReq)
		if err != nil {
			return fmt.Errorf("unable to get disk: %w", err)
		}
	}

	req := &computepb.InsertSnapshotRequest{
		Project: projectID,
		SnapshotResource: &computepb.Snapshot{
			Name:             proto.String(snapshotName),
			SourceDisk:       proto.String(disk.GetSelfLink()),
			StorageLocations: locations,
		},
	}

	op, err := snapshotsClient.Insert(ctx, req)
	if err != nil {
		return fmt.Errorf("unable to create snapshot: %w", err)
	}

	if err = op.Wait(ctx); err != nil {
		return fmt.Errorf("unable to wait for the operation: %w", err)
	}

	fmt.Fprintf(w, "Snapshot created\n")

	return nil
}

์ž๋ฐ”

Java

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Compute Engine ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Java ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Compute Engine Java API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Compute Engine์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.


import com.google.cloud.compute.v1.Disk;
import com.google.cloud.compute.v1.DisksClient;
import com.google.cloud.compute.v1.Operation;
import com.google.cloud.compute.v1.RegionDisksClient;
import com.google.cloud.compute.v1.Snapshot;
import com.google.cloud.compute.v1.SnapshotsClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateSnapshot {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    // You need to pass `zone` or `region` parameter relevant to the disk you want to
    // snapshot, but not both. Pass `zone` parameter for zonal disks and `region` for
    // regional disks.

    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";

    // Name of the disk you want to create.
    String diskName = "YOUR_DISK_NAME";

    // Name of the snapshot that you want to create.
    String snapshotName = "YOUR_SNAPSHOT_NAME";

    // The zone of the source disk from which you create the snapshot (for zonal disks).
    String zone = "europe-central2-b";

    // The region of the source disk from which you create the snapshot (for regional disks).
    String region = "your-disk-region";

    // The Cloud Storage multi-region or the Cloud Storage region where you
    // want to store your snapshot.
    // You can specify only one storage location. Available locations:
    // https://cloud.google.com/storage/docs/locations#available-locations
    String location = "europe-central2";

    // Project ID or project number of the Cloud project that
    // hosts the disk you want to snapshot. If not provided, the value will be defaulted
    // to 'projectId' value.
    String diskProjectId = "YOUR_DISK_PROJECT_ID";

    createSnapshot(projectId, diskName, snapshotName, zone, region, location, diskProjectId);
  }

  // Creates a snapshot of a disk.
  public static void createSnapshot(String projectId, String diskName, String snapshotName,
      String zone, String region, String location, String diskProjectId)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `snapshotsClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {

      if (zone.isEmpty() && region.isEmpty()) {
        throw new Error("You need to specify 'zone' or 'region' for this function to work");
      }

      if (!zone.isEmpty() && !region.isEmpty()) {
        throw new Error("You can't set both 'zone' and 'region' parameters");
      }

      // If Disk's project id is not specified, then the projectId parameter will be used.
      if (diskProjectId.isEmpty()) {
        diskProjectId = projectId;
      }

      // If zone is not empty, use the DisksClient to create a disk.
      // Else, use the RegionDisksClient.
      Disk disk;
      if (!zone.isEmpty()) {
        DisksClient disksClient = DisksClient.create();
        disk = disksClient.get(projectId, zone, diskName);
      } else {
        RegionDisksClient regionDisksClient = RegionDisksClient.create();
        disk = regionDisksClient.get(diskProjectId, region, diskName);
      }

      // Set the snapshot properties.
      Snapshot snapshotResource;
      if (!location.isEmpty()) {
        snapshotResource = Snapshot.newBuilder()
            .setName(snapshotName)
            .setSourceDisk(disk.getSelfLink())
            .addStorageLocations(location)
            .build();
      } else {
        snapshotResource = Snapshot.newBuilder()
            .setName(snapshotName)
            .setSourceDisk(disk.getSelfLink())
            .build();
      }

      // Wait for the operation to complete.
      Operation operation = snapshotsClient.insertAsync(projectId, snapshotResource)
          .get(3, TimeUnit.MINUTES);

      if (operation.hasError()) {
        System.out.println("Snapshot creation failed!" + operation);
        return;
      }

      // Retrieve the created snapshot.
      Snapshot snapshot = snapshotsClient.get(projectId, snapshotName);
      System.out.printf("Snapshot created: %s", snapshot.getName());

    }
  }
}

Node.js

Node.js

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Compute Engine ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Node.js ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Compute Engine Node.js API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Compute Engine์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const diskName = 'YOUR_DISK_NAME';
// const snapshotName = 'YOUR_SNAPSHOT_NAME';
// const zone = 'europe-central2-b';
// const region = '';
// const location = 'europe-central2';
// let diskProjectId = 'YOUR_DISK_PROJECT_ID';

const compute = require('@google-cloud/compute');

async function createSnapshot() {
  const snapshotsClient = new compute.SnapshotsClient();

  let disk;

  if (!zone && !region) {
    throw new Error(
      'You need to specify `zone` or `region` for this function to work.'
    );
  }

  if (zone && region) {
    throw new Error("You can't set both `zone` and `region` parameters");
  }

  if (!diskProjectId) {
    diskProjectId = projectId;
  }

  if (zone) {
    const disksClient = new compute.DisksClient();
    [disk] = await disksClient.get({
      project: diskProjectId,
      zone,
      disk: diskName,
    });
  } else {
    const regionDisksClient = new compute.RegionDisksClient();
    [disk] = await regionDisksClient.get({
      project: diskProjectId,
      region,
      disk: diskName,
    });
  }

  const snapshotResource = {
    name: snapshotName,
    sourceDisk: disk.selfLink,
  };

  if (location) {
    snapshotResource.storageLocations = [location];
  }

  const [response] = await snapshotsClient.insert({
    project: projectId,
    snapshotResource,
  });
  let operation = response.latestResponse;
  const operationsClient = new compute.GlobalOperationsClient();

  // Wait for the create snapshot operation to complete.
  while (operation.status !== 'DONE') {
    [operation] = await operationsClient.wait({
      operation: operation.name,
      project: projectId,
    });
  }

  console.log('Snapshot created.');
}

createSnapshot();

Python

Python

์ด ์ƒ˜ํ”Œ์„ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ ์ „์— Compute Engine ๋น ๋ฅธ ์‹œ์ž‘: ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ์˜ Python ์„ค์ • ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Compute Engine Python API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Compute Engine์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

from __future__ import annotations

import sys
from typing import Any

from google.api_core.extended_operation import ExtendedOperation
from google.cloud import compute_v1


def wait_for_extended_operation(
    operation: ExtendedOperation, verbose_name: str = "operation", timeout: int = 300
) -> Any:
    """
    Waits for the extended (long-running) operation to complete.

    If the operation is successful, it will return its result.
    If the operation ends with an error, an exception will be raised.
    If there were any warnings during the execution of the operation
    they will be printed to sys.stderr.

    Args:
        operation: a long-running operation you want to wait on.
        verbose_name: (optional) a more verbose name of the operation,
            used only during error and warning reporting.
        timeout: how long (in seconds) to wait for operation to finish.
            If None, wait indefinitely.

    Returns:
        Whatever the operation.result() returns.

    Raises:
        This method will raise the exception received from `operation.exception()`
        or RuntimeError if there is no exception set, but there is an `error_code`
        set for the `operation`.

        In case of an operation taking longer than `timeout` seconds to complete,
        a `concurrent.futures.TimeoutError` will be raised.
    """
    result = operation.result(timeout=timeout)

    if operation.error_code:
        print(
            f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
            file=sys.stderr,
            flush=True,
        )
        print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
        raise operation.exception() or RuntimeError(operation.error_message)

    if operation.warnings:
        print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
        for warning in operation.warnings:
            print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)

    return result


def create_snapshot(
    project_id: str,
    disk_name: str,
    snapshot_name: str,
    *,
    zone: str | None = None,
    region: str | None = None,
    location: str | None = None,
    disk_project_id: str | None = None,
) -> compute_v1.Snapshot:
    """
    Create a snapshot of a disk.

    You need to pass `zone` or `region` parameter relevant to the disk you want to
    snapshot, but not both. Pass `zone` parameter for zonal disks and `region` for
    regional disks.

    Args:
        project_id: project ID or project number of the Cloud project you want
            to use to store the snapshot.
        disk_name: name of the disk you want to snapshot.
        snapshot_name: name of the snapshot to be created.
        zone: name of the zone in which is the disk you want to snapshot (for zonal disks).
        region: name of the region in which is the disk you want to snapshot (for regional disks).
        location: The Cloud Storage multi-region or the Cloud Storage region where you
            want to store your snapshot.
            You can specify only one storage location. Available locations:
            https://cloud.google.com/storage/docs/locations#available-locations
        disk_project_id: project ID or project number of the Cloud project that
            hosts the disk you want to snapshot. If not provided, will look for
            the disk in the `project_id` project.

    Returns:
        The new snapshot instance.
    """
    if zone is None and region is None:
        raise RuntimeError(
            "You need to specify `zone` or `region` for this function to work."
        )
    if zone is not None and region is not None:
        raise RuntimeError("You can't set both `zone` and `region` parameters.")

    if disk_project_id is None:
        disk_project_id = project_id

    if zone is not None:
        disk_client = compute_v1.DisksClient()
        disk = disk_client.get(project=disk_project_id, zone=zone, disk=disk_name)
    else:
        regio_disk_client = compute_v1.RegionDisksClient()
        disk = regio_disk_client.get(
            project=disk_project_id, region=region, disk=disk_name
        )

    snapshot = compute_v1.Snapshot()
    snapshot.source_disk = disk.self_link
    snapshot.name = snapshot_name
    if location:
        snapshot.storage_locations = [location]

    snapshot_client = compute_v1.SnapshotsClient()
    operation = snapshot_client.insert(project=project_id, snapshot_resource=snapshot)

    wait_for_extended_operation(operation, "snapshot creation")

    return snapshot_client.get(project=project_id, snapshot=snapshot_name)

REST

์†Œ์Šค ๋””์Šคํฌ์˜ ๋ฐ์ดํ„ฐ ๋˜๋Š” ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋””์Šคํฌ ๋ฐ์ดํ„ฐ

์Šค๋ƒ…์ƒท ์„ค์ •์— ์ •์˜๋œ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์ •์ฑ… ๋˜๋Š” ์ž์‹ ์ด ์„ ํƒํ•œ ๋‹ค๋ฅธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์‚ฌ์šฉํ•ด ๋””์Šคํฌ์˜ ๋ฐ์ดํ„ฐ์—์„œ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์Šค๋ƒ…์ƒท ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜ ์„ ํƒ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

  • ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค์„ค์ •๋œ ๊ธฐ๋ณธ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด snapshots.insert ๋ฉ”์„œ๋“œ์— POST ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•˜์„ธ์š”.

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    {
      "name": "SNAPSHOT_NAME",
      "sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME",
      "snapshotType": "SNAPSHOT_TYPE"
    }
    
  • ๋˜๋Š” ์Šค๋ƒ…์ƒท ์„ค์ •์„ ์žฌ์ •์˜ํ•˜๊ณ  ์ปค์Šคํ…€ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜์— ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด snapshots.insert ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด POST ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์š”์ฒญ์— storageLocations ์†์„ฑ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    {
      "name": "SNAPSHOT_NAME",
      "sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME",
      "snapshotType": "SNAPSHOT_TYPE",
      "storageLocations": [
          "STORAGE_LOCATION"
      ],
    }
    
  • (๋ฏธ๋ฆฌ๋ณด๊ธฐ) ํ—ˆ์šฉ๋œ ๋ฆฌ์ „์—์„œ ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด snapshots.insert ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด POST ์š”์ฒญ์„ ์‹คํ–‰ํ•˜๊ณ  ์ƒ์„ฑ ๋ฆฌ์ „์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

    POST https://compute.googleapis.com/compute/beta/projects/DESTINATION_PROJECT_ID/regions/SNAPSHOT_SCOPE_REGION/snapshots
    {
      "name": "SNAPSHOT_NAME",
      "sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME",
      "snapshotType": "SNAPSHOT_TYPE",
    }
    

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • DESTINATION_PROJECT_ID: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” ํ”„๋กœ์ ํŠธ์˜ ID์ž…๋‹ˆ๋‹ค.
  • SNAPSHOT_NAME: ์Šค๋ƒ…์ƒท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SOURCE_PROJECT_ID: ์†Œ์Šค ๋””์Šคํฌ ํ”„๋กœ์ ํŠธ์˜ ID์ž…๋‹ˆ๋‹ค.
  • SOURCE_REGION: ์†Œ์Šค ๋””์Šคํฌ์˜ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค.
  • SOURCE_DISK_NAME: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” ๋ฆฌ์ „ Persistent Disk ๋˜๋Š” Hyperdisk Balanced ๊ณ ๊ฐ€์šฉ์„ฑ ๋ณผ๋ฅจ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SNAPSHOT_TYPE: ์Šค๋ƒ…์ƒท ์œ ํ˜•์ž…๋‹ˆ๋‹ค(STANDARD ๋˜๋Š” ARCHIVE). ์Šค๋ƒ…์ƒท ์œ ํ˜•์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด STANDARD ์Šค๋ƒ…์ƒท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • STORAGE_LOCATION: (์„ ํƒ์‚ฌํ•ญ) ์ „์—ญ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ฒฝ์šฐ ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•  Cloud Storage ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ๋˜๋Š” Cloud Storage ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋Š” ํ•˜๋‚˜๋งŒ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค ์„ค์ •๋œ ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ์žฌ์ •์˜ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ์—๋งŒ storageLocations ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • SNAPSHOT_SCOPE_REGION: (์„ ํƒ์‚ฌํ•ญ) ๋ฆฌ์ „ ๋ฒ”์œ„ ์Šค๋ƒ…์ƒท์˜ ๊ฒฝ์šฐ ์Šค๋ƒ…์ƒท ๋ฒ”์œ„๊ฐ€ ์ง€์ •๋œ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํฌํ•จํ•˜๋ฉด storageLocations ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. STORAGE_LOCATION์€ SNAPSHOT_SCOPE_REGION์œผ๋กœ ์ž๋™ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.

์ฒดํฌํฌ์ธํŠธ

๋˜๋Š” ์„ฑ๋Šฅ ์ €ํ•˜๋œ ๋””์Šคํฌ์˜ ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ถˆ์™„์ „ํ•œ ๋ณต์ œ๋ณธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ•œ ์Šค๋ƒ…์ƒท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋ฉด snapshots.insert ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด POST ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. sourceDisk ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ œ์™ธํ•˜๊ณ  ๋Œ€์‹  sourceDiskForRecoveryCheckpoint ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ํฌํ•จํ•ด์„œ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋„๋ก ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots

{
  "name": "SNAPSHOT_NAME",
  "sourceDiskForRecoveryCheckpoint": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME",
  "storageLocations": "STORAGE_LOCATION",
  "snapshotType": "SNAPSHOT_TYPE"
}

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • DESTINATION_PROJECT_ID: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๋Š” ํ”„๋กœ์ ํŠธ์˜ ID์ž…๋‹ˆ๋‹ค.
  • SNAPSHOT_NAME: ์Šค๋ƒ…์ƒท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • SOURCE_PROJECT_ID: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์†Œ์Šค ๋””์Šคํฌ์˜ ํ”„๋กœ์ ํŠธ ID์ž…๋‹ˆ๋‹ค.
  • SOURCE_REGION: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์†Œ์Šค ๋””์Šคํฌ์˜ ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค.
  • SOURCE_DISK_NAME: ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์†Œ์Šค ๋””์Šคํฌ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • STORAGE_LOCATION: (์„ ํƒ์‚ฌํ•ญ) ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•  Cloud Storage ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ๋˜๋Š” Cloud Storage ๋ฆฌ์ „์ž…๋‹ˆ๋‹ค. ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋Š” ํ•˜๋‚˜๋งŒ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ์Šค๋ƒ…์ƒท ์„ค์ •์— ๊ตฌ์„ฑ๋œ ์‚ฌ์ „ ์ •์˜๋˜์—ˆ๊ฑฐ๋‚˜ ๋งž์ถค ์„ค์ •๋œ ๊ธฐ๋ณธ ์Šคํ† ๋ฆฌ์ง€ ์œ„์น˜๋ฅผ ๋ฌดํšจํ™”ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ์—๋งŒ storageLocations ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • SNAPSHOT_TYPE: ์Šค๋ƒ…์ƒท ์œ ํ˜•์ž…๋‹ˆ๋‹ค(STANDARD ๋˜๋Š” ARCHIVE). ์Šค๋ƒ…์ƒท ์œ ํ˜•์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด STANDARD ์Šค๋ƒ…์ƒท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ฑ๋Šฅ ์ €ํ•˜๋œ ๋””์Šคํฌ์—์„œ๋งŒ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ๊ธฐ๊ฐ€ ์™„์ „ํžˆ ๋ณต์ œ๋˜์—ˆ์„ ๋•Œ ๋ณต์ œ๋ณธ ๋ณต๊ตฌ ์ฒดํฌํฌ์ธํŠธ์—์„œ ์Šค๋ƒ…์ƒท์„ ๋งŒ๋“ค๋ ค๊ณ  ์‹œ๋„ํ•˜๋ฉด ๋‹ค์Œ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

The device is fully replicated and should not create snapshots out of a recovery checkpoint. Please
create regular snapshots instead.

๋‹ค์Œ ๋‹จ๊ณ„