问题
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
- 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. - 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 selectFirebase Rules System
from theOther
category. - Get your Google Storage URL from the Firebase Storage Page in the dashboard (Towards the top) Should look something like this:
gs://<bucket_name>
- 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
- 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.
- 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