internal

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	// UFT8 uft-8 charset
	UFT8 = Charset("UTF-8")
	// GB18030 uft-8 charset
	GB18030 = Charset("GB18030")
)
View Source
const MlbCron = "MLB_CRON"
View Source
const MlbHost = "MLB_HOST"
View Source
const MlbMongoexport = "MLB_MONGOEXPORT"
View Source
const MlbOutput = "MLB_OUTPUT"
View Source
const MlbPassword = "MLB_PASSWORD"
View Source
const MlbPort = "MLB_PORT"
View Source
const MlbPrefix = "MLB_PREFIX"
View Source
const MlbTarget = "MLB_TARGET"
View Source
const MlbType = "MLB_TYPE"
View Source
const MlbUsername = "MLB_USERNAME"
View Source
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

func CheckConfig(conf *Config, cron bool) error

CheckConfig call to validate all fields by ozzo-validation

func ConvertByteToString

func ConvertByteToString(data []byte, charset Charset) string

ConvertByteToString convert byte array to string with specific charset, such as UTF8

func Exist

func Exist(path string) bool

Exist check if the given path is exists of file or directory

func FileTrans

func FileTrans(sourcePath, targetPath string) error

FileTrans move file form `sourcePath` to `targetPath`

func GenBackupFilename added in v0.5.0

func GenBackupFilename(prefix, db, collection, postfix string) string

GenBackupFilename generate backup file name

func GenTempFile

func GenTempFile(format string) string

GenTempFile generate temp file path

func IsDir

func IsDir(path string) bool

IsDir check if the given path is a directory or not

func IsFile

func IsFile(path string) bool

IsFile check if the given path is a file or not

func Mkdir

func Mkdir(path string) error

Mkdir create a new directory from the given path

func Run

func Run(conf *Config) error

Run execute app with the config once

func RunInDaemon

func RunInDaemon(conf *Config) error

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

func (*Args) Version

func (*Args) Version() string

Version gets the full version string

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 Charset

type Charset string

Charset define a type as string

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

func ReadConfig(file, format string) (*Config, error)

ReadConfig read config file from given path and file format, support `json`, `yaml` and `toml`

func ReadJson

func ReadJson(config *Config, b []byte) (*Config, error)

func ReadToml

func ReadToml(config *Config, b []byte) (*Config, error)

func ReadYaml

func ReadYaml(config *Config, b []byte) (*Config, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL