From 217ff8f57ccd082a2e89e1a10b9502facf844a4c Mon Sep 17 00:00:00 2001 From: Manfred Schuller Date: Wed, 18 Nov 2020 16:25:53 +0100 Subject: [PATCH] localfs first skeleton --- Makefile | 13 +++++++-- cmd/internal/database/localfs/localfs.go | 35 ++++++++++++++++++++++++ cmd/main.go | 10 ++++++- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 cmd/internal/database/localfs/localfs.go diff --git a/Makefile b/Makefile index 5143474..9a0f7e8 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,22 @@ GO111MODULE := on CGO_ENABLED := 1 -LINKMODE := -extldflags '-static -s -w' +EXTLDFLAGS := -extldflags '-static -s -w' DOCKER_TAG := $(or ${GITHUB_TAG_NAME}, latest) BACKUP_PROVIDER := $(or ${BACKUP_PROVIDER},local) +SHA := $(shell git rev-parse --short=8 HEAD) +GITVERSION := $(shell git describe --long --all) +BUILDDATE := $(shell date -Iseconds) +VERSION := $(or ${VERSION},devel) .PHONY: all all: go mod tidy - go build -ldflags "$(LINKMODE)" -tags 'osusergo netgo static_build' -o bin/backup-restore-sidecar github.com/metal-stack/backup-restore-sidecar/cmd + go build -ldflags "-X 'github.com/metal-stack/v.Version=$(VERSION)' \ + -X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \ + -X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \ + -X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)' \ + $(EXTLDFLAGS)" \ + -tags 'osusergo netgo static_build' -o bin/backup-restore-sidecar github.com/metal-stack/backup-restore-sidecar/cmd strip bin/backup-restore-sidecar .PHONY: proto diff --git a/cmd/internal/database/localfs/localfs.go b/cmd/internal/database/localfs/localfs.go new file mode 100644 index 0000000..7ee4d22 --- /dev/null +++ b/cmd/internal/database/localfs/localfs.go @@ -0,0 +1,35 @@ +package localfs + +import "go.uber.org/zap" + +type LocalFS struct { + datadir string + log *zap.SugaredLogger +} + +func New(log *zap.SugaredLogger, datadir string) *LocalFS { + return &LocalFS{ + datadir: datadir, + log: log, + } +} + +func (l *LocalFS) Check() (bool, error) { + //ToDo: check if Datadir empty -> true + return true, nil +} + +func (l *LocalFS) Backup() error { + //ToDo: put Datadir into compressed archive + return nil +} + +func (l *LocalFS) Recover() error { + //ToDo: decompress archive into Datadir + return nil +} + +func (l *LocalFS) Probe() error { + //Nothing to do, not a real Database + return nil +} diff --git a/cmd/main.go b/cmd/main.go index dcabda1..52da103 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,6 +7,8 @@ import ( "os" "strings" + "github.com/metal-stack/backup-restore-sidecar/cmd/internal/database/localfs" + "github.com/metal-stack/backup-restore-sidecar/cmd/internal/backup" "github.com/metal-stack/backup-restore-sidecar/cmd/internal/backup/providers" "github.com/metal-stack/backup-restore-sidecar/cmd/internal/backup/providers/gcp" @@ -188,7 +190,7 @@ func init() { rootCmd.AddCommand(startCmd, waitCmd, restoreCmd) rootCmd.PersistentFlags().StringP(logLevelFlg, "", "info", "sets the application log level") - rootCmd.PersistentFlags().StringP(databaseFlg, "", "", "the kind of the database [postgres|rethinkdb]") + rootCmd.PersistentFlags().StringP(databaseFlg, "", "", "the kind of the database [postgres|rethinkdb|localfs]") rootCmd.PersistentFlags().StringP(databaseDatadirFlg, "", "", "the directory where the database stores its data in") err := viper.BindPFlags(rootCmd.PersistentFlags()) @@ -323,6 +325,12 @@ func initDatabase() error { viper.GetString(rethinkDBURLFlg), viper.GetString(rethinkDBPasswordFileFlg), ) + case "localfs": + db = localfs.New( + logger.Named("localfs"), + datadir, + ) + default: return fmt.Errorf("unsupported database type: %s", dbString) }