From 051583d767546c63043619cd6dc7380746b75b6e Mon Sep 17 00:00:00 2001 From: YannikBramkamp <74957914+YannikBramkamp@users.noreply.github.com> Date: Tue, 2 Feb 2021 11:27:54 +0100 Subject: [PATCH] Add release workflow (#25) * Create go.yml * remove unneded workflow * create GzipFile() * added --gzip flag and integrated it into backup process * error handling * Revert " added --gzip flag and integrated it into backup process" This reverts commit c755f461c65f8575d286f996fee5e4a651ed7f26. * tests for gzip functions * fix import * updated readme * properly use gzip const everywhere, change gzip variable definition * more const uses * add test for validity of generated gzip * create gzip testfile during runtime, renamed test * const for test file permissions * cleanup and some comments * rename github workflow * fix forgotten error handling in test * test for CheckAndGunzipFile * documentation * multiline cupcakes * add release workflow * fixed docker user * fixed workflow * update readme toc * update linter cfg * lint maligned structures * linting * Fix error in mongorestore cli flags * add restic output to error restic backup and restore error message * use global linter cfg * attempt to fix workflow * checkout project before linting * remove unneeded lint step, try to fix goreleaser lint step * fix working directory * fix skip dirs * removed context check --- .github/workflows/release.yaml | 19 ++++ Makefile | 25 +++-- README.md | 55 +++++------ build/ci/.golangci.yml | 82 +---------------- build/ci/.goreleaser.yml | 2 +- main.go | 5 +- pkg/cli/cli.go | 20 ++-- pkg/config/config_handler.go | 6 +- pkg/restic/client.go | 11 ++- pkg/restic/commands.go | 18 ++-- pkg/restic/types.go | 32 +++---- pkg/source/backup.go | 2 +- pkg/source/mongodump/cli.go | 18 ++-- .../mongorestore/backend_config_based.go | 2 +- pkg/source/mongorestore/cli.go | 27 +++--- pkg/source/mongorestore/config.go | 6 +- pkg/source/mysqldump/cli.go | 92 +++++++++---------- pkg/source/mysqlrestore/cli.go | 92 +++++++++---------- pkg/source/pgdump/cli.go | 46 +++++----- pkg/source/pgrestore/cli.go | 70 +++++++------- pkg/source/psql/cli.go | 26 +++--- pkg/source/redisdump/cli.go | 30 +++--- pkg/source/restore.go | 2 +- pkg/source/tar/cli.go | 10 +- pkg/source/tarrestore/cli.go | 10 +- test/pkg/source/internal/testcommons.go | 10 +- 26 files changed, 334 insertions(+), 384 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..0af6987 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,19 @@ +name: Release + +on: + push: + tags: + - '*' + +jobs: + build: + name: Build and release image + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - run: docker login -u "${{ secrets.DOCKER_LOGIN_USER }}" -p "${{ secrets.DOCKER_LOGIN_PASSWORD }}" quay.io + + - run: curl -sL https://git.io/goreleaser | bash -s -- --config build/ci/.goreleaser.yml --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_USER_TOKEN }} diff --git a/Makefile b/Makefile index 10abc93..aac60ea 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ BINARY_NAME = brudi COMMIT_HASH = $(shell git rev-parse --verify HEAD) CURDIR = $(shell pwd) -GOLANGCI_LINT_VER = v1.33.0 +GOLANGCI_LINT_VER = v1.35.0 .PHONY: build test @@ -25,14 +25,21 @@ build: test: go test -v ./... -lintpull: - docker pull golangci/golangci-lint:$(GOLANGCI_LINT_VER) - -lint: lintpull - docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:$(GOLANGCI_LINT_VER) golangci-lint -c build/ci/.golangci.yml run -v - -lintfix: lintpull - docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:$(GOLANGCI_LINT_VER) golangci-lint -c build/ci/.golangci.yml run -v --fix +lintci: + docker run --rm \ + -v $(CURDIR):/app \ + -w /app \ + -e GOLANGCI_ADDITIONAL_YML=/app/build/package/ci/.golangci.yml \ + quay.io/mittwald/golangci-lint:0.0.8 \ + golangci-lint run -v --fix ./... + +lint: + docker run --rm \ + -v $(shell go env GOPATH):/go \ + -v ${CURDIR}:/app -w /app \ + -e GOLANGCI_ADDITIONAL_YML=/app/build/package/ci/.golangci.yml \ + quay.io/mittwald/golangci-lint:0.0.8 \ + golangci-lint run -v --fix ./... goreleaser: curl -sL https://git.io/goreleaser | bash -s -- --snapshot --skip-publish --rm-dist diff --git a/README.md b/README.md index 2fca950..dfbf600 100644 --- a/README.md +++ b/README.md @@ -13,30 +13,33 @@ Besides creating backups, `brudi` can also be used to restore your data from bac ## Table of contents -- [Usage](#usage) - - [CLI](#cli) - - [Configuration](#configuration) - - [Sources](#sources) - - [Tar](#tar) - - [MySQLDump](#mysqldump) - - [MongoDump](#mongodump) - - [PgDump](#pgdump) - - [Limitations](#limitations) - - [Redis](#redis) - - [Restic](#restic) - - [Forget](#forget) - - [Sensitive data: Environment variables](#sensitive-data--environment-variables) - - [Restoring from backup](#restoring-from-backup) - - [TarRestore](#tarrestore) - - [MongoRestore](#mongorestore) - - [MySQLRestore](#mysqlrestore) - - [PgRestore](#pgrestore) - - [Restore using pg_restore](#restore-using-pg_restore) - - [Restore using psql](#restore-using-psql) -- [Featurestate](#featurestate) - - [Source backup methods](#source-backup-methods) - - [Restore backup methods](#restore-backup-methods) - - [Incremental backup of the source backups](#incremental-backup-of-the-source-backups) + - [Usage](#usage) + - [CLI](#cli) + - [Docker](#docker) + - [Configuration](#configuration) + - [Sources](#sources) + - [Tar](#tar) + - [MySQLDump](#mysqldump) + - [MongoDump](#mongodump) + - [PgDump](#pgdump) + - [Limitations](#limitations) + - [Redis](#redis) + - [Restic](#restic) + - [Forget](#forget) + - [Sensitive data: Environment variables](#sensitive-data-environment-variables) + - [Gzip support for binaries without native gzip support](#gzip-support-for-binaries-without-native-gzip-support) + - [Restoring from backup](#restoring-from-backup) + - [TarRestore](#tarrestore) + - [MongoRestore](#mongorestore) + - [MySQLRestore](#mysqlrestore) + - [PgRestore](#pgrestore) + - [Restore using pg_restore](#restore-using-pg_restore) + - [Restore using psql](#restore-using-psql) + - [Restoring using restic](#restoring-using-restic) + - [Featurestate](#featurestate) + - [Source backup methods](#source-backup-methods) + - [Restore backup methods](#restore-backup-methods) + - [Incremental backup of the source backups](#incremental-backup-of-the-source-backups) ## Usage @@ -411,7 +414,7 @@ Restoration for PostgreSQL databases is split into two commands, `psql` and `pgr `pgrestore` can be used if the `format` option of `pg_dump` was set to `tar`, `directory` or `custom`. -##### Restore using pg_restore +###### Restore using pg_restore ```yaml pgrestore: @@ -435,7 +438,7 @@ This command has to be used if the `format` option was set to `tar`, `directory` All available flags to be set in the `.yaml`-configuration can be found [here](pkg/source/pgrestore/cli.go#L7). -##### Restore using psql +###### Restore using psql ```yaml psql: diff --git a/build/ci/.golangci.yml b/build/ci/.golangci.yml index a96fe3d..f69bcd4 100644 --- a/build/ci/.golangci.yml +++ b/build/ci/.golangci.yml @@ -1,83 +1,7 @@ -linters-settings: - dupl: - threshold: 100 - funlen: - lines: 100 - statements: 50 - goconst: - min-len: 2 - min-occurrences: 2 - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - disabled-checks: - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - ifElseChain - - octalLiteral - - whyNoLint - - wrapperFunc - gocyclo: - min-complexity: 20 - goimports: - local-prefixes: github.com/mittwald/brudi - golint: - min-confidence: 0 - gomnd: - settings: - mnd: - # don't include the "operation" and "assign" - checks: argument,case,return - lll: - line-length: 140 - maligned: - suggest-new: true - misspell: - locale: US - -linters: - disable-all: true - enable: - - bodyclose - - deadcode - - depguard - - dogsled - - dupl - - errcheck - - funlen - - goconst - - gocritic - - gocyclo - - gofmt - - goimports - - golint - - gomnd - - goprintffuncname - - gosimple - - govet - - ineffassign - - interfacer - - lll - - misspell - - nakedret - - rowserrcheck - - scopelint - - staticcheck - - structcheck - - stylecheck - - typecheck - - unconvert - - unparam - - unused - - varcheck - - whitespace +# tested with golangci/golangci-lint:v1.35 run: skip-dirs: - - example/ - - .github/ - - dist/ - test/ + timeout: 10m + diff --git a/build/ci/.goreleaser.yml b/build/ci/.goreleaser.yml index 8fd5477..c010ac1 100644 --- a/build/ci/.goreleaser.yml +++ b/build/ci/.goreleaser.yml @@ -1,7 +1,7 @@ before: hooks: - go mod download - - make lint + - make lintci builds: - env: diff --git a/main.go b/main.go index ac66948..a37d931 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,11 @@ package main import ( - "github.com/spf13/cobra" + "errors" "github.com/mittwald/brudi/cmd" "github.com/mittwald/brudi/internal" + "github.com/spf13/cobra" ) func init() { @@ -13,7 +14,7 @@ func init() { func main() { err := cmd.Execute() - if err != nil && err != cobra.ErrSubCommandRequired { + if err != nil && !errors.Is(err, cobra.ErrSubCommandRequired) { panic(err) } } diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 845dd71..1908bb5 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -93,7 +93,7 @@ func includeFlag(flag, val string) []string { // Notice: // ---------------------------------------------------- // Zero values (0, "", nil, false) and "-" will be ignored -func StructToCLI(optionStruct interface{}) []string { // nolint: gocyclo +func StructToCLI(optionStruct interface{}) []string { if optionStruct == reflect.Zero(reflect.TypeOf(optionStruct)).Interface() { return nil } @@ -201,12 +201,12 @@ func Run(ctx context.Context, cmd CommandType) ([]byte, error) { commandLine := ParseCommandLine(cmd) log.WithField("command", strings.Join(commandLine, " ")).Debug("executing command") if ctx != nil { - out, err = exec.CommandContext(ctx, commandLine[0], commandLine[1:]...).CombinedOutput() + out, err = exec.CommandContext(ctx, commandLine[0], commandLine[1:]...).CombinedOutput() // nolint: gosec if ctx.Err() != nil { return out, fmt.Errorf("failed to execute command: timed out or canceled") } } else { - out, err = exec.Command(commandLine[0], commandLine[1:]...).CombinedOutput() + out, err = exec.Command(commandLine[0], commandLine[1:]...).CombinedOutput() // nolint: gosec } if err != nil { return out, fmt.Errorf("failed to execute command: %s", err) @@ -251,13 +251,8 @@ func RunPiped(ctx context.Context, cmd1, cmd2 CommandType, pids *PipedCommandsPi ), ).Debug("executing command") - if ctx != nil { - cmd1Exec = exec.CommandContext(ctx, cmdLine1[0], cmdLine1[1:]...) - cmd2Exec = exec.CommandContext(ctx, cmdLine2[0], cmdLine2[1:]...) - } else { - cmd1Exec = exec.Command(cmdLine1[0], cmdLine1[1:]...) - cmd2Exec = exec.Command(cmdLine2[0], cmdLine2[1:]...) - } + cmd1Exec = exec.CommandContext(ctx, cmdLine1[0], cmdLine1[1:]...) // nolint: gosec + cmd2Exec = exec.CommandContext(ctx, cmdLine2[0], cmdLine2[1:]...) // nolint: gosec cmd2Exec.Stdin, err = cmd1Exec.StdoutPipe() if err != nil { @@ -288,7 +283,8 @@ func RunPiped(ctx context.Context, cmd1, cmd2 CommandType, pids *PipedCommandsPi err = cmd1Exec.Wait() if err != nil { - msg, ok := err.(*exec.ExitError) + var msg exec.ExitError + ok := errors.As(err, &msg) if !ok || !(cmd1.Binary == "tar" && msg.Sys().(syscall.WaitStatus).ExitStatus() == 1) { // ignore tar exit-code of 1 errs = append(errs, err.Error()) } @@ -438,7 +434,7 @@ func CheckAndGunzipFile(fileName string) (string, error) { }() // write unzipped file to file system - _, err = io.Copy(outFile, archiveReader) + _, err = io.Copy(outFile, archiveReader) // nolint: gosec // we work with potentially large backups if err != nil { return "", errors.WithStack(err) } diff --git a/pkg/config/config_handler.go b/pkg/config/config_handler.go index a2348b3..c441330 100644 --- a/pkg/config/config_handler.go +++ b/pkg/config/config_handler.go @@ -36,7 +36,7 @@ func ReadPaths(cfgFiles ...string) [][]byte { } } - var cfgContent [][]byte + var cfgContent = make([][]byte, 0, len(cfgFiles)) for _, file := range cfgFiles { content, err := ioutil.ReadFile(file) if err != nil { @@ -49,7 +49,7 @@ func ReadPaths(cfgFiles ...string) [][]byte { // RawConfigs creates templates for provided configs func RawConfigs(configContent [][]byte) []*template.Template { - var tpl []*template.Template + var tpl = make([]*template.Template, 0, len(configContent)) for _, content := range configContent { tpltemp, err := template.New("").Parse(string(content)) @@ -78,7 +78,7 @@ func RenderConfigs(templates []*template.Template) []*bytes.Buffer { } } - var cfgsRendered []*bytes.Buffer + var cfgsRendered = make([]*bytes.Buffer, 0, len(templates)) for _, template := range templates { renderedCfg := new(bytes.Buffer) err := template.Execute(renderedCfg, &data) diff --git a/pkg/restic/client.go b/pkg/restic/client.go index f4988e9..b91f1ed 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -55,7 +55,7 @@ func (c *Client) DoResticBackup(ctx context.Context) error { c.Logger.Info("running 'restic backup'") _, err := initBackup(ctx, c.Config.Global) - if err == ErrRepoAlreadyInitialized { + if errors.Is(err, ErrRepoAlreadyInitialized) { c.Logger.Info("restic repo is already initialized") } else if err != nil { return errors.WithStack(fmt.Errorf("error while initializing restic repository: %s", err.Error())) @@ -63,9 +63,10 @@ func (c *Client) DoResticBackup(ctx context.Context) error { c.Logger.Info("restic repo initialized successfully") } - _, _, err = CreateBackup(ctx, c.Config.Global, c.Config.Backup, true) + var out []byte + _, out, err = CreateBackup(ctx, c.Config.Global, c.Config.Backup, true) if err != nil { - return errors.WithStack(fmt.Errorf("error while while running restic backup: %s", err.Error())) + return errors.WithStack(fmt.Errorf("error while while running restic backup: %s - %s", err.Error(), out)) } c.Logger.Info("successfully saved restic stuff") @@ -75,9 +76,9 @@ func (c *Client) DoResticBackup(ctx context.Context) error { func (c *Client) DoResticRestore(ctx context.Context, backupPath string) error { c.Logger.Info("running 'restic restore'") - _, err := RestoreBackup(ctx, c.Config.Global, c.Config.Restore, false) + out, err := RestoreBackup(ctx, c.Config.Global, c.Config.Restore, false) if err != nil { - return errors.WithStack(fmt.Errorf("error while while running restic restore: %s", err.Error())) + return errors.WithStack(fmt.Errorf("error while while running restic restore: %s - %s", err.Error(), out)) } return nil } diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index 8ac4322..9d12a69 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -58,14 +58,12 @@ func parseSnapshotOut(jsonLog []byte) (BackupResult, error) { var curSnapshotID string for idx := range responseList { v := responseList[idx] - if v[messageType] != nil { - if *v[messageType] == messageTypeSummary { - if v[snapshotID] != nil { - curSnapshotID = (*v[snapshotID]).(string) - } - if v[parentID] != nil { - parentSnapshotID = (*v[parentID]).(string) - } + if v[messageType] != nil && *v[messageType] == messageTypeSummary { + if v[snapshotID] != nil { + curSnapshotID = (*v[snapshotID]).(string) + } + if v[parentID] != nil { + parentSnapshotID = (*v[parentID]).(string) } } } @@ -109,7 +107,7 @@ func CreateBackup(ctx context.Context, globalOpts *GlobalOptions, backupOpts *Ba // transform output from restic into list of json elements out = []byte(fmt.Sprint("[" + - strings.Replace(strings.TrimRight(string(out), "\n"), "\n", ",", -1) + + strings.ReplaceAll(strings.TrimRight(string(out), "\n"), "\n", ",") + "]")) var backupRes BackupResult @@ -145,7 +143,7 @@ func Ls(ctx context.Context, glob *GlobalOptions, opts *LsOptions) ([]LsResult, } out = []byte(fmt.Sprint("[" + - strings.Replace(strings.TrimRight(string(out), "\n"), "\n", ",", -1) + + strings.ReplaceAll(strings.TrimRight(string(out), "\n"), "\n", ",") + "]")) var result []LsResult result, err = LsResponseFromJSON(out, opts) diff --git a/pkg/restic/types.go b/pkg/restic/types.go index 096b4ea..59f602f 100644 --- a/pkg/restic/types.go +++ b/pkg/restic/types.go @@ -9,16 +9,16 @@ type GlobalOptions struct { type GlobalFlags struct { CaCert string `flag:"--cacert"` CacheDir string `flag:"--cache-dir"` - CleanupCache bool `flag:"--cleanup-cache"` KeyHint string `flag:"--key-hint"` - LimitDownload int `flag:"--limit-download"` - LimitUpload int `flag:"--limit-upload"` - NoCache bool `flag:"--no-cache"` - NoLock bool `flag:"--no-lock"` PasswordFile string `flag:"--password-file"` Repo string `flag:"--repo"` RepositoryFile string `flag:"--repository-file"` TLSClientCert string `flag:"--tls-client-cert"` + LimitDownload int `flag:"--limit-download"` + LimitUpload int `flag:"--limit-upload"` + CleanupCache bool `flag:"--cleanup-cache"` + NoCache bool `flag:"--no-cache"` + NoLock bool `flag:"--no-lock"` } // BackupResult for cmd "restic backup" @@ -35,24 +35,24 @@ type BackupOptions struct { // BackupFlags for cmd: "restic backup" type BackupFlags struct { - Exclude []string `flag:"-e"` - ExcludeCaches bool `flag:"--exclude-caches"` - ExcludeFile string `flag:"--exclude-file"` - ExcludeLargerThan int `flag:"exclude-larger-than"` - FilesFromFile []string `flag:"--files-from file"` - FilesFromRaw []string `flag:"--files-from-raw file"` FilesFromVerbatim string `flag:"--files-from-verbatim file"` - Force bool `flag:"-f"` + ExcludeFile string `flag:"--exclude-file"` Host string `flag:"--host"` IexcludeFile string `flag:"--iexclude-file"` IexCludePattern string `flag:"--iexclude-pattern"` - IgnoreInode bool `flag:"--ignore-inode"` - OneFileSystem bool `flag:"-x"` Parent string `flag:"--parent"` - Stdin bool `flag:"--stdin"` StdinFilename string `flag:"--stdin-filename"` - Tags []string `flag:"--tag"` Time string `flag:"--time"` + Exclude []string `flag:"-e"` + FilesFromFile []string `flag:"--files-from file"` + FilesFromRaw []string `flag:"--files-from-raw file"` + Tags []string `flag:"--tag"` + ExcludeLargerThan int `flag:"exclude-larger-than"` + ExcludeCaches bool `flag:"--exclude-caches"` + Force bool `flag:"-f"` + IgnoreInode bool `flag:"--ignore-inode"` + OneFileSystem bool `flag:"-x"` + Stdin bool `flag:"--stdin"` WithAtime bool `flag:"--with-atime"` } diff --git a/pkg/source/backup.go b/pkg/source/backup.go index 320920e..1915384 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -59,7 +59,7 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe "cmd": "cleanup", }, ) - if err := backend.CleanUp(); err != nil { + if err = backend.CleanUp(); err != nil { cleanupLogger.WithError(err).Warn("failed to cleanup backup") } else { cleanupLogger.Info("successfully cleaned up backup") diff --git a/pkg/source/mongodump/cli.go b/pkg/source/mongodump/cli.go index cf814d2..21b133a 100644 --- a/pkg/source/mongodump/cli.go +++ b/pkg/source/mongodump/cli.go @@ -12,15 +12,10 @@ type Options struct { type Flags struct { URI string `flag:"--uri="` Host string `flag:"--host=" validate:"min=1"` - Port int `flag:"--port="` - IPv6 bool `flag:"--ipv6"` - Ssl bool `flag:"--ssl"` SslCAFile string `flag:"--sslCAFile="` SslPEMKeyFile string `flag:"--sslPEMKeyFile="` SslPEMKeyPassword string `flag:"--sslPEMKeyPassword="` SslCRLFile string `flag:"--sslCRLFile="` - SslAllowInvalidCertificates bool `flag:"--sslAllowInvalidCertificates"` - SslAllowInvalidHostnames bool `flag:"--sslAllowInvalidHostnames"` Username string `flag:"--username="` Password string `flag:"--password="` AuthenticationDatabase string `flag:"--authenticationDatabase="` @@ -32,14 +27,19 @@ type Flags struct { Query string `flag:"--query="` QueryFile string `flag:"--queryFile="` ReadPreference string `flag:"--readPreference="` - ForceTableScan bool `flag:"--forceTableScan"` - Gzip bool `flag:"--gzip"` Out string `flag:"--out="` Archive string `flag:"--archive="` - Oplog bool `flag:"--oplog"` - DumpDBUsersAndRoles bool `flag:"--dumpDbUsersAndRoles"` ExcludeCollection string `flag:"--excludeCollection="` ExcludeCollectionsWithPrefix string `flag:"--excludeCollectionsWithPrefix="` + Port int `flag:"--port="` NumParallelCollections int `flag:"--numParallelCollections="` + IPv6 bool `flag:"--ipv6"` + Ssl bool `flag:"--ssl"` + SslAllowInvalidCertificates bool `flag:"--sslAllowInvalidCertificates"` + SslAllowInvalidHostnames bool `flag:"--sslAllowInvalidHostnames"` + ForceTableScan bool `flag:"--forceTableScan"` + Gzip bool `flag:"--gzip"` + Oplog bool `flag:"--oplog"` + DumpDBUsersAndRoles bool `flag:"--dumpDbUsersAndRoles"` ViewsAsCollections bool `flag:"--viewsAsCollections"` } diff --git a/pkg/source/mongorestore/backend_config_based.go b/pkg/source/mongorestore/backend_config_based.go index 476502e..8cee522 100644 --- a/pkg/source/mongorestore/backend_config_based.go +++ b/pkg/source/mongorestore/backend_config_based.go @@ -49,7 +49,7 @@ func (b *ConfigBasedBackend) GetBackupPath() string { return b.cfg.Options.Flags.Archive } - return b.cfg.Options.Flags.Out + return b.cfg.Options.Flags.Dir } func (b *ConfigBasedBackend) GetHostname() string { diff --git a/pkg/source/mongorestore/cli.go b/pkg/source/mongorestore/cli.go index 765ba9c..277c364 100644 --- a/pkg/source/mongorestore/cli.go +++ b/pkg/source/mongorestore/cli.go @@ -12,14 +12,10 @@ type Options struct { type Flags struct { URI string `flag:"--uri="` Host string `flag:"--host=" validate:"min=1"` - Port int `flag:"--port="` - Ssl bool `flag:"--ssl"` SslCAFile string `flag:"--sslCAFile="` SslPEMKeyFile string `flag:"--sslPEMKeyFile="` SslPEMKeyPassword string `flag:"--sslPEMKeyPassword="` SslCRLFile string `flag:"--sslCRLFile="` - SslFIPSMode bool `flag:" --sslFIPSMode"` - TlSInsecure bool `flag:"--tlsInsecure"` Username string `flag:"--username="` Password string `flag:"--password="` AuthenticationDatabase string `flag:"--authenticationDatabase="` @@ -33,30 +29,33 @@ type Flags struct { NsFrom string `flag:"--nsFrom="` NsTo string `flag:"--nsTo="` ReadPreference string `flag:"--readPreference="` + OplogFile string `flag:"--oplogFile="` + Dir string `flag:"--dir="` + WriteConcern string `flag:"--writeConcern="` + Archive string `flag:"--archive="` + ExcludeCollection string `flag:"--excludeCollection="` + ExcludeCollectionsWithPrefix string `flag:"--excludeCollectionsWithPrefix="` + Port int `flag:"--port="` + OplogLimit int `flag:"--oplogLimit="` + NumInsertionWorkersPerCollection int `flag:"--numInsertionWorkersPerCollection="` + NumParallelCollections int `flag:"--numParallelCollections="` + Ssl bool `flag:"--ssl"` + SslFIPSMode bool `flag:" --sslFIPSMode"` + TlSInsecure bool `flag:"--tlsInsecure"` ForceTableScan bool `flag:"--forceTableScan"` Objcheck bool `flag:"--objcheck"` OplogReplay bool `flag:"--oplogReplay"` - OplogLimit int `flag:"--oplogLimit="` - OplogFile string `flag:"--oplogFile="` RestoreOnUsersAndRoles bool `flag:"--restoreDbUsersAndRoles"` - Dir string `flag:"--dir="` Drop bool `flag:"--drop"` DryRun bool `flag:"--dryRun"` - WriteConcern string `flag:"--writeConcern="` NoIndexRestore bool `flag:"--noIndexRestore"` ConvertLegacyIndexes bool `flag:"--convertLegacyIndexes"` NoOptionRestore bool `flag:"--noOptionsRestore"` KeepIndexVersion bool `flag:"--keepIndexVersion"` MaintainInsertionOrder bool `flag:"--maintainInsertionOrder"` - NumInsertionWorkersPerCollection int `flag:"--numInsertionWorkersPerCollection="` StopOnError bool `flag:"--stopOnError"` BypassDocumentValidation bool `flag:"--bypassDocumentValidation"` PreserveUUID bool `flag:"--preserveUUID"` FixDottedHashIndex bool `flag:"--fixDottedHashIndex"` Gzip bool `flag:"--gzip"` - Out string `flag:"--out="` - Archive string `flag:"--archive="` - ExcludeCollection string `flag:"--excludeCollection="` - ExcludeCollectionsWithPrefix string `flag:"--excludeCollectionsWithPrefix="` - NumParallelCollections int `flag:"--numParallelCollections="` } diff --git a/pkg/source/mongorestore/config.go b/pkg/source/mongorestore/config.go index c5c6a90..59ba50a 100644 --- a/pkg/source/mongorestore/config.go +++ b/pkg/source/mongorestore/config.go @@ -28,8 +28,8 @@ func (c *Config) InitFromViper() error { func configStructLevelValidation(sl validator.StructLevel) { c := sl.Current().Interface().(Config) - if c.Options.Flags.Out == "" && c.Options.Flags.Archive == "" { - sl.ReportError(c.Options.Flags.Out, "out", "Out", "eitherOutOrArchiveRequired", "") - sl.ReportError(c.Options.Flags.Archive, "archive", "Archive", "eitherOutOrArchiveRequired", "") + if c.Options.Flags.Dir == "" && c.Options.Flags.Archive == "" { + sl.ReportError(c.Options.Flags.Dir, "dir", "Dir", "eitherDirOrArchiveRequired", "") + sl.ReportError(c.Options.Flags.Archive, "archive", "Archive", "eitherDirOrArchiveRequired", "") } } diff --git a/pkg/source/mysqldump/cli.go b/pkg/source/mysqldump/cli.go index 8e4fb0f..40b438a 100644 --- a/pkg/source/mysqldump/cli.go +++ b/pkg/source/mysqldump/cli.go @@ -10,6 +10,52 @@ type Options struct { } type Flags struct { + BindAddress string `flag:"--bind-address="` + CharacterSetsDir string `flag:"--character-sets-dir="` + CompressAlgorithms string `flag:"--compression-algorithms="` + Debug string `flag:"--debug="` + DefaultAuth string `flag:"--default-auth="` + DefaultCharacterSet string `flag:"--default-character-set="` + DefaultsExtraFile string `flag:"--defaults-extra-file="` + DefaultsFile string `flag:"--defaults-file="` + DefaultsGroupSuffix string `flag:"--defaults-group-suffix="` + FieldsEnclosedBy string `flag:"--fields-enclosed-by="` + FieldsEscapedBy string `flag:"--fields-escaped-by="` + FieldsOptionallyEnclosedBy string `flag:"--fields-optionally-enclosed-by="` + FieldsTerminatedBy string `flag:"--fields-terminated-by="` + Host string `flag:"--host=" validate:"min=1"` + IgnoreError string `flag:"--ignore-error="` + IgnoreTable string `flag:"--ignore-table="` + LinesTerminatedBy string `flag:"--lines-terminated-by="` + LogError string `flag:"--log-error="` + LoginPath string `flag:"--login-path="` + MasterData string `flag:"--master-data="` + MaxAllowedPacket string `flag:"--max-allowed-packet="` + NetBufferLength string `flag:"--net-buffer-length="` + Password string `flag:"--password="` + PluginDir string `flag:"--plugin-dir="` + Protocol string `flag:"--protocol="` + ResultFile string `flag:"--result-file=" validate:"min=1"` + ServerPublicKeyPath string `flag:"--server-public-key-path="` + SharedMemoryBaseName string `flag:"--shared-memory-base-name="` + ShowCreateSkipSecondary string `flag:"--show-create-skip-secondary-engine="` + Socket string `flag:"--socket="` + SslCa string `flag:"--ssl-ca="` + SslCaPath string `flag:"--ssl-capath="` + SslCert string `flag:"--ssl-cert="` + SslCipher string `flag:"--ssl-cipher="` + SslCrl string `flag:"--ssl-crl="` + SslCrlPath string `flag:"--ssl-crlpath="` + SslKey string `flag:"--ssl-key="` + Tab string `flag:"--tab="` + TLSCipherSuites string `flag:"--tls-ciphersuites="` + TLSVersion string `flag:"--tls-version="` + User string `flag:"--user="` + Where string `flag:"--where"` + Databases []string `flag:"--databases"` + Tables []string `flag:"--tables"` + Port int `flag:"--port="` + ZstdCompressionLevel int `flag:"--zstd-compression-level"` AddDropDatabase bool `flag:"--add-drop-database"` AddDropTable bool `flag:"--add-drop-table"` AddDropTrigger bool `flag:"--add-drop-trigger"` @@ -17,25 +63,15 @@ type Flags struct { AllDatabases bool `flag:"--all-databases"` AllowKeywords bool `flag:"--allow-keywords"` ApplySlaveStatements bool `flag:"--apply-slave-statements"` - BindAddress string `flag:"--bind-address="` - CharacterSetsDir string `flag:"--character-sets-dir="` ColumnStatistics bool `flag:"--column-statistics"` Comments bool `flag:"--comments"` Compact bool `flag:"--compact"` Compatible bool `flag:"--compatible"` CompleteInsert bool `flag:"--complete-insert"` Compress bool `flag:"--compress"` - CompressAlgorithms string `flag:"--compression-algorithms="` CreateOptions bool `flag:"--create-options"` - Databases []string `flag:"--databases"` - Debug string `flag:"--debug="` DebugCheck bool `flag:"--debug-check"` DebugInfo bool `flag:"--debug-info"` - DefaultAuth string `flag:"--default-auth="` - DefaultCharacterSet string `flag:"--default-character-set="` - DefaultsExtraFile string `flag:"--defaults-extra-file="` - DefaultsFile string `flag:"--defaults-file="` - DefaultsGroupSuffix string `flag:"--defaults-group-suffix="` DeleteMasterLogs bool `flag:"--delete-master-logs"` DisableKeys bool `flag:"--disable-keys"` DumpDate bool `flag:"--dump-date"` @@ -43,28 +79,15 @@ type Flags struct { EnableCleartextPlugin bool `flag:"--enable-cleartext-plugin"` Events bool `flag:"--events"` ExtendedInsert bool `flag:"--extended-insert"` - FieldsEnclosedBy string `flag:"--fields-enclosed-by="` - FieldsEscapedBy string `flag:"--fields-escaped-by="` - FieldsOptionallyEnclosedBy string `flag:"--fields-optionally-enclosed-by="` - FieldsTerminatedBy string `flag:"--fields-terminated-by="` FlushLogs bool `flag:"--flush-logs"` FlushPrivileges bool `flag:"--flush-privileges"` Force bool `flag:"--force"` GetServerPublicKey bool `flag:"--get-server-public-key"` HexBlog bool `flag:"--hex-blob"` - Host string `flag:"--host=" validate:"min=1"` - IgnoreError string `flag:"--ignore-error="` - IgnoreTable string `flag:"--ignore-table="` IncludeMasterHostPort bool `flag:"--include-master-host-port"` InsertIgnore bool `flag:"--insert-ignore"` - LinesTerminatedBy string `flag:"--lines-terminated-by="` LockAllTables bool `flag:"--lock-all-tables"` LockTables bool `flag:"--lock-tables"` - LogError string `flag:"--log-error="` - LoginPath string `flag:"--login-path="` - MasterData string `flag:"--master-data="` - MaxAllowedPacket string `flag:"--max-allowed-packet="` - NetBufferLength string `flag:"--net-buffer-length="` NetworkTimeout bool `flag:"--network-timeout"` NoAutocommit bool `flag:"--no-autocommit"` NoCreateDB bool `flag:"--no-create-db"` @@ -75,21 +98,13 @@ type Flags struct { NoTablespaces bool `flag:"--no-tablespaces"` Opt bool `flag:"--opt"` OrderByPrimary bool `flag:"--order-by-primary"` - Password string `flag:"--password="` - PluginDir string `flag:"--plugin-dir="` - Port int `flag:"--port="` PrintDefaults bool `flag:"--print-defaults"` - Protocol string `flag:"--protocol="` Quick bool `flag:"--quick"` QuoteNames bool `flag:"--quote-names"` Replace bool `flag:"--replace"` - ResultFile string `flag:"--result-file=" validate:"min=1"` Routines bool `flag:"--routines"` - ServerPublicKeyPath string `flag:"--server-public-key-path="` SetCharset bool `flag:"--set-charset"` SetGtidPurged bool `flag:"--set-gtid-purged"` - SharedMemoryBaseName string `flag:"--shared-memory-base-name="` - ShowCreateSkipSecondary string `flag:"--show-create-skip-secondary-engine="` SingleTransaction bool `flag:"--single-transaction"` SkipAddDropTable bool `flag:"--skip-add-drop-table"` SkipAddLocks bool `flag:"--skip-add-locks"` @@ -103,23 +118,8 @@ type Flags struct { SkipSetCharset bool `flag:"--skip-set-charset"` SkipTriggers bool `flag:"--skip-triggers"` SkipTzUtc bool `flag:"--skip-tz-utc"` - Socket string `flag:"--socket="` - SslCa string `flag:"--ssl-ca="` - SslCaPath string `flag:"--ssl-capath="` - SslCert string `flag:"--ssl-cert="` - SslCipher string `flag:"--ssl-cipher="` - SslCrl string `flag:"--ssl-crl="` - SslCrlPath string `flag:"--ssl-crlpath="` SslFipsMode bool `flag:"--ssl-fips-mode"` - SslKey string `flag:"--ssl-key="` - Tab string `flag:"--tab="` - Tables []string `flag:"--tables"` - TLSCipherSuites string `flag:"--tls-ciphersuites="` - TLSVersion string `flag:"--tls-version="` Triggers bool `flag:"--triggers"` TzUtc bool `flag:"--tz-utc"` - User string `flag:"--user="` - Where string `flag:"--where"` XML bool `flag:"--xml"` - ZstdCompressionLevel int `flag:"--zstd-compression-level"` } diff --git a/pkg/source/mysqlrestore/cli.go b/pkg/source/mysqlrestore/cli.go index 5a8a44c..41cd0b6 100644 --- a/pkg/source/mysqlrestore/cli.go +++ b/pkg/source/mysqlrestore/cli.go @@ -11,71 +11,85 @@ type Options struct { } type Flags struct { + BindAddress string `flag:"--bind-address="` + CharacterSetsDir string `flag:"--character-sets-dir="` + CompressionAlgorithms string `flag:"--compression-algorithms="` + Database string `flag:"--database="` + Debug string `flag:"--debug="` + DefaultAuth string `flag:"--default-auth="` + DefaultCharacterSet string `flag:"--default-character-set="` + DefaultsExtraFile string `flag:"--defaults-extra-file="` + DefaultsFile string `flag:"--defaults-file="` + DefaultsGroupSuffix string `flag:"--defaults-group-suffix="` + Delimiter string `flag:"--delimiter="` + DNSSrvName string `flag:"--dns-srv-name"` + Execute string `flag:"--execute="` + Host string `flag:"--host=" validate:"min=1"` + InitCommand string `flag:"--init-command="` + LoadDataLocalDir string `flag:"--load-data-local-dir="` + LoginPath string `flag:"--login-path="` + MaxAllowedPacket string `flag:"--max-allowed-packet="` + NetworkNamespace string `flag:"--network-namespace"` + Pager string `flag:"--pager"` + Password string `flag:"--password="` + PluginDir string `flag:"--plugin-dir"` + Promtp string `flag:"--prompt="` + Protocol string `flag:"--protocol="` + ServerPublicKeyPath string `flag:"--server-public-key-path="` + SharedMemoryBaseName string `flag:"--shared-memory-base-name="` + Socket string `flag:"--socket="` + SslCa string `flag:"--ssl-ca="` + SslCaPath string `flag:"--ssl-capath="` + SslCert string `flag:"--ssl-cert="` + SslCipher string `flag:"--ssl-cipher="` + SslCrl string `flag:"--ssl-crl="` + SslCrlPath string `flag:"--ssl-crlpath="` + SslFipsMode string `flag:"--ssl-fips-mode"` + SslKey string `flag:"--ssl-key="` + Tee string `flag:"--tee="` + TLSCipherSuites string `flag:"--tls-ciphersuites="` + TLSVersion string `flag:"--tls-version="` + User string `flag:"--user="` + ConnectTimeout int `flag:"--connect-timeout"` + LocalInfile int `flag:"--local-infile"` + MaxJoinSize int `flag:"--max-join-size="` + NetBufferLength int `flag:"--net-buffer-length="` + Port int `flag:"--port="` + SelcetLimit int `flag:"--select-limit"` + ZstdCompressionLevel int `flag:"--zstd-compression-level="` AutoRehash bool `flag:"--auto-rehash"` AutoVerticalInput bool `flag:"--auto-vertical-output"` Batch bool `flag:"--batch"` BinaryAsHex bool `flag:"--binary-as-hex"` BinaryMode bool `flag:"--binary-mode"` - BindAddress string `flag:"--bind-address="` - CharacterSetsDir string `flag:"--character-sets-dir="` ColumnNames bool `flag:"--column-names"` ColumnTypeInfo bool `flag:"column-type-info"` Comments bool `flag:"--comments"` Compress bool `flag:"--compress"` - CompressionAlgorithms string `flag:"--compression-algorithms="` ConnectExpiredPassword bool `flag:"--connect-expired-password"` - ConnectTimeout int `flag:"--connect-timeout"` - Database string `flag:"--database="` - Debug string `flag:"--debug="` DebugCheck bool `flag:"--debug-check"` DebugInfo bool `flag:"--debug-info"` - DefaultAuth string `flag:"--default-auth="` - DefaultCharacterSet string `flag:"--default-character-set="` - DefaultsExtraFile string `flag:"--defaults-extra-file="` - DefaultsFile string `flag:"--defaults-file="` - DefaultsGroupSuffix string `flag:"--defaults-group-suffix="` - Delimiter string `flag:"--delimiter="` DisableNamedCommands bool `flag:"--disable-named-commands"` - DNSSrvName string `flag:"--dns-srv-name"` EnableCleartextPlugin bool `flag:"--enable-cleartext-plugin"` - Execute string `flag:"--execute="` Force bool `flaf:"--force"` GetServerPublicKey bool `flag:"--get-server-public-key"` Help bool `flag:"--help"` HistIgnore bool `flag:"--histignore"` - Host string `flag:"--host=" validate:"min=1"` HTML bool `flag:"--html"` IAmADummy bool `flag:"--i-am-a-dummy"` IgnoreSpaces bool `flag:"--ignore-spaces"` - InitCommand string `flag:"--init-command="` LineNumbers bool `flag:"--line-numbers"` - LoadDataLocalDir string `flag:"--load-data-local-dir="` - LocalInfile int `flag:"--local-infile"` - LoginPath string `flag:"--login-path="` - MaxAllowedPacket string `flag:"--max-allowed-packet="` - MaxJoinSize int `flag:"--max-join-size="` NamedCommands bool `flag:"--named-commands"` - NetBufferLength int `flag:"--net-buffer-length="` - NetworkNamespace string `flag:"--network-namespace"` NoAutoRehash bool `flag:"--no-auto-rehash"` NoBeep bool `flag:"--no-beep"` NoDefaults bool `flag:"--no-defaults"` OneDatabase bool `flag:"--one-database"` - Pager string `flag:"--pager"` - Password string `flag:"--password="` Pipe bool `flag:"--pipe"` - PluginDir string `flag:"--plugin-dir"` - Port int `flag:"--port="` PrintDefaults bool `flag:"--print-defaults"` - Promtp string `flag:"--prompt="` - Protocol string `flag:"--protocol="` Quick bool `flag:"--quick"` Raw bool `flag:"--raw"` Reconnect bool `flag:"--reconnect"` SafeUpdates bool `flag:"--safe-updates"` - SelcetLimit int `flag:"--select-limit"` - ServerPublicKeyPath string `flag:"--server-public-key-path="` - SharedMemoryBaseName string `flag:"--shared-memory-base-name="` ShowWarning bool `flag:"--show-warnings"` SigintIgnore bool `flag:"--sigint-ignore"` Silent bool `flag:"--silent"` @@ -85,26 +99,12 @@ type Flags struct { SkipNamedCommands bool `flags:"--skip-named-commands"` SkipPager bool `flag:"--skip-pager"` SkipReconnect bool `flag:"--skip-reconnect"` - Socket string `flag:"--socket="` - SslCa string `flag:"--ssl-ca="` - SslCaPath string `flag:"--ssl-capath="` - SslCert string `flag:"--ssl-cert="` - SslCipher string `flag:"--ssl-cipher="` - SslCrl string `flag:"--ssl-crl="` - SslCrlPath string `flag:"--ssl-crlpath="` - SslFipsMode string `flag:"--ssl-fips-mode"` - SslKey string `flag:"--ssl-key="` Syslog bool `flag:"--syslog"` Table bool `flag:"--table"` - Tee string `flag:"--tee="` - TLSCipherSuites string `flag:"--tls-ciphersuites="` - TLSVersion string `flag:"--tls-version="` Unbuffered bool `flag:"--unbuffered"` - User string `flag:"--user="` Verbose bool `flag:"--verbose"` Version bool `flag:"--version"` Vertical bool `flag:"--vertical"` Wait bool `flag:"--wait"` XML bool `flag:"--xml"` - ZstdCompressionLevel int `flag:"--zstd-compression-level="` } diff --git a/pkg/source/pgdump/cli.go b/pkg/source/pgdump/cli.go index 3d02b73..2d35fec 100644 --- a/pkg/source/pgdump/cli.go +++ b/pkg/source/pgdump/cli.go @@ -10,33 +10,44 @@ type Options struct { } type Flags struct { - File string `flag:"--file="` - Format string `flag:"--format="` + File string `flag:"--file="` + Format string `flag:"--format="` + LockWaitTimeout string `flag:"--lock-wait-timeout="` + Encoding string `flag:"--encoding="` + Schema string `flag:"--schema="` + ExcludeSchema string `flag:"--exclude-schema="` + Superuser string `flag:"--superuser="` + Table string `flag:"--table="` + ExcludeTable string `flag:"--exclude-table="` + ExcludeTableData string `flag:"--exclude-table-data="` + Section string `flag:"--section="` + Snapshots string `flag:"--snapshot="` + DBName string `flag:"--dbname="` + Host string `flag:"--host="` + Username string `flag:"--username="` + // unfortunately pg_dump has no cli-option to specify the password + // therefore we have to workaround by setting the corresponding password env-var + Password string `flag:"-" env:"PGPASSWORD"` + Role string `flag:"--role="` Jobs int `flag:"--jobs="` - Verbose bool `flag:"--verbose"` Compress int `flag:"--compress="` - LockWaitTimeout string `flag:"--lock-wait-timeout="` + ExtraFloatDigits int `flag:"--extra-float-digits="` + RowsPerInsert int `flag:"--rows-per-insert="` + Port int `flag:"--port="` + Verbose bool `flag:"--verbose"` NoSync bool `flag:"--no-sync"` DataOnly bool `flag:"--data-only"` Blobs bool `flag:"--blobs"` Clean bool `flag:"--clean"` Create bool `flag:"--create"` - Encoding string `flag:"--encoding="` - Schema string `flag:"--schema="` - ExcludeSchema string `flag:"--exclude-schema="` NoOwner bool `flag:"--no-owner"` SchemaOnly bool `flag:"--schema-only"` - Superuser string `flag:"--superuser="` - Table string `flag:"--table="` - ExcludeTable string `flag:"--exclude-table="` NoPrivileges bool `flag:"--no-privileges"` BinaryUpgrade bool `flag:"--binary-upgrade"` ColumnInserts bool `flag:"--column-inserts"` DisableDollarQuoting bool `flag:"--disable-dollar-quoting"` DisableTriggers bool `flag:"--disable-triggers"` EnableRowSecurity bool `flag:"--enable-row-security"` - ExcludeTableData string `flag:"--exclude-table-data="` - ExtraFloatDigits int `flag:"--extra-float-digits="` IfExists bool `flag:"--if-exists"` Inserts bool `flag:"--inserts"` LoadViaPartitionRoot bool `flag:"--load-via-partition-root"` @@ -49,19 +60,8 @@ type Flags struct { NoUnloggedTableData bool `flag:"--no-unlogged-table-data"` OnConflictDoNothing bool `flag:"--on-conflict-do-nothing"` QuoteAllIdentifiers bool `flag:"--quote-all-identifiers"` - RowsPerInsert int `flag:"--rows-per-insert="` - Section string `flag:"--section="` SerializableDeferrable bool `flag:"--serializable-deferrable"` - Snapshots string `flag:"--snapshot="` StrictNames bool `flag:"--strict-names"` UseSetSessionAuthorization bool `flag:"--use-set-session-authorization"` - DBName string `flag:"--dbname="` - Host string `flag:"--host="` - Port int `flag:"--port="` - Username string `flag:"--username="` NoPassword bool `flag:"--no-password"` - // unfortunately pg_dump has no cli-option to specify the password - // therefore we have to workaround by setting the corresponding password env-var - Password string `flag:"-" env:"PGPASSWORD"` - Role string `flag:"--role="` } diff --git a/pkg/source/pgrestore/cli.go b/pkg/source/pgrestore/cli.go index 400a76a..eb41474 100644 --- a/pkg/source/pgrestore/cli.go +++ b/pkg/source/pgrestore/cli.go @@ -13,50 +13,50 @@ type Options struct { } type Flags struct { - BinaryUpgrade bool `flag:"--binary-upgrade"` - Blobs bool `flag:"--blobs"` - Clean bool `flag:"--clean"` - ColumnInserts bool `flag:"--column-inserts"` - Compress int `flag:"--compress="` - Create bool `flag:"--create"` - DataOnly bool `flag:"--data-only"` - DBName string `flag:"--dbname="` - DisableTriggers bool `flag:"--disable-triggers"` - ExitOnError bool `flag:"--exit-on-error"` - File string `flag:"--file="` - Format string `flag:"--format="` - Function string `flag:"--function="` - Host string `flag:"--host="` - IgnoreVersion bool `flag:"--ignore-version"` - Index string `flag:"--index="` - Inserts bool `flag:"--inserts"` - Jobs int `flag:"--jobs="` - List bool `flag:"--list"` - ListFile string `flag:"--use-List="` - LoadViaPartitionRoot bool `flag:"--load-via-partition-root"` - LockWaitTimeout string `flag:"--lock-wait-timeout="` - NoACL bool `flag:"--no-acl"` - NoComments bool `flag:"--no-comments"` - NoDataForFailedTables bool `flag:"--no-data-for-failed-tables"` - NoOwner bool `flag:"--no-owner"` - NoPassword bool `flag:"--no-password"` - NoPrivileges bool `flag:"--no-privileges"` - NoReconnect bool `flag:"--no-reconnect"` - NoSecurityLabels bool `flag:"--no-security-labels"` - NoTablespaces bool `flag:"--no-tablespaces"` - // unfortunately pg_dump has no cli-option to specify the password + DBName string `flag:"--dbname="` + File string `flag:"--file="` + Format string `flag:"--format="` + Function string `flag:"--function="` + Host string `flag:"--host="` + Index string `flag:"--index="` + ListFile string `flag:"--use-List="` + LockWaitTimeout string `flag:"--lock-wait-timeout="` + // unfortunately pg_restore has no cli-option to specify the password // therefore we have to workaround by setting the corresponding password env-var Password string `flag:"-" env:"PGPASSWORD"` - Port int `flag:"--port="` - QuoteAllIdentifiers bool `flag:"--quote-all-identifiers"` Role string `flag:"--role="` Schema string `flag:"--schema="` - SchemaOnly bool `flag:"--schema-only"` Section string `flag:"--section="` Superuser string `flag:"--superuser="` Table string `flag:"--table="` Trigger string `flag:"--trigger="` Username string `flag:"--username="` + Compress int `flag:"--compress="` + Jobs int `flag:"--jobs="` + Port int `flag:"--port="` + BinaryUpgrade bool `flag:"--binary-upgrade"` + Blobs bool `flag:"--blobs"` + Clean bool `flag:"--clean"` + ColumnInserts bool `flag:"--column-inserts"` + Create bool `flag:"--create"` + DataOnly bool `flag:"--data-only"` + DisableTriggers bool `flag:"--disable-triggers"` + ExitOnError bool `flag:"--exit-on-error"` + IgnoreVersion bool `flag:"--ignore-version"` + Inserts bool `flag:"--inserts"` + List bool `flag:"--list"` + LoadViaPartitionRoot bool `flag:"--load-via-partition-root"` + NoACL bool `flag:"--no-acl"` + NoComments bool `flag:"--no-comments"` + NoDataForFailedTables bool `flag:"--no-data-for-failed-tables"` + NoOwner bool `flag:"--no-owner"` + NoPassword bool `flag:"--no-password"` + NoPrivileges bool `flag:"--no-privileges"` + NoReconnect bool `flag:"--no-reconnect"` + NoSecurityLabels bool `flag:"--no-security-labels"` + NoTablespaces bool `flag:"--no-tablespaces"` + QuoteAllIdentifiers bool `flag:"--quote-all-identifiers"` + SchemaOnly bool `flag:"--schema-only"` UseSetSessionAuthorization bool `flag:"--use-set-session-authorization"` Verbose bool `flag:"--verbose"` } diff --git a/pkg/source/psql/cli.go b/pkg/source/psql/cli.go index 44b122f..4014ee8 100644 --- a/pkg/source/psql/cli.go +++ b/pkg/source/psql/cli.go @@ -14,35 +14,35 @@ type Options struct { type Flags struct { Command string `flag:"--command="` Dbname string `flag:"--dbname="` + FieldSeparator string `flag:"--field-separator="` + File string `flag:"--file="` + Host string `flag:"--host=" validate:"min=1"` + LogFile string `flag:"--log-file="` + Output string `flag:"--output="` + Password string `flag:"-" env:"PGPASSWORD"` + Pset string `flag:"--pset="` + RecordSeparator string `flag:"--record-separator="` + Set string `flag:"--set="` + TableAttr string `flag:"--table-attr="` + User string `flag:"--username="` + Variable string `flag:"--variable="` + Port int `flag:"--port="` EchoAll bool `flag:"--echo-all"` EchoHidden bool `flag:"--echo-hidden"` EchoQueries bool `flag:"--echo-queries"` Expanded bool `flag:"--expanded"` - FieldSeparator string `flag:"--field-separator="` FieldSeparatorZero bool `flag:"--field-separator-zero"` - File string `flag:"--file="` - Host string `flag:"--host=" validate:"min=1"` HTML bool `flag:"--html"` List bool `flag:"--list"` - LogFile string `flag:"--log-file="` NoAllign bool `flag:"--no-align"` NoPassword bool `flag:"--no-password"` NoPsqlrc bool `flag:"--no-psqlrc"` NoReafline bool `flag:"--no-readline"` - Output string `flag:"--output="` - Password string `flag:"-" env:"PGPASSWORD"` - Port int `flag:"--port="` - Pset string `flag:"--pset="` Quiet bool `flag:"--quiet"` - RecordSeparator string `flag:"--record-separator="` RecordSeparatorZero bool `flag:"--record-separator-zero"` SingleLine bool `flag:"--single-line"` SingleStep bool `flag:"--single-step"` SingleTransaction bool `flag:"--single-transaction"` - Set string `flag:"--set="` - TableAttr string `flag:"--table-attr="` TuplesOnly bool `flag:"--tuples-only"` - User string `flag:"--username="` - Variable string `flag:"--variable="` Version bool `flsg:"--version"` } diff --git a/pkg/source/redisdump/cli.go b/pkg/source/redisdump/cli.go index 20405b7..9dfed6c 100644 --- a/pkg/source/redisdump/cli.go +++ b/pkg/source/redisdump/cli.go @@ -11,40 +11,40 @@ type Options struct { } type Flags struct { - Bigkeys bool `flag:"--bigKeys"` Cluster string `flag:"--cluster="` - ClusterMode bool `flag:"-c"` - Csv bool `flag:"--csv"` - DatabaseNumber int `flag:"-n"` Delimiter string `flag:"-d"` Eval string `flag:"--eval="` Host string `flag:"-h" validate:"min=1"` - Hotkeys bool `flag:"--hotkeys"` + LruTest string `flag:"--lru-test="` + Password string `flag:"-a"` + Pattern string `flag:"--pattern="` + Rdb string `flag:"--rdb" validate:"min=1"` + Socket string `flag:"-s"` + URI string `flag:"-u"` + DatabaseNumber int `flag:"-n"` Interval int `flag:"-i"` IntrinsicLatency int `flag:"--intrinsic-latency="` + MemkeysSamples int `flag:"--memkeys-samples="` + PipeTimeout int `flag:"--pipe-timeout="` + Port int `flag:"-p"` + Repeat int `flag:"-r"` + Bigkeys bool `flag:"--bigKeys"` + ClusterMode bool `flag:"-c"` + Csv bool `flag:"--csv"` + Hotkeys bool `flag:"--hotkeys"` Latency bool `flag:"--latency"` LatencyDist bool `flag:"latency-dist"` LatencyHistory bool `flag:"--latency-history"` Ldb bool `flag:"--ldb"` LdbSyncMode bool `flag:"--ldb-sync-mode"` - LruTest string `flag:"--lru-test="` Memkeys bool `flag:"--memkeys"` - MemkeysSamples int `flag:"--memkeys-samples="` NoAuthWarning bool `flag:"--no-auth-warning"` NoRaw bool `flag:"--no-raw"` - Password string `flag:"-a"` - Pattern string `flag:"--pattern="` Pipe bool `flag:"--pipe"` - PipeTimeout int `flag:"--pipe-timeout="` - Port int `flag:"-p"` Raw bool `flag:"--raw"` - Rdb string `flag:"--rdb" validate:"min=1"` ReadStdin bool `flag:"-x"` - Repeat int `flag:"-r"` Replica bool `flag:"--replica"` Scan bool `flag:"--scan"` - Socket string `flag:"-s"` Stat bool `flag:"--stat"` - URI string `flag:"-u"` Verbose bool `flag:"--verbose"` } diff --git a/pkg/source/restore.go b/pkg/source/restore.go index c99d26d..e415f81 100644 --- a/pkg/source/restore.go +++ b/pkg/source/restore.go @@ -43,7 +43,7 @@ func DoRestoreForKind(ctx context.Context, kind string, cleanup, useRestic, useR return err } - if useRestic { + if useRestic { // nolint: nestif var resticClient *restic.Client resticClient, err = restic.NewResticClient(logKind, backend.GetHostname(), backend.GetBackupPath()) if err != nil { diff --git a/pkg/source/tar/cli.go b/pkg/source/tar/cli.go index f96db35..7a689c3 100644 --- a/pkg/source/tar/cli.go +++ b/pkg/source/tar/cli.go @@ -11,14 +11,14 @@ type Options struct { } type Flags struct { + Target string `flag:"-C"` + File string `flag:"-f" validate:"min=1"` + Warning []string `flag:"--warning"` + Exclude []string `flag:"--exclude"` + StripComponents int `flag:"--strip-components="` Create bool `flag:"-c"` Gzip bool `flag:"-z"` Extract bool `flag:"-x"` - StripComponents int `flag:"--strip-components="` Overwrite bool `flag:"--overwrite"` NoOverwriteDir bool `flag:"--no-overwrite-dir"` - Warning []string `flag:"--warning"` - Exclude []string `flag:"--exclude"` - Target string `flag:"-C"` - File string `flag:"-f" validate:"min=1"` } diff --git a/pkg/source/tarrestore/cli.go b/pkg/source/tarrestore/cli.go index e8aa5fd..4060665 100644 --- a/pkg/source/tarrestore/cli.go +++ b/pkg/source/tarrestore/cli.go @@ -11,14 +11,14 @@ type Options struct { } type Flags struct { + Target string `flag:"-C"` + File string `flag:"-f" validate:"min=1"` + Warning []string `flag:"--warning"` + Exclude []string `flag:"--exclude"` + StripComponents int `flag:"--strip-components="` Create bool `flag:"-c"` Gzip bool `flag:"-z"` Extract bool `flag:"-x"` - StripComponents int `flag:"--strip-components="` Overwrite bool `flag:"--overwrite"` NoOverwriteDir bool `flag:"--no-overwrite-dir"` - Warning []string `flag:"--warning"` - Exclude []string `flag:"--exclude"` - Target string `flag:"-C"` - File string `flag:"-f" validate:"min=1"` } diff --git a/test/pkg/source/internal/testcommons.go b/test/pkg/source/internal/testcommons.go index e9ddb32..f13edc0 100644 --- a/test/pkg/source/internal/testcommons.go +++ b/test/pkg/source/internal/testcommons.go @@ -3,12 +3,13 @@ package internal import ( "context" "fmt" - "github.com/pkg/errors" - "github.com/spf13/viper" "os" "os/exec" "strings" + "github.com/pkg/errors" + "github.com/spf13/viper" + "github.com/docker/go-connections/nat" "github.com/testcontainers/testcontainers-go" ) @@ -69,8 +70,9 @@ func TestSetup() { // DoResticRestore pulls the given backup from the given restic repo func DoResticRestore(ctx context.Context, resticContainer TestContainerSetup, dataDir string) error { - cmd := exec.CommandContext(ctx, "restic", "restore", "-r", fmt.Sprintf("rest:http://%s:%s/", - resticContainer.Address, resticContainer.Port), + cmd := exec.CommandContext(ctx, "restic", "restore", "-r", // nolint: gosec + fmt.Sprintf("rest:http://%s:%s/", + resticContainer.Address, resticContainer.Port), "--target", dataDir, "latest") out, err := cmd.CombinedOutput() if err != nil {