Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export: add command to export backup file to txt file #62

Merged
merged 3 commits into from
Sep 11, 2023
Merged

Conversation

1023280072
Copy link
Collaborator

  • add tcpmon/export.go
  • add tcpmon/print_metric.go
  • add tools/codegen.go to generate tcpmon/print_metric_tsdb.go

- add tcpmon/export.go
- add tcpmon/print_metric.go
- add tools/codegen.go to generate tcpmon/print_metric_tsdb.go
cmd/export.go Outdated
hostname := args[1]

if net.ParseIP(hostname) == nil {
log.Fatal().Msg("Invalid IP address")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hostname 不一定是个 ip

cmd/export.go Outdated
log.Fatal().Msg("Invalid IP address")
}

var printer tcpmon.PrintMetric
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该叫 MetricPrinter

cmd/export.go Outdated
var printer tcpmon.PrintMetric
switch format {
case "tsdb":
printer = tcpmon.TSDBPrintMetric{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上。

cmd/export.go Outdated

isEmpty, err := IsDirEmpty(dbDir)
if err != nil {
log.Fatal().Err(err).Msg("Check db directory failed, need an empty directory")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里写 need an empty directory,但是 force = true 的情况又不需要一个空的目录。并且这里 err != nil 的情况下,也并不意味着 need an empty directory 的发生。

cmd/export.go Outdated
}
defer db.Close()

if !isEmpty {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像可以直接 DropAll?因为他肯定是 empty,或者是有数据,反正不需要判断

cmd/export.go Outdated
func init() {
exportCmd.Flags().StringVarP(&format, "format", "f", "tsdb", "export backup to txt in this format")
exportCmd.Flags().StringVarP(&dbDir, "db", "d", "/tmp/tcpmon/export/db", "db path to restore backup")
exportCmd.Flags().BoolVarP(&force, "force", "e", false, "force restore, may overwrite files")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force 一般是 -f

这里冲突的情况,format 通常是可以忽略的,不经常用,所以 format 可能不需要 P

@@ -0,0 +1,7 @@
package tcpmon

type PrintMetric interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@fanyang89 fanyang89 merged commit 7e0d7ca into main Sep 11, 2023
1 check passed
@fanyang89 fanyang89 deleted the rxh2 branch September 11, 2023 11:29
@fanyang89 fanyang89 assigned fanyang89 and 1023280072 and unassigned fanyang89 Sep 11, 2023
@fanyang89 fanyang89 added the enhancement New feature or request label Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants