Skip to content

Instantly share code, notes, and snippets.

Avatar
💤
Thinking ...

Ananda Dwi Ae misskecupbung

💤
Thinking ...
View GitHub Profile
View stopec2instance.py
import boto3
def GetInstanceRunning():
client = boto3.client('ec2')
ec2_regions = [region['RegionName'] for region in client.describe_regions()['Regions']]
for region in ec2_regions:
ec2 = boto3.resource('ec2')
instances = ec2.instances.filter(Filters=[{'Name': 'instance-state-name', 'Values': ['running']}])
return [instance.id for instance in instances]
View velero-restore
BACKUP_NAME = wp-backup
velero restore create --from-backup $BACKUP_NAME
View velero-backup-ns-wordpress
velero backup create wp-backup --include-namespace wordpress
velero backup get
velero backup describe wp-backup
View velero-install-1
velero install --provider gcp --plugins velero/velero-plugin-for-gcp:v1.5.0 --bucket velero-backup --secret-file ./credentials-velero --use-volume-snapshots=true
View velero-install
wget -c https://github.com/vmware-tanzu/velero/releases/download/v1.9.2/<RELEASE-TARBALL-NAME>.tar.gz
tar -xvf <RELEASE-TARBALL-NAME>.tar.gz
sudo cp <RELEASE-TARBALL-NAME>/velero /usr/bin/
View velero-create-sa
gcloud iam service-accounts create velero-backup-anandadwi --display-name "Velero SA"
SERVICE_ACCOUNT_EMAIL=$(gcloud iam service-accounts list --filter="displayName:Velero SA" --format 'value(email)')
gcloud iam service-accounts list
ROLE_PERMISSIONS=(
compute.disks.get
compute.disks.create
compute.disks.createSnapshot
compute.snapshots.get
compute.snapshots.create
View create-bucket-cloudstorage-gcp
BUCKET=velero-backup-anandadwi
gsutil mb gs://$BUCKET/
# verify
gsutil ls
View restore-gke
export RESTORE="manual-restore1"
gcloud alpha container backup-restore restores create $RESTORE \
--project=$PROJECT_ID \
--location=$GCP_REGION \
--restore-plan=$RESTORE_PLAN \
--backup=projects/$PROJECT_ID/locations/$LOCATION/backupPlans/$BACKUP_PLAN/backups/$BACKUP \
--wait-for-completion
View export-vars-backup-gke
export RESTORE_LOCATION="us-central1"
export RESTORE_PLAN="gke-central1-b-restore"
export CLUSTER2="projects/$PROJECT_ID/locations/$GCP_REGION/clusters/$CLUSTER_NAME2"
export CLUSTER_RESOURCE_CONFLICT_POLICY="use-backup-version"
export NAMESPACED_RESOURCE_RESTORE_MODE="delete-and-restore"
export VOLUME_DATA_RESTORE_POLICY="restore-volume-data-from-backup"
View create-new-cluster-gke-2
export CLUSTER_NAME2="gke-central1-b"
gcloud beta container clusters create $CLUSTER_NAME2 \
--project=$PROJECT_ID \
--region=$LOCATION \
--addons=BackupRestore \
--num-nodes=1 \
--enable-autoupgrade --no-enable-basic-auth \
--no-issue-client-certificate --enable-ip-alias \
--metadata disable-legacy-endpoints=true \
--workload-pool=$IDNS