Documentation ¶
Index ¶
- Constants
- func CheckArgsConfigFormat(p *arg.Parser, args Args)
- func CheckArgsLogLevel(p *arg.Parser, args Args)
- func CheckConfig(conf *Config, cron bool) error
- func ConvertByteToString(data []byte, charset Charset) string
- func Exist(path string) bool
- func FileTrans(sourcePath, targetPath string) error
- func GenBackupFilename(prefix, db, collection, postfix string) string
- func GenTempFile(format string) string
- func IsDir(path string) bool
- func IsFile(path string) bool
- func Mkdir(path string) error
- func Run(conf *Config) error
- func RunInDaemon(conf *Config) error
- func ValidCronExpression(value interface{}) error
- func ValidDir(value interface{}) error
- func ValidFilePath(value interface{}) error
- func ValidTarget(value interface{}) error
- type Args
- type BaseCmd
- type Charset
- type Config
- type MongoTarget
Constants ¶
const ( // Name define app name Name = "mongodb-local-backup" // Version define app version Version = "0.6.0" // BackupFileName define backup temp file name BackupFileName = "mongo_backup_temp" // TagCmd define variable for parse data in golang tags TagCmd = "cmd" )
const ( // UFT8 uft-8 charset UFT8 = Charset("UTF-8") // GB18030 uft-8 charset GB18030 = Charset("GB18030") )
const MlbCron = "MLB_CRON"
const MlbHost = "MLB_HOST"
const MlbMongoexport = "MLB_MONGOEXPORT"
const MlbOutput = "MLB_OUTPUT"
const MlbPassword = "MLB_PASSWORD"
const MlbPort = "MLB_PORT"
const MlbPrefix = "MLB_PREFIX"
const MlbTarget = "MLB_TARGET"
const MlbType = "MLB_TYPE"
const MlbUsername = "MLB_USERNAME"
const TempDir = "/tmp/"
TempDir define a directory to save temp time
Variables ¶
This section is empty.
Functions ¶
func CheckArgsConfigFormat ¶ added in v0.6.0
func CheckArgsConfigFormat(p *arg.Parser, args Args)
CheckArgsConfigFormat check config format is valid
func CheckArgsLogLevel ¶ added in v0.6.0
func CheckArgsLogLevel(p *arg.Parser, args Args)
CheckArgsLogLevel check log level is valid
func CheckConfig ¶
CheckConfig call to validate all fields by ozzo-validation
func ConvertByteToString ¶
ConvertByteToString convert byte array to string with specific charset, such as UTF8
func GenBackupFilename ¶ added in v0.5.0
GenBackupFilename generate backup file name
func RunInDaemon ¶
RunInDaemon execute app with the config by cron, and stop until shutdown the app
func ValidCronExpression ¶
func ValidCronExpression(value interface{}) error
ValidCronExpression custom validator to validate cron expression for ozzo-validation
func ValidDir ¶
func ValidDir(value interface{}) error
ValidDir custom validator to validate directory path for ozzo-validation
func ValidFilePath ¶
func ValidFilePath(value interface{}) error
ValidFilePath custom validator to validate filepath for ozzo-validation
func ValidTarget ¶
func ValidTarget(value interface{}) error
ValidTarget custom validator to validate export db&collection in MongoDB for ozzo-validation
Types ¶
type Args ¶
type Args struct {
StartCmd *BaseCmd `arg:"subcommand:start" help:"start application"`
}
Args all commands struct
type BaseCmd ¶
type BaseCmd struct { Config string `arg:"-c,--config" help:"config file"` Format string `arg:"-f,--format" help:"config file format(json, yaml, toml)"` Daemon bool `arg:"-d,--daemon" help:"non stop running"` LogLevel string `arg:"-l,--log" default:"info" help:"log level(debug, info, warn, error, fatal, panic)"` }
BaseCmd base command struct
type Config ¶
type Config struct { Mongo string `json:"mongo,omitempty" yaml:"mongo,omitempty" help:"path of mongoexport program"` Host string `json:"host,omitempty" yaml:"host,omitempty" cmd:"host" help:"mongodb host"` Port int `json:"port,omitempty" yaml:"port,omitempty" cmd:"port" help:"mongodb port"` Username string `json:"username,omitempty" yaml:"username,omitempty" cmd:"username" help:"mongodb username"` Password string `json:"password,omitempty" yaml:"password" cmd:"password" help:"mongodb password"` Target []MongoTarget `json:"target,omitempty" yaml:"target,omitempty" help:"mongodb target"` Type string `json:"type,omitempty" yaml:"type,omitempty" cmd:"type" help:"backup file format"` Output string `json:"output,omitempty" yaml:"output,omitempty" help:"specific a path to store backup files"` Cron string `json:"cron,omitempty" yaml:"cron,omitempty" help:"CRON expression"` Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty" help:"backup file prefix"` }
Config config file struct
func ReadConfig ¶
ReadConfig read config file from given path and file format, support `json`, `yaml` and `toml`
type MongoTarget ¶
type MongoTarget struct { Db string `json:"db,omitempty" yaml:"db,omitempty" cmd:"db" help:"mongodb db"` Collection []string `json:"collection,omitempty" yaml:"collection,omitempty" cmd:"collection" help:"mongodb collection"` }
MongoTarget command options for target MongoDB db name and collection name