Skip to content

Commit

Permalink
localfs first skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuller committed Nov 18, 2020
1 parent c6f172d commit 217ff8f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions cmd/internal/database/localfs/localfs.go
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 9 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 217ff8f

Please sign in to comment.