:floppy_disk: a simple Firebase database backup tool
This script downloads the entire Firebase database and uploads it as a GZipped JSON file to Firebase Storage.
pyrebase
libraryhttplib2
librarygz
libraryFirst, ensure you have Python 3 and pip installed on your machine. Then, install the required Python libraries using pip:
pip install -r requirements.txt
Update the config
dictionary in the script with your Firebase project information:
config = {
"apiKey": "YOUR-API-KEY",
"authDomain": "YOUR-FIREBASE-DOMAIN.firebaseapp.com",
"databaseURL": "https://YOUR-FIREBASE-DOMAIN.firebaseio.com",
"storageBucket": "YOUR-FIREBASE-DOMAIN.appspot.com",
"serviceAccount": "YOUR-CLIENTSECRET-FILE.json"
}
Replace the placeholders with your actual Firebase project information.
Run the script using Python:
python backup.py
This will:
db, auth, storage = initialize_firebase(config)
upload_name, gzip_name = get_file_names()
data = download_database(auth, config, httplib2.Http())
with gzip.open(gzip_name, 'wb') as f_out:
f_out.write(data)
upload_backup(storage, gzip_name)
The script uses the logging
library to log information about its execution. By default, it logs at the INFO
level.
This project is licensed under the MIT License.