Download all files from a Google Cloud Storage bucket (in OSX)

To download all files from a Google Cloud Storage bucket (if you are using Google Cloud services like App Engine etc) is actually quite easy but you’ll need to use gsutil to do it. See the docs at https://cloud.google.com/storage/docs/gsutil. You will need the Google Cloud SDK installed so you can run “gcloud”.

I’m using OSX and did the following:

Download gsutil fromĀ https://storage.googleapis.com/pub/gsutil.tar.gz

Extract to your home directory:

tar xfz gsutil.tar.gz -C $HOME

Go to $HOME/gsutil and check the version, it may ask if you want to update Google Cloud components:

gsutil version -l

If you need to, update Google Cloud components:

gcloud components update

Authenticate with your Google Cloud account:

gcloud auth login

Set the correct project (in this case “project101″):

gcloud config set project project101

Copy everything recursively from the bucket “bucketname” to the directory “bucketname”:

gsutil -m cp -R gs://bucketname

Done!

Find and Kill HTTP Server Process Running on Port 80 or 8080 in Apple Mac OSX

I’m using a Mac to do Java development and occasionally need to kill the process running my development HTTP server on port 8080. It’s only 2 commands in the terminal.

Find the process running the HTTP server on port 8080:

lsof -n -i4TCP:8080 | grep LISTEN

Which returns something like:

java 554 myusername 62u IPv6 0xe02c342ea983a2b1 0t0 TCP *:http-alt (LISTEN)

The process ID is the second column (554 in this case), so kill the running HTTP server with:

kill 554

Compare Two MySQL Database Structures Using mysqldump and diff

To compare two mysql databases in linux/osx you can use a very simple script that calls the “mysqldump” and “diff” commands to output the difference in structure of two databases to an output file. In this case I was comparing my local database with another at IP address 1.2.3.4. You will be prompted for passwords but to avoid this you can add “-pYOURPASSWORD” (less secure):

mysqldump --no-data --skip-comments --skip-extended-insert --host=127.0.0.1 -u root -p DATABASENAME>file1.sql
mysqldump --no-data --skip-comments --skip-extended-insert --host=1.2.3.4 -u root -p DATABASENAME>file2.sql
diff file1.sql file2.sql > diffoutput.txt
rm -f file1.sql
rm -f file2.sql