summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-09-17 15:51:26 +0100
committerGitHub <noreply@github.com>2018-09-17 15:51:26 +0100
commitab99f0656fabed8a62a8c6340be7d538cc7bf8d9 (patch)
treebb68ee1d0c743be23bba470f5d81ef11dc134182 /cmd
parent5786b0d6d57b90bbb0c262235dd9d19b497b5fae (diff)
downloadchat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.tar.gz
chat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.tar.bz2
chat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.zip
MM-11781: Basic Data Export Command Line. (#9296)
* MM-11781: Basic Data Export Command Line. * ChannelStore new unit tests. * TeamStore new unit tests. * Unit test for new UserStore function. * Unit tests for post store new methods. * Review fixes. * Fix duplicate command name.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mattermost/commands/export.go (renamed from cmd/mattermost/commands/message_export.go)58
-rw-r--r--cmd/mattermost/commands/export_test.go (renamed from cmd/mattermost/commands/message_export_test.go)0
2 files changed, 52 insertions, 6 deletions
diff --git a/cmd/mattermost/commands/message_export.go b/cmd/mattermost/commands/export.go
index 953d4ccba..bd311e154 100644
--- a/cmd/mattermost/commands/message_export.go
+++ b/cmd/mattermost/commands/export.go
@@ -5,6 +5,7 @@ package commands
import (
"errors"
+ "os"
"context"
@@ -14,10 +15,10 @@ import (
"github.com/spf13/cobra"
)
-var MessageExportCmd = &cobra.Command{
+var ExportCmd = &cobra.Command{
Use: "export",
Short: "Export data from Mattermost",
- Long: "Export data from Mattermost in a format suitable for import into a third-party application",
+ Long: "Export data from Mattermost in a format suitable for import into a third-party application or another Mattermost instance",
}
var ScheduleExportCmd = &cobra.Command{
@@ -44,16 +45,31 @@ var ActianceExportCmd = &cobra.Command{
RunE: buildExportCmdF("actiance"),
}
+var BulkExportCmd = &cobra.Command{
+ Use: "bulk [file]",
+ Short: "Export bulk data.",
+ Long: "Export data to a file compatible with the Mattermost Bulk Import format.",
+ Example: " export bulk bulk_data.json",
+ RunE: bulkExportCmdF,
+}
+
func init() {
ScheduleExportCmd.Flags().String("format", "actiance", "The format to export data")
ScheduleExportCmd.Flags().Int64("exportFrom", -1, "The timestamp of the earliest post to export, expressed in seconds since the unix epoch.")
ScheduleExportCmd.Flags().Int("timeoutSeconds", -1, "The maximum number of seconds to wait for the job to complete before timing out.")
+
CsvExportCmd.Flags().Int64("exportFrom", -1, "The timestamp of the earliest post to export, expressed in seconds since the unix epoch.")
+
ActianceExportCmd.Flags().Int64("exportFrom", -1, "The timestamp of the earliest post to export, expressed in seconds since the unix epoch.")
- MessageExportCmd.AddCommand(ScheduleExportCmd)
- MessageExportCmd.AddCommand(CsvExportCmd)
- MessageExportCmd.AddCommand(ActianceExportCmd)
- RootCmd.AddCommand(MessageExportCmd)
+
+ BulkExportCmd.Flags().Bool("all-teams", false, "Export all teams from the server.")
+
+ ExportCmd.AddCommand(ScheduleExportCmd)
+ ExportCmd.AddCommand(CsvExportCmd)
+ ExportCmd.AddCommand(ActianceExportCmd)
+ ExportCmd.AddCommand(BulkExportCmd)
+
+ RootCmd.AddCommand(ExportCmd)
}
func scheduleExportCmdF(command *cobra.Command, args []string) error {
@@ -140,3 +156,33 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string)
return nil
}
}
+
+func bulkExportCmdF(command *cobra.Command, args []string) error {
+ a, err := InitDBCommandContextCobra(command)
+ if err != nil {
+ return err
+ }
+ defer a.Shutdown()
+
+ allTeams, err := command.Flags().GetBool("all-teams")
+ if err != nil {
+ return errors.New("Apply flag error")
+ }
+
+ if !allTeams {
+ return errors.New("Nothing to export. Please specify the --all-teams flag to export all teams.")
+ }
+
+ fileWriter, err := os.Create(args[0])
+ if err != nil {
+ return err
+ }
+ defer fileWriter.Close()
+
+ if err := a.BulkExport(fileWriter); err != nil {
+ CommandPrettyPrintln(err.Error())
+ return err
+ }
+
+ return nil
+}
diff --git a/cmd/mattermost/commands/message_export_test.go b/cmd/mattermost/commands/export_test.go
index 89ef45a6a..89ef45a6a 100644
--- a/cmd/mattermost/commands/message_export_test.go
+++ b/cmd/mattermost/commands/export_test.go