smellyarmpits
smellyarmpits

Reputation: 1120

How to copy a Google Cloud Storage Bucket from project to project?

I have a Compute Engine instance with Postgres running on project1. I want to migrate that to the fully managed postgres provided by Google Cloud SQL environment, on project2, so a different project. To do so, I have SSHed into my VM instance and dumped the database to a file.

Now I want to restore the DB into Google Cloud SQL on project2.

I was thinking about saving the file to a project1's Storage Bucket and then move it somehow to project2, but I don't know how to copy a bucket from project1 to project2.

Upvotes: 4

Views: 4948

Answers (1)

Amir Rahwane
Amir Rahwane

Reputation: 674

The quickest way I think of doing it from where you stopped is,

  1. After dumping the file, in your SSH session, check what service account is activated on the instance.

    $ gcloud auth list

Copy the account marked ACTIVE

- [email protected] ACTIVE
  1. Than, go to the Storage page on the Cloud Console for project2 and create a new bucket.
  2. Click on the More Options icon on the right to edit the bucket permissions. Add the service account as User entity with write permissions.
  3. Copy the dump file from your instance to bucket on project2

    $ gsutil cp /home/user/dump.gz gs://bucket-on-project2/

  4. Import the databse to Google Cloud SQL from the bucket

If you just want to tansfer files between buckets:

Using the browser, You can navigate to Storage->Transfer in the Cloud Console.

Using th CloudSDK and considering you have the right write/read permissions for both buckets on both projects.

$ gsutil cp gs://bucket-on-project1/dump.gz gs://bucket-on-project2/

Upvotes: 5

Related Questions