首页 > 解决方案 > How to keep/re-create object metadata during gsutil cp on storage bucket

问题描述

I would like to sync all of the files in my Google Cloud Storage bucket with the exported files in my Firebase Storage Emulator.

  1. I downloaded all of my cloud files using gsutil to my local machine.
  2. I used BeyondCompare to move all of the new files to the '../storage_export/blobs/ directory.
  3. How do I update/create the JSON metadata in '../storage_export/metadata' to reflect these new files and make them available when I run the emulator and import them in?

Edit:

The gsutil docs mention the following:

when you download data from the cloud, it ends up in a file with no associated metadata, unless you have some way to keep or re-create that metadata.

How would one "keep" or "re-create" that metadata during a gsutil cp download?

标签: firebasegoogle-cloud-platformgoogle-cloud-storagegsutil

解决方案


You can use gsutil or the SDK to get each object's metadata and then write it down to a JSON file however, there's currently no native way to import Google Cloud Storage data in the Storage Emulator. But as I stated in my answer to this post, you can study how the emulator register the object by uploading sample files within the emulator and then running the export, you will see that the emulator will require 1 object and 1 JSON file that contains it's metadata.

Lastly, you can add the option --export-on-exit when starting the emulator, Downloaded all data from the real Firebase project, uploaded everything with the Emulator, then kill the emulator; as stated in this post.

Note: This is not a documented feature! Firebase doesn't expose the concept of download tokens in its public SDKs or APIs, so manipulating tokens this way feels a bit "hacky". For your further reference, check this post.


推荐阅读