coding-to-music / coding-to-music.github.io

https://pandemic-overview.readthedocs.io/en/latest/index.html
MIT License
2 stars 8 forks source link

DigitalOcean : Create Droplet from snapshot using doctl command line CLI – Here are the steps to do it #154

Open coding-to-music opened 3 years ago

coding-to-music commented 3 years ago

DigitalOcean : Create Droplet from snapshot using doctl command line CLI – Here are the steps to do it

https://bobcares.com/blog/digitalocean-create-droplet-from-snapshot/

DigitalOcean : Create Droplet from Snapshot – 2 important steps

Here are 2 important steps to create a DigitalOcean Droplet from a snapshot.

1) Take a Droplet snapshot

Firstly, our Support Engineers create a snapshot of the existing Droplet to save all the current contents of the Droplet.

If you already have a working snapshot, skip this step.

This involves 2 steps.

a) Power off the Droplet We always power off the Droplet before taking the snapshot to avoid data inconsistency.

For instance, when taking a snapshot on a running Droplet, databases don’t guarantee consistent data.

That is, it takes a while to copy a file and the files may change as you copy them, so your backup file become an inconsistent snapshot.

So, as a precaution, we always poweroff the Droplet before taking the snapshot.

Users can poweroff the Droplet from Power >> Poweroff option in the DigitalOcean control panel.

However, we always poweroff the server via SSH, because this ensures that all the services are stopped before the server is shutdown.

For instance, we use the below command to shutdown the server from command line.

shutdown -h now

b) Take a snapshot of the Droplet The next step is to take the Droplet snapshot.

Our Support Engineers usually take the snapshot from Snapshots > Take Snapshot option in DigitalOcean control panel.

digitalocean create droplet from snapshot How to take snapshot from DigitalOcean panel?

Alternatively, in some cases, we have to take the snapshot of a running Droplet.

In such cases, we take the snapshot from Snapshots > Take Snapshot > Take live Snapshot in DigitalOcean control panel.

2) Create a new Droplet from snapshot

The second step is to create a new Droplet from the snapshot.

Our Support Engineers follow the below steps to create a new droplet from the snapshot.

Click Create > Droplets. Click on Snapshots. Select the snapshot. Select the size, Droplet region and additional parameters. Click on Create.

Alternatively, when we need to create multiple Droplets from the snapshot, we use the command line utility to speed up the process.

For that, we use the DigitalOcean doctl command line client. It uses the DigitaOcean API to access Droplet features.

For instance, we use the below command to create a Droplet from snapshot.

doctl compute droplet create testserver --size 1gb --image debian-8-x64 --region nyc1

Here testserver is the Droplet name, Droplet size is 1GB, snapshot name is debian-8-x64 and Droplet region is nyc1.

coding-to-music commented 3 years ago

Create droplets from image: Common failure points

Most importantly, when creating a new Droplet from snapshot, we ensure that the disk space of the new Droplet is equal to or larger than the Droplet used in snapshot.

This ensures that there is no loss of data during this process.

Also, when a new Droplet is created, it transfers all SSH keys and user accounts from the time the snapshot was created.

Once we create the new Droplet from the snapshot, we always test the services on the new instance as there may be chances that some services will not set to start at boot.

DigitalOcean : Create Droplet from Snapshot – Common failure points

Although creating Droplet from snapshot is a pretty straight forward process, we’ve seen that this can sometimes fail.

Let’s discuss some common scenarios here.

1) Create Droplet from snapshot in different region

We’ve seen customers complain that they get the below error when creating a Droplet from a snapshot in a different region.

The image you specified is not available in the selected region, you can make it globally available by initiating an image region transfer from the images tab.

In order to create a Droplet from a snapshot taken in another datacenter, this snapshot should be transferred to the region where the new Droplet should be created.

Our Support Engineers transfer the snapshot to other regions from Snapshots > Droplet snapshots > More > Add to region > Click on region name. to fix this issue.

2) Create Droplet from command line

Droplet owners usually create Droplets from command line using the snapshots with image slug (for example, centos-6-5-x32, centos-6-5-x64, etc).

However, in some cases, the snapshots don’t come up with a slug to uniquely identify it.

So, in such cases, our Support Engineers get the unique image ID and use it for Droplet creation.

For instance, to create a new Droplet from an image, we first get the unique image ID using the below command.

doctl compute image list-user

After that, we create a new Droplet from the image with this image ID.

doctl compute droplet create testserver --size 1gb --image imageID --region nyc1

Replace imageID with the unique image ID.

Conclusion

In short, create DigitalOcean Droplet from snapshot is useful when there is unexpected server crashes, migration to a new location, and more. Today, we’ve discussed the steps to create a DigitaOcean Droplet from snapshot and the common failure points