Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added abstract helper interface for all storage backends #135

Merged
merged 32 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aaa8098
Added abstract helper interface and implemented it for all storage ba…
MaxJa4 Jul 21, 2022
2ac2fd9
Moved storage client initializations also to helper classes
MaxJa4 Jul 21, 2022
3ceda07
Fixed ssh init issue
MaxJa4 Jul 21, 2022
6ae3acc
Moved script parameter to helper struct to simplify script init.
MaxJa4 Jul 21, 2022
5842ff1
Created sub modules. Enhanced abstract implementation.
MaxJa4 Jul 22, 2022
7104600
Fixed config issue
MaxJa4 Jul 22, 2022
195f61a
Fixed declaration issues. Added config to interface.
MaxJa4 Jul 22, 2022
d28b1ed
Added StorageProviders to unify all backends.
MaxJa4 Jul 22, 2022
d60ed9d
Cleanup, optimizations, comments.
MaxJa4 Jul 22, 2022
2c0e56b
Applied discussed changes. See description.
MaxJa4 Jul 24, 2022
6df4ef0
Fix docker build issue
MaxJa4 Jul 24, 2022
0947709
Fixed accidentally removed local copy condition.
MaxJa4 Jul 24, 2022
068a124
Delete .gitignore
MaxJa4 Jul 24, 2022
2d85858
Renaming/changes according to review
MaxJa4 Jul 24, 2022
ce43201
Fixed auto-complete error.
MaxJa4 Jul 24, 2022
01e40fd
Combined copy instructions into one layer.
MaxJa4 Jul 25, 2022
76826bb
Added logging func for storages.
MaxJa4 Jul 25, 2022
d0a4ade
Introduced logging func for errors too.
MaxJa4 Jul 25, 2022
fbc7a4b
Missed an error message
MaxJa4 Jul 25, 2022
b34cc4a
Moved config back to main. Optimized prune stats handling.
MaxJa4 Jul 29, 2022
b0fd3c7
Move stats back to main package
MaxJa4 Aug 5, 2022
3eac5e4
Code doc stuff
MaxJa4 Aug 5, 2022
3df59b5
Apply changes from #136
MaxJa4 Aug 15, 2022
344db2f
Replace name field with function.
MaxJa4 Aug 15, 2022
0f569f3
Changed receiver names from stg to b.
MaxJa4 Aug 15, 2022
70f18aa
Renamed LogFuncDef to Log
MaxJa4 Aug 15, 2022
17f19b9
Removed redundant package name.
MaxJa4 Aug 15, 2022
e69e327
Renamed storagePool to storages.
MaxJa4 Aug 15, 2022
0efa7fd
Simplified creation of new storage backend.
MaxJa4 Aug 15, 2022
847a72e
Added initialization for storage stats map.
MaxJa4 Aug 15, 2022
03c98d9
Invert .dockerignore patterns.
MaxJa4 Aug 15, 2022
b7f644b
Fix package typo
MaxJa4 Aug 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
test
# Ignore everything
*

# Exceptions:
# Note: Wildcards for directories like * or ** don't work (yet) with exclamation marks!

!cmd/backup/*.go
!cmd/backup/*.tmpl

!internal/storage/*.go
!internal/storage/local/*.go
!internal/storage/s3/*.go
!internal/storage/ssh/*.go
!internal/storage/webdav/*.go
!internal/utilities/*.go

!Dockerfile
!entrypoint.sh
!go.*
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
FROM golang:1.18-alpine as builder

WORKDIR /app
COPY go.mod go.sum ./
COPY . .
RUN go mod download
COPY cmd/backup ./cmd/backup/
WORKDIR /app/cmd/backup
RUN go build -o backup .

Expand Down
18 changes: 9 additions & 9 deletions cmd/backup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import (
// Config holds all configuration values that are expected to be set
// by users.
type Config struct {
AwsS3BucketName string `split_words:"true"`
AwsS3Path string `split_words:"true"`
AwsEndpoint string `split_words:"true" default:"s3.amazonaws.com"`
AwsEndpointProto string `split_words:"true" default:"https"`
AwsEndpointInsecure bool `split_words:"true"`
AwsStorageClass string `split_words:"true"`
AwsAccessKeyID string `envconfig:"AWS_ACCESS_KEY_ID"`
AwsSecretAccessKey string `split_words:"true"`
AwsIamRoleEndpoint string `split_words:"true"`
BackupSources string `split_words:"true" default:"/backup"`
BackupFilename string `split_words:"true" default:"backup-%Y-%m-%dT%H-%M-%S.tar.gz"`
BackupFilenameExpand bool `split_words:"true"`
Expand All @@ -23,15 +32,6 @@ type Config struct {
BackupStopContainerLabel string `split_words:"true" default:"true"`
BackupFromSnapshot bool `split_words:"true"`
BackupExcludeRegexp RegexpDecoder `split_words:"true"`
AwsS3BucketName string `split_words:"true"`
AwsS3Path string `split_words:"true"`
AwsEndpoint string `split_words:"true" default:"s3.amazonaws.com"`
AwsEndpointProto string `split_words:"true" default:"https"`
AwsEndpointInsecure bool `split_words:"true"`
AwsStorageClass string `split_words:"true"`
AwsAccessKeyID string `envconfig:"AWS_ACCESS_KEY_ID"`
AwsSecretAccessKey string `split_words:"true"`
AwsIamRoleEndpoint string `split_words:"true"`
GpgPassphrase string `split_words:"true"`
NotificationURLs []string `envconfig:"NOTIFICATION_URLS"`
NotificationLevel string `split_words:"true" default:"error"`
Expand Down
4 changes: 3 additions & 1 deletion cmd/backup/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package main
import (
"fmt"
"sort"

"github.com/offen/docker-volume-backup/internal/utilities"
)

// hook contains a queued action that can be trigger them when the script
Expand Down Expand Up @@ -50,7 +52,7 @@ func (s *script) runHooks(err error) error {
}
}
if len(actionErrors) != 0 {
return join(actionErrors...)
return utilities.Join(actionErrors...)
}
return nil
}
5 changes: 3 additions & 2 deletions cmd/backup/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/gofrs/flock"
"github.com/offen/docker-volume-backup/internal/utilities"
)

// lock opens a lockfile at the given location, keeping it locked until the
Expand All @@ -31,7 +32,7 @@ func (s *script) lock(lockfile string) (func() error, error) {
for {
acquired, err := fileLock.TryLock()
if err != nil {
return noop, fmt.Errorf("lock: error trying lock: %w", err)
return utilities.Noop, fmt.Errorf("lock: error trying lock: %w", err)
}
if acquired {
if s.encounteredLock {
Expand All @@ -52,7 +53,7 @@ func (s *script) lock(lockfile string) (func() error, error) {
case <-retry.C:
continue
case <-deadline.C:
return noop, errors.New("lock: timed out waiting for lockfile to become available")
return utilities.Noop, errors.New("lock: timed out waiting for lockfile to become available")
}
}
}
3 changes: 2 additions & 1 deletion cmd/backup/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

sTypes "github.com/containrrr/shoutrrr/pkg/types"
"github.com/offen/docker-volume-backup/internal/utilities"
)

//go:embed notifications.tmpl
Expand Down Expand Up @@ -68,7 +69,7 @@ func (s *script) sendNotification(title, body string) error {
}
}
if len(errs) != 0 {
return fmt.Errorf("sendNotification: error sending message: %w", join(errs...))
return fmt.Errorf("sendNotification: error sending message: %w", utilities.Join(errs...))
}
return nil
}
Expand Down
Loading