From dd8edbd078dc93848ea73ce863af124e6c97104a Mon Sep 17 00:00:00 2001 From: Timothy Middelkoop Date: Mon, 13 Dec 2021 15:46:20 +0000 Subject: [PATCH] Cleanup buckets --- content/GCP/06_running_analysis.ipynb | 2 +- content/GCP/08_cleaning_up_resources.ipynb | 126 +++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/content/GCP/06_running_analysis.ipynb b/content/GCP/06_running_analysis.ipynb index 654a9cf..6a78156 100644 --- a/content/GCP/06_running_analysis.ipynb +++ b/content/GCP/06_running_analysis.ipynb @@ -617,7 +617,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 4, "id": "f36cb8c5-f305-4cb2-a5cc-0c9fd8592fb4", "metadata": {}, "outputs": [ diff --git a/content/GCP/08_cleaning_up_resources.ipynb b/content/GCP/08_cleaning_up_resources.ipynb index 9f476a5..ba4d367 100644 --- a/content/GCP/08_cleaning_up_resources.ipynb +++ b/content/GCP/08_cleaning_up_resources.ipynb @@ -22,6 +22,132 @@ "\n", "```" ] + }, + { + "cell_type": "markdown", + "id": "d43bd86d-acf7-416a-9b35-506f5625f2c3", + "metadata": {}, + "source": [ + "## Cleanup Buckets\n", + "\n", + "This Episode is used to cleanup resources created by the Lesson. Note, this will clean buckets created on any day.\n", + "\n", + "First set the environment variables and verify them. If they are previously set you can just verify them." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "86c5804d-b8ae-49d8-b67c-61360a922590", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Account: 1002111293252-compute@developer.gserviceaccount.com, Project: just-armor-301114, Region: us-west2\n", + "Bucket: essentials-learner-*\n" + ] + } + ], + "source": [ + "ACCOUNT=$(gcloud config list --format='value(core.account)')\n", + "PROJECT=$(gcloud config list --format='value(core.project)')\n", + "BUCKET=\"essentials-${USER}-*\"\n", + "REGION=\"us-west2\"\n", + "echo \"Account: $ACCOUNT, Project: $PROJECT, Region: $REGION\"\n", + "echo \"Bucket: $BUCKET\"" + ] + }, + { + "cell_type": "markdown", + "id": "218cc720-bf36-49a4-b98a-11024f5b391c", + "metadata": {}, + "source": [ + "List the buckets we will be deleting." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "93add660-5bdb-4393-a05a-031ec301d7f8", + "metadata": {}, + "outputs": [], + "source": [ + "gsutil ls -b \"gs://$BUCKET\"" + ] + }, + { + "cell_type": "markdown", + "id": "8daa2ec9-d64d-4586-8ab9-33f03c1b1138", + "metadata": {}, + "source": [ + "**WARNING: All of the above buckets will be deleted if the following commands are run**" + ] + }, + { + "cell_type": "markdown", + "id": "be020ee5-d3af-4ada-a674-51775648f373", + "metadata": {}, + "source": [ + "**Delete** all the objects first" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "24616c20-ae7e-4d0f-9f9c-6c8752891fa7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CommandException: 1 files/objects could not be removed.\n" + ] + }, + { + "ename": "", + "evalue": "1", + "output_type": "error", + "traceback": [] + } + ], + "source": [ + "gsutil -m rm \"gs://$BUCKET/*\"" + ] + }, + { + "cell_type": "markdown", + "id": "194c0181-6a47-43c5-af40-29230d858164", + "metadata": {}, + "source": [ + "Delete the empty buckets" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "a1310b76-6212-48fa-b023-0a15e06d4332", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CommandException: No URLs matched: ['gs://essentials-learner-*/']\n" + ] + }, + { + "ename": "", + "evalue": "1", + "output_type": "error", + "traceback": [] + } + ], + "source": [ + "gsutil rb \"gs://$BUCKET/\"" + ] } ], "metadata": {