2017-07-06 13:03:44 +02:00
|
|
|
// zrepl replicates ZFS filesystems & volumes between pools
|
|
|
|
//
|
|
|
|
// Code Organization
|
|
|
|
//
|
|
|
|
// The cmd package uses github.com/spf13/cobra for its CLI.
|
|
|
|
//
|
|
|
|
// It combines the other packages in the zrepl project to implement zrepl functionality.
|
|
|
|
//
|
|
|
|
// Each subcommand's code is in the corresponding *.go file.
|
|
|
|
// All other *.go files contain code shared by the subcommands.
|
|
|
|
package cmd
|
2017-04-14 19:26:32 +02:00
|
|
|
|
2017-04-26 20:21:18 +02:00
|
|
|
import (
|
2017-07-06 13:03:44 +02:00
|
|
|
"github.com/spf13/cobra"
|
2017-06-09 21:01:50 +02:00
|
|
|
"net/http"
|
|
|
|
_ "net/http/pprof"
|
2017-04-26 20:21:18 +02:00
|
|
|
)
|
|
|
|
|
2017-05-03 18:32:11 +02:00
|
|
|
type Logger interface {
|
|
|
|
Printf(format string, v ...interface{})
|
|
|
|
}
|
|
|
|
|
2017-07-06 13:03:44 +02:00
|
|
|
var RootCmd = &cobra.Command{
|
|
|
|
Use: "zrepl",
|
|
|
|
Short: "ZFS dataset replication",
|
|
|
|
Long: `Replicate ZFS filesystems & volumes between pools:
|
2017-04-14 19:26:32 +02:00
|
|
|
|
2017-07-06 13:03:44 +02:00
|
|
|
- push & pull mode
|
|
|
|
- automatic snapshot creation & pruning
|
|
|
|
- local / over the network
|
|
|
|
- ACLs instead of blank SSH access`,
|
2017-04-26 20:21:18 +02:00
|
|
|
}
|
2017-04-14 19:26:32 +02:00
|
|
|
|
2017-07-06 13:03:44 +02:00
|
|
|
var rootArgs struct {
|
|
|
|
configFile string
|
|
|
|
httpPprof string
|
2017-04-14 19:26:32 +02:00
|
|
|
}
|
|
|
|
|
2017-07-06 13:03:44 +02:00
|
|
|
func init() {
|
2017-09-17 18:20:05 +02:00
|
|
|
//cobra.OnInitialize(initConfig)
|
2017-07-06 13:03:44 +02:00
|
|
|
RootCmd.PersistentFlags().StringVar(&rootArgs.configFile, "config", "", "config file path")
|
|
|
|
RootCmd.PersistentFlags().StringVar(&rootArgs.httpPprof, "debug.pprof.http", "", "run pprof http server on given port")
|
|
|
|
}
|
2017-04-14 19:26:32 +02:00
|
|
|
|
2017-07-06 13:03:44 +02:00
|
|
|
func initConfig() {
|
2017-04-29 18:26:43 +02:00
|
|
|
|
2017-07-06 13:03:44 +02:00
|
|
|
// CPU profiling
|
|
|
|
if rootArgs.httpPprof != "" {
|
|
|
|
go func() {
|
|
|
|
http.ListenAndServe(rootArgs.httpPprof, nil)
|
|
|
|
}()
|
2017-05-07 12:28:31 +02:00
|
|
|
}
|
|
|
|
|
2017-05-16 16:57:24 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
}
|