• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

snapshot

AWS CLI Lightsail

May 19, 2019

Get instance details

aws lightsail get-instance --instance-name your-server

aws lightsail get-instance --instance-name your-server

Get instance state

aws lightsail get-instance-state --instance-name your-server

aws lightsail get-instance-state --instance-name your-server

Create a snapshot

aws lightsail create-instance-snapshot \
--instance-snapshot-name your-server-new-snapshot-201905192200 \
--instance-name your-server

aws lightsail create-instance-snapshot \ --instance-snapshot-name your-server-new-snapshot-201905192200 \ --instance-name your-server

Create disk from snapshot

aws lightsail create-disk-from-snapshot \
--disk-name your-server-new-boot-disk \
--disk-name your-server-new-snapshot-201905192200 \
--availability-zone us-east-1a
--size-in-gb 50

aws lightsail create-disk-from-snapshot \ --disk-name your-server-new-boot-disk \ --disk-name your-server-new-snapshot-201905192200 \ --availability-zone us-east-1a --size-in-gb 50

Attach Disk

aws lightsail attach-disk \
--disk-name your-server-new-boot-disk \
--instance-name your-server \
--disk-path /dev/sda1

aws lightsail attach-disk \ --disk-name your-server-new-boot-disk \ --instance-name your-server \ --disk-path /dev/sda1

Create instance from snapshot

aws lightsail create-instance-snapshot \
--instance-snaphot-name your-server-new-snapshot-201905192200
--instance-name your-server

aws lightsail create-instance-snapshot \ --instance-snaphot-name your-server-new-snapshot-201905192200 --instance-name your-server

Attach Static IP Address

aws lightsail attach-static-ip \
--static-ip-name your-ip-name \
--instance-name your-server

aws lightsail attach-static-ip \ --static-ip-name your-ip-name \ --instance-name your-server

Filed Under: Cloud, Linux Tagged With: attach, aws, cli, instance, lightsail, snapshot, static ip

GCP Create Images

May 12, 2019

Here’s how to create a GCP Disk Image from a Boot Drive.

  • First, stop the instance.
  • If you can’t, stop the applications/database from writing to disks.
  • Run sudo sync .

Create From Disk

gcloud compute images create the-new-image-name \
   --source-disk the-source-boot-disk \
   --source-disk-zone us-central1-a \
   --family the-image-family \
   [--force]

gcloud compute images create the-new-image-name \ --source-disk the-source-boot-disk \ --source-disk-zone us-central1-a \ --family the-image-family \ [--force]

Create From Image

gcloud compute images create the-new-image-name \
  --source-image the-source-image \
  --source-image-project the-project-where-the-image-is-located \
  --family the-image-family

gcloud compute images create the-new-image-name \ --source-image the-source-image \ --source-image-project the-project-where-the-image-is-located \ --family the-image-family

Create From Snapshot

gcloud compute images create the-new-image-name \
  --source-snapshot the-source-snapshot

gcloud compute images create the-new-image-name \ --source-snapshot the-source-snapshot

For more info.

Filed Under: Cloud, Linux Tagged With: cli, disk, gcp, image, snapshot

GCP Create Disk from Snapshot

May 1, 2019

Here’s how to create a disk from a snapshot via Google SDK.

gcloud compute disks create new-server-disk-2 \
--project=project-name \
--source-snapshot=server-disk-2 \
--zone=us-central1-b

gcloud compute disks create new-server-disk-2 \ --project=project-name \ --source-snapshot=server-disk-2 \ --zone=us-central1-b

Filed Under: Linux Tagged With: disk, gcp, sdk, snapshot

Encrypt Volume via Terraform

April 9, 2019

Here’s the Terraform script to encrypt an unencrypted volume. It creates a snapshot, encrypts a snapshot, and encrypts the volume.

#
# Set Variables
#
variable "volume" {
  description = "The Volume to encrypt: vol-12345678901234567"
}
variable "region" {
  description = "The Region: us-east-2"
}
variable "az" {
  description = "The AZ: us-east-2a"
}
 
#
# Set Credentials
#
provider "aws" {
	access_key = "put-your-access-key-here"
	secret_key = "put-your-secret-key-here"
	region = "${var.region}"
}
 
/*
#
# Create Unencrypted Volume
#
resource "aws_ebs_volume" "unencrypted_volume" {
  availability_zone = "${var.az}"
  size              = 10
  tags = {
    Name = "Unencrypted_Volume"
  }
}
*/
 
#
# Create Unencrypted Snapshot
#
resource "aws_ebs_snapshot" "unencrypted_snapshot" {
  #volume_id = "${aws_ebs_volume.unencrypted_volume.id}"
  volume_id = "${var.volume}"
  tags = {
    Name = "Unencrypted_Snapshot"
  }
}
 
#
# Create Encrypted Snapshot
#
resource "aws_ebs_snapshot_copy" "encrypted_snapshot" {
  source_snapshot_id = "${aws_ebs_snapshot.unencrypted_snapshot.id}"
  source_region      = "${var.region}"
  encrypted = true
  tags = {
    Name = "Encrypted_Snapshot"
  }
}
 
#
# Created Encrypted Volume
#
resource "aws_ebs_volume" "encrypted_volume" {
  availability_zone = "${var.az}"
  snapshot_id = "${aws_ebs_snapshot_copy.encrypted_snapshot.id}"
  tags = {
    Name = "Encrypted_Volume"
  }
}

# # Set Variables # variable "volume" { description = "The Volume to encrypt: vol-12345678901234567" } variable "region" { description = "The Region: us-east-2" } variable "az" { description = "The AZ: us-east-2a" } # # Set Credentials # provider "aws" { access_key = "put-your-access-key-here" secret_key = "put-your-secret-key-here" region = "${var.region}" } /* # # Create Unencrypted Volume # resource "aws_ebs_volume" "unencrypted_volume" { availability_zone = "${var.az}" size = 10 tags = { Name = "Unencrypted_Volume" } } */ # # Create Unencrypted Snapshot # resource "aws_ebs_snapshot" "unencrypted_snapshot" { #volume_id = "${aws_ebs_volume.unencrypted_volume.id}" volume_id = "${var.volume}" tags = { Name = "Unencrypted_Snapshot" } } # # Create Encrypted Snapshot # resource "aws_ebs_snapshot_copy" "encrypted_snapshot" { source_snapshot_id = "${aws_ebs_snapshot.unencrypted_snapshot.id}" source_region = "${var.region}" encrypted = true tags = { Name = "Encrypted_Snapshot" } } # # Created Encrypted Volume # resource "aws_ebs_volume" "encrypted_volume" { availability_zone = "${var.az}" snapshot_id = "${aws_ebs_snapshot_copy.encrypted_snapshot.id}" tags = { Name = "Encrypted_Volume" } }

Filed Under: Linux Tagged With: encrypt, snapshot, terraform, volume

Steps to Encrypt Volumes

March 18, 2019

Here the steps to encrypt an unencrypted volume.

  1. Take a snapshot of the unencrypted volume.
  2. Make a copy of that snapshot and turn on encryption.
  3. Create a volume of the encrypted snapshot.
  4. Stop the instance.
  5. Detach the original unencrypted volume from the instance.
  6. Attach the newly created encrypted volume to the instance.
  7. Start the instance.

AWS CLI

# CREATE A SNAPSHOT
aws ec2 create-snapshot \
--volume-id vol-1234567890abcdef0 \
--description "This is my snapshot"
 
# COPY SNAPSHOT
aws ec2 copy-snapshot \
--source-region us-west-2 --source-snapshot-id snap-066877671789bd71b \
--region us-east-1 --description "This is my copied snapshot."
 
# CREATE A VOLUME
aws ec2 create-volume \
--region us-east-1 --availability-zone us-east-1a \
--snapshot-id snap-066877671789bd71b --volume-type io1 --iops 1000
 
# STOP AN INSTANCE
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
 
# DETACH A VOLUME
aws ec2 detach-volume --volume-id vol-1234567890abcdef0
 
# ATTACH A VOLUME
aws ec2 attach-volume --volume-id vol-1234567890abcdef0 \
--instance-id i-01474ef662b89480 --device /dev/sdf
 
# START AN INSTANCE
aws ec2 start-instances --instance-ids i-1234567890abcdef0

# CREATE A SNAPSHOT aws ec2 create-snapshot \ --volume-id vol-1234567890abcdef0 \ --description "This is my snapshot" # COPY SNAPSHOT aws ec2 copy-snapshot \ --source-region us-west-2 --source-snapshot-id snap-066877671789bd71b \ --region us-east-1 --description "This is my copied snapshot." # CREATE A VOLUME aws ec2 create-volume \ --region us-east-1 --availability-zone us-east-1a \ --snapshot-id snap-066877671789bd71b --volume-type io1 --iops 1000 # STOP AN INSTANCE aws ec2 stop-instances --instance-ids i-1234567890abcdef0 # DETACH A VOLUME aws ec2 detach-volume --volume-id vol-1234567890abcdef0 # ATTACH A VOLUME aws ec2 attach-volume --volume-id vol-1234567890abcdef0 \ --instance-id i-01474ef662b89480 --device /dev/sdf # START AN INSTANCE aws ec2 start-instances --instance-ids i-1234567890abcdef0

Filed Under: Cloud, Linux Tagged With: encrypted, instance, snapshot, unencrypted, volumes

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to Next Page »
  • Home
  • About
  • Search

Copyright © 2023