aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-08-23 00:02:04 -0700
committerChris Lu <chris.lu@gmail.com>2018-08-23 00:02:04 -0700
commit6e3f4d1079342a53056e95becbf6953c0f9115c3 (patch)
treed380f2204b31df6ba9ca9bc5bb1260f79448ea0d
parent98b8f8649d725dcddcda03b7dea6883688a62e04 (diff)
downloadseaweedfs-6e3f4d1079342a53056e95becbf6953c0f9115c3.tar.xz
seaweedfs-6e3f4d1079342a53056e95becbf6953c0f9115c3.zip
add working filer.export command
-rw-r--r--weed/command/filer_export.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/weed/command/filer_export.go b/weed/command/filer_export.go
index ab8962630..6ca360b44 100644
--- a/weed/command/filer_export.go
+++ b/weed/command/filer_export.go
@@ -28,6 +28,7 @@ var cmdFilerExport = &Command{
var (
// filerExportOutputFile = cmdFilerExport.Flag.String("output", "", "the output file. If empty, only list out the directory tree")
filerExportSourceStore = cmdFilerExport.Flag.String("sourceStore", "", "the source store name in filer.toml")
+ filerExportTargetStore = cmdFilerExport.Flag.String("targetStore", "", "the target store name in filer.toml")
)
type statistics struct {
@@ -40,7 +41,7 @@ func runFilerExport(cmd *Command, args []string) bool {
weed_server.LoadConfiguration("filer", true)
config := viper.GetViper()
- var sourceStore filer2.FilerStore
+ var sourceStore, targetStore filer2.FilerStore
for _, store := range filer2.Stores {
if store.GetName() == *filerExportSourceStore {
@@ -55,6 +56,19 @@ func runFilerExport(cmd *Command, args []string) bool {
}
}
+ for _, store := range filer2.Stores {
+ if store.GetName() == *filerExportTargetStore {
+ viperSub := config.Sub(store.GetName())
+ if err := store.Initialize(viperSub); err != nil {
+ glog.Fatalf("Failed to initialize store for %s: %+v",
+ store.GetName(), err)
+ } else {
+ targetStore = store
+ }
+ break
+ }
+ }
+
if sourceStore == nil {
glog.Errorf("Failed to find source store %s", *filerExportSourceStore)
println("existing data sources are:")
@@ -65,7 +79,18 @@ func runFilerExport(cmd *Command, args []string) bool {
}
stat := statistics{}
- doTraverse(&stat, sourceStore, filer2.FullPath("/"), 0, printout)
+
+ var fn func(level int, entry *filer2.Entry) error
+
+ if targetStore == nil {
+ fn = printout
+ } else {
+ fn = func(level int, entry *filer2.Entry) error {
+ return targetStore.InsertEntry(entry)
+ }
+ }
+
+ doTraverse(&stat, sourceStore, filer2.FullPath("/"), 0, fn)
glog.Infof("processed %d directories, %d files", stat.directoryCount, stat.fileCount)