8
votes

I am attempting to copy the contents of a folder in one Firebase project's Storage bucket to the storage bucket of another Firebase project.

I have been following the firestore docs and this SO question.

Both projects have the necessary permissions to other's service accounts.

Here is what I have done:

When attempting to transfer files from a folder in the default bucket of Project-A to the default bucket of Project-B using the cloud shell terminal, I first set the project to 'Project-A'. I then ran gcloud beta firestore export gs://[PROJECT_A_ID] --collection-ids=[FOLDER_TO_TRANSFER] --async. This succeeds and creates a folder called "2019-08-26T21:23:23_26014/" in Project-A. This folder contains some metadata. Next, I tried beginning the import by setting the project to Project-B and running gcloud beta firestore import gs://[PROJECT_A_ID]/2019-08-26T21:23:23_26014 This completes and the logs display this message:

done: true metadata: '@type': type.googleapis.com/google.firestore.admin.v1beta1.ImportDocumentsMetadata collectionIds: - [FOLDER_TO_TRANSFER] endTime: '2019-08-26T21:25:56.794588Z' inputUriPrefix: gs://[PROJECT_A_ID]/2019-08-26T21:23:23_26014 operationState: SUCCESSFUL startTime: '2019-08-26T21:25:19.689430Z' name: projects/[PROJECT_B]/databases/(default)/operations/[SOME_ID_STRING] response: '@type': type.googleapis.com/google.protobuf.Empty

However, the Project-B storage bucket doesn't have any new files or folders. It looks like the import did nothing. Am I missing something?

1
Are you trying to move Cloud Storage objects or Cloud Firestore data? The docs/commands you describe are the ones for moving Cloud Firestore data. If you're trying to move Cloud Storage objects, see cloud.google.com/storage/docs/renaming-copying-moving-objects. - Juan Lara
Ah, I am trying to move a folder within a Storage bucket. So I guess that'd be a storage object. The documentation doesn't seem to mention moving an object between projects though. Do you know if this is possible? - Chris Voss

1 Answers

12
votes

You can create a transfer job in the GCP Console. You can specify source/destination buckets from different projects as long as you have access permissions. You can specify the folder by setting "Specify file filters":

https://console.cloud.google.com/storage/transfer

You can also use the gsutil tool, which is part of gcloud, to move or copy your objects to another bucket.

So your default buckets would be gs://[PROJECT_A_ID].appspot.com and gs://[PROJECT_B_ID].appspot.com Let's say you wanted to copy over the contents of my_directory:

gsutil cp -r gs://[PROJECT_A_ID].appspot.com/my_directory gs://[PROJECT_B_ID].appspot.com