Firebase Storage - How to setup a backup

谁说我不能喝 提交于 2020-01-24 20:19:26

问题


Can someone please advise how to setup a backup for Files in Firebase storage. I am able to make a backup of Database but not sure how to setup a regular backup for files (I have images) in firebase storage.


回答1:


How to make local backup of Firebase Storage

There is no built-in method via Firebase. However, since Firebase uses Google Cloud Storage behind the scenes for Firebase Storage it's possible to use the gutils Tool.

Prerequisites

  • Make sure Python (2.7.9+) is installed on your machine python -V
  • Go to the Google Cloud SDK page and follow the directions to download and install Google Cloud SKD on your OS.

Steps

  1. At the end of the Google SDK installation you should have run gcloud init. This will ask you to select your project and authenticate you. Since Firebase uses Google Cloud Platform behind the scenes your Firebase project should be available as a choice.
  2. In order for Google Cloud Utils to download the files that were uploaded with Firebase permissions you need to give your account Firebase Privileges. Go to the IAM page and select your email address you signed into cloud init with. In the list of available permissions you need to select Firebase Rules System from the Other category.
  3. Get your Google Storage URL from the Firebase Storage Page in the dashboard (Towards the top) Should look something like this: gs://<bucket_name>
  4. In command line on your local machine navigate to the folder you want to do a local backup to. Make sure you are in the folder you want as the following command will download all files right there in current folder
  5. Run the gutil command gsutil -m cp -R gs://<bucket_name> .
    • -m enables multithreading for faster downloads if you have many files.
    • cp is the copy command
    • -R is recursive. If enabled it will download all files and folders in the specified tree.
  6. You're done! This will run for some time depending on the size of your storage.

This can be used to also make a copy(backup) to another Google Cloud Storage Bucket or AWS etc.




回答2:


There is no built-in backup feature in Cloud Storage for Firebase.

But since it is built on top of Google Cloud Storage, any backup solution for GCS can work for Firebase too. Typically this will involve creating a separate bucket that is the target of the regular bucket where you store/read files.



来源:https://stackoverflow.com/questions/46419175/firebase-storage-how-to-setup-a-backup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!