English | 日本語
fsrpl is CloudFirestore replication tool.
copyReplicate document data from some node to another node. With Wildcard option, Replicate all document data from some collection node to another collection node.- In addition to this, replicate document data from some projectId's Firestore to another projectId's Firestore.
dumpBackup document data from some node to local JSON file.restoreRestore document data from local JSON file. Because the data can be restored to thefirestore emulatoras well, it can be used to create test data.
Table Of Contents:
| copy |
|---|
![]() |
| restore | dump |
|---|---|
![]() |
![]() |
you can use homebrew for macOS
# add informal formula
brew tap matsu0228/homebrew-fsrpl
brew install fsrpl
go get github.com/matsu0228/fsrpl
download here to get binary. https://github.com/matsu0228/fsrpl/releases
- you should set firestore's private key(JSON file).
- you can get private key from console. see official document
- You have two options.
- set environment variable:
FSRPL_CREDENTIALS - use
--credoption
- set environment variable:
- copy some documents with
copysub command.
fsrpl copy [input document path] --dest [output document path]
e.g.
fsrpl copy "inputData/user" --dest "new/user"
fsrpl copy "inputData/*" --dest "outputData/*"
- export data from some documents with
dumpsub command.
fsrpl dump [input document path] -f [json file directory path]
e.g.
fsrpl dump "inputData/user" --path ./
cat user.json
{
"_created_at": "2019-08-26T05:00:00Z",
"coin": 0,
"favorites": [
"1",
"2"
],
"isDeleted": true,
"mapData": {
"isMan": true,
"name": "subName"
},
"name": "user"
}
fsrpl dump "inputData/*" --path ./
cat cat.json | jq
{
"_created_at": "2019-08-26T05:00:00Z",
"coin": 0,
"favorites": [
"1",
"2"
],
"isDeleted": true,
"mapData": {
"isBrownhair": true,
"name": "calico"
},
"name": "cat"
}
cat dog.json | jq
{
"name": "dog"
...
}
...
- import data from JSON files with
restoresub command.
fsrpl restore [import document path] --path [import JSON file directory path]
e.g.
fsrpl restore "importData/*" --path "./"
save to importData/ dog. data: map[string]interface {}{"_created_at":time.Time{wall:0x0, ext:63702392400, loc:(*time.Location)(nil)}, "coin":0, "favorites":[]interface {}{"1", "2"}, "isDeleted":true, "mapData":map[string]interface {}{"b":true, "name":"mName"}, "name":"pig"}
...
- With setting the
FIRESTORE_EMULATOR_HOSTenvironment variable, therestorecommand can be used to restore the emulator.- The
--emulators-project-idoption allow to specify the projectId with to avoid data conflicts by specifying it. - see this examples
- The
FIRESTORE_EMULATOR_HOST=**your_firestore_emulator** fsrpl restore [import document path] --path [import JSON file directory path] --emulators-project-id [test unique Id]
e.g.
FIRESTORE_EMULATOR_HOST=localhost:8080 fsrpl restore "importData/*" --path "./" --emulators-project-id emulator-integration-test
- generate Go struct from some document with
-show-go-structoption
e.g.
fsrpl dump "inputData/user" --show-go-struct
package main
type JsonStruct struct {
CreatedAt string `json:"_created_at"`
Coin int64 `json:"coin"`
Favorites []string `json:"favorites"`
IsDeleted bool `json:"isDeleted"`
MapData struct {
B bool `json:"b"`
Name string `json:"name"`
} `json:"mapData"`
Name string `json:"name"`
}



