• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3#script migrates buckets from old to new gcp
4#https://cloud.google.com/storage/docs/moving-buckets?hl=en#gsutil
5
6# new GCP
7newGcp='chromeos-partner-devices'
8# temp suffix
9temp_suffix='tmp'
10
11# Weird error when bucket is empty
12# CommandException: No URLs matched: gs://chromeos-xxx
13
14migrate_bucket() {
15  local bucket_name="${1}"
16  gsutil mb gs://"${bucket_name}-${temp_suffix}"
17  gsutil cp -r gs://"${bucket_name}"/* gs://"${bucket_name}-${temp_suffix}"
18  gsutil rm -r gs://"${bucket_name}"
19
20  gsutil mb gs://"${bucket_name}"
21  gsutil cp -r gs://"${bucket_name}-${temp_suffix}"/* gs://"${bucket_name}"
22  gsutil rm -r gs://"${bucket_name}-${temp_suffix}"
23}
24
25input="${1}"
26gcloud config set project "${newGcp}"
27while IFS= read -r line
28do
29  echo "migrate ${line}"
30  migrate_bucket "${line}"
31done < "${input}"
32