• Skip to main content

Uly.me

cloud engineer

  • Home
  • Archives
  • Search

GCP Backup Instance

April 3, 2022 by Ulysses

Here’s the script to backup GCP disks.

#!/bin/bash
now=$(date +%s)
disks=$(gcloud compute disks list --project project-id --filter="users:instance" --format="value(name)")
for disk in $disks
do
  gcloud compute disks snapshot $disk \
  --snapshot-names=$disk-$now \
  --zone=us-central1-a \
  --project=project-id \
  --async
done

#!/bin/bash now=$(date +%s) disks=$(gcloud compute disks list --project project-id --filter="users:instance" --format="value(name)") for disk in $disks do gcloud compute disks snapshot $disk \ --snapshot-names=$disk-$now \ --zone=us-central1-a \ --project=project-id \ --async done

Filed Under: Cloud, Linux Tagged With: backup, disks, gcp, manual, snapshots

Vi Search and Replace

April 3, 2022 by Ulysses

How to do search and replace in Vim.

Search for “foo” and replace it with “bar” in the current line. Use :s

:s/foo/bar/g

:s/foo/bar/g

Search for “foo” and replace it with “bar” in the entire document. Use :%s

:%s/foo/bar/g

:%s/foo/bar/g

You can also pipe instead of forward slash. Useful if your search contains a /.

:%s|foo/|bar|g

:%s|foo/|bar|g

Filed Under: Linux Tagged With: entire, file, replace, search, vim

Redhat 8 Network Manager

March 10, 2022 by Ulysses

In Redhat 8, every time you the Network Manager get’s restarted it overwrites /etc/resolv.conf. To prevent that from hapenning, create a new file called /etc/NetworkManager/conf.d/90-dns-none.conf and add the following lines. Restart Network Manager. Your /etc/resolv.conf should be unchanged.

[main]
dns=none

[main] dns=none

Restart Network Manager

$ systemctl reload NetworkManager

$ systemctl reload NetworkManager

Filed Under: Linux Tagged With: network manager, overwrite, prevent, redhat 8, resolv.conf

GCP Project Quotas

March 8, 2022 by Ulysses

Here’s how to get your project quotas in GCP.

gcloud compute project-info describe --project your-project-id

gcloud compute project-info describe --project your-project-id

Filed Under: Cloud Tagged With: gcloud, gcp, project, quotas

GCP Regional Quotas

March 8, 2022 by Ulysses

Here’s how to get Regional Quotas for your project in GCP.

gcloud compute regions describe us-central1 --project your-project-id

gcloud compute regions describe us-central1 --project your-project-id

Filed Under: Cloud Tagged With: gcloud, gcp, project, quotas, regional

Windows Check If Port is Listening

March 3, 2022 by Ulysses

Here’s how to check if port is listening on a Windows Server.

Log in to the destination server.

netstat -ano | find "443" | find "LISTEN"
tasklist /fi "PID eq "443"

netstat -ano | find "443" | find "LISTEN" tasklist /fi "PID eq "443"

Filed Under: Misc Tagged With: check, listening, netstat, port, tasklist, windows

Python Boto3 S3 List Objects

February 27, 2022 by Ulysses

How to list S3 objects using Python Boto3

import boto3
from sys import argv
bucket=argv[1]
s3 = boto3.resource('s3')
mybucket = s3.Bucket(bucket)
def list_buckets():
    print("List of Buckets: ")
    for bucket in s3.buckets.all():
        print(bucket.name)
def list_files():
    print("Buckets: The objects in the \"" + bucket + "\" buckets are ... ")
    for files in mybucket.objects.all():
        print(files.key)
def main():
    #list_buckets()
    list_files()
if __name__ == "__main__":
    main()

import boto3 from sys import argv bucket=argv[1] s3 = boto3.resource('s3') mybucket = s3.Bucket(bucket) def list_buckets(): print("List of Buckets: ") for bucket in s3.buckets.all(): print(bucket.name) def list_files(): print("Buckets: The objects in the \"" + bucket + "\" buckets are ... ") for files in mybucket.objects.all(): print(files.key) def main(): #list_buckets() list_files() if __name__ == "__main__": main()

Running command

$ python test.py bucket-name    # with python
$ ./test.py bucket-name         # without python

$ python test.py bucket-name # with python $ ./test.py bucket-name # without python

Results

Buckets: The objects in the "bucket-name" are ....
abc.txt
def.txt

Buckets: The objects in the "bucket-name" are .... abc.txt def.txt

Filed Under: Linux Tagged With: boto3, list, objects, python, s3

Python Virtual Environment

February 27, 2022 by Ulysses

How to create a Python virtual environment.

On Windows

$ pip install venv
$ python3 -m venv ~/python-test

$ pip install venv $ python3 -m venv ~/python-test

On Ubuntu

$ sudo apt install python3.8-venv
$ python3 -m venv ~/python-test

$ sudo apt install python3.8-venv $ python3 -m venv ~/python-test

On Mac OS

$ brew install virtualenv
$ virtualenv python-test

$ brew install virtualenv $ virtualenv python-test

Activate

$ cd ~/python-test
$ source bin/activate

$ cd ~/python-test $ source bin/activate

Deactivate

$ deactivate

$ deactivate

Filed Under: Linux Tagged With: activate, deactivate, environment, python, virtual

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Interim pages omitted …
  • Go to page 119
  • Go to Next Page »
  • Home
  • About
  • Contact

Copyright © 2022