Skip to content

Commit 94e1456

Browse files
authored
Merge pull request #10 from swisscom/master
bump
2 parents 8994772 + dd545b1 commit 94e1456

File tree

936 files changed

+108774
-17347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

936 files changed

+108774
-17347
lines changed

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ RUN echo "debconf debconf/frontend select noninteractive" | debconf-set-selectio
55
export DEBIAN_FRONTEND=noninteractive && \
66
apt-get -y $package_args update && \
77
apt-get -y $package_args dist-upgrade && \
8-
apt-get -y $package_args install curl ca-certificates gnupg tzdata golang git
8+
apt-get -y $package_args install curl ca-certificates gnupg tzdata git
9+
RUN curl --location --output go.tar.gz "https://golang.org/dl/go1.16.3.linux-amd64.tar.gz" && \
10+
echo "951a3c7c6ce4e56ad883f97d9db74d3d6d80d5fec77455c6ada6c1f7ac4776d2 go.tar.gz" | sha256sum -c && \
11+
tar -C /usr/local -xzf go.tar.gz && \
12+
rm go.tar.gz
13+
14+
ENV PATH=$PATH:/usr/local/go/bin
915

1016
WORKDIR /go/src/github.com/swisscom/backman
1117
COPY . .
@@ -27,7 +33,7 @@ RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
2733
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.4.list
2834
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
2935
RUN apt-get -y $package_args update && \
30-
apt-get -y $package_args install mysql-client postgresql-client-12 mongodb-org-tools=4.4.0 mongodb-org-shell=4.4.0 redis-tools nodejs openssh-server bash vim && \
36+
apt-get -y $package_args install mysql-client postgresql-client-12 mongodb-org-tools=4.4.5 mongodb-org-shell=4.4.5 redis-tools nodejs openssh-server bash vim && \
3137
apt-get clean && \
3238
find /usr/share/doc/*/* ! -name copyright | xargs rm -rf && \
3339
rm -rf \

config/config.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ type ServiceConfig struct {
4444
Days int
4545
Files int
4646
}
47-
DisableColumnStatistics bool `json:"disable_column_statistics"`
48-
ForceImport bool `json:"force_import"`
49-
LocalBackupPath string `json:"local_backup_path"`
47+
DisableColumnStatistics bool `json:"disable_column_statistics"`
48+
ForceImport bool `json:"force_import"`
49+
LocalBackupPath string `json:"local_backup_path"`
50+
BackupOptions []string `json:"backup_options"`
51+
RestoreOptions []string `json:"restore_options"`
5052
}
5153

5254
type TimeoutDuration struct {
@@ -170,6 +172,12 @@ func Get() *Config {
170172
if len(serviceConfig.LocalBackupPath) > 0 {
171173
mergedServiceConfig.LocalBackupPath = serviceConfig.LocalBackupPath
172174
}
175+
if len(serviceConfig.BackupOptions) > 0 {
176+
mergedServiceConfig.BackupOptions = serviceConfig.BackupOptions
177+
}
178+
if len(serviceConfig.RestoreOptions) > 0 {
179+
mergedServiceConfig.RestoreOptions = serviceConfig.RestoreOptions
180+
}
173181
config.Services[serviceName] = mergedServiceConfig
174182
}
175183
}

go.mod

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
module github.com/swisscom/backman
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/cloudfoundry-community/go-cfenv v1.18.0
77
github.com/dustin/go-humanize v1.0.0
8-
github.com/hako/durafmt v0.0.0-20190612201238-650ed9f29a84
9-
github.com/labstack/echo/v4 v4.1.6
10-
github.com/minio/minio-go/v6 v6.0.33
11-
github.com/minio/sio v0.2.0
12-
github.com/prometheus/client_golang v1.1.0
8+
github.com/golang/protobuf v1.5.2 // indirect
9+
github.com/hako/durafmt v0.0.0-20210316092057-3a2c319c1acd
10+
github.com/klauspost/cpuid/v2 v2.0.6 // indirect
11+
github.com/labstack/echo/v4 v4.2.2
12+
github.com/mattn/go-colorable v0.1.8 // indirect
13+
github.com/minio/md5-simd v1.1.2 // indirect
14+
github.com/minio/minio-go/v6 v6.0.57
15+
github.com/minio/sha256-simd v1.0.0 // indirect
16+
github.com/minio/sio v0.2.1
17+
github.com/mitchellh/mapstructure v1.4.1 // indirect
18+
github.com/prometheus/client_golang v1.10.0
19+
github.com/prometheus/common v0.20.0 // indirect
1320
github.com/robfig/cron v1.2.0
14-
github.com/sirupsen/logrus v1.4.2
21+
github.com/sirupsen/logrus v1.8.1
1522
github.com/stretchr/testify v1.6.1 // indirect
16-
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b
23+
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
24+
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1 // indirect
25+
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 // indirect
26+
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
27+
gopkg.in/ini.v1 v1.62.0 // indirect
1728
)

go.sum

Lines changed: 388 additions & 58 deletions
Large diffs are not rendered by default.

manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ applications:
2323

2424
# ### push either as docker image
2525
docker:
26-
image: jamesclonk/backman:1.26.0 # choose version from https://hub.docker.com/r/jamesclonk/backman/tags, or 'latest'
26+
image: jamesclonk/backman:1.27.2 # choose version from https://hub.docker.com/r/jamesclonk/backman/tags, or 'latest'
2727
# ### or as buildpack/src
2828
# buildpacks:
2929
# - https://github.com/cloudfoundry/apt-buildpack

router/api/backup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (h *Handler) GetBackup(c echo.Context) error {
107107
// schemes: http, https
108108
//
109109
// responses:
110-
// 202:
110+
// 202: service
111111
func (h *Handler) CreateBackup(c echo.Context) error {
112112
serviceType := c.Param("service_type")
113113
serviceName, err := url.QueryUnescape(c.Param("service_name"))
@@ -132,7 +132,7 @@ func (h *Handler) CreateBackup(c echo.Context) error {
132132
log.Errorf("requested backup for service [%s] failed: %v", serviceName, err)
133133
}
134134
}()
135-
return c.JSON(http.StatusAccepted, nil)
135+
return c.JSON(http.StatusAccepted, cfService)
136136
}
137137

138138
// swagger:route GET /api/v1/backup/{service_type}/{service_name}/{filename}/download backup downloadBackup

router/api/restore.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/swisscom/backman/service/util"
1111
)
1212

13-
// swagger:route POST /api/v1/restore/{service_type}/{service_name} restore restoreBackup
13+
// swagger:route POST /api/v1/restore/{service_type}/{service_name}/{filename} restore restoreBackup
1414
// Triggers a restore for given service.
1515
//
1616
// produces:
@@ -19,7 +19,7 @@ import (
1919
// schemes: http, https
2020
//
2121
// responses:
22-
// 202:
22+
// 202: service
2323
func (h *Handler) RestoreBackup(c echo.Context) error {
2424
serviceType := c.Param("service_type")
2525
serviceName, err := url.QueryUnescape(c.Param("service_name"))
@@ -64,5 +64,8 @@ func (h *Handler) RestoreBackup(c echo.Context) error {
6464
log.Errorf("requested restore for service [%s] failed: %v", serviceName, err)
6565
}
6666
}()
67-
return c.JSON(http.StatusAccepted, nil)
67+
if len(targetService.Name) > 0 {
68+
return c.JSON(http.StatusAccepted, targetService)
69+
}
70+
return c.JSON(http.StatusAccepted, cfService)
6871
}

service/elasticsearch/backup.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
2929
esMutex.Lock()
3030
defer esMutex.Unlock()
3131

32-
state.BackupStart(service)
32+
state.BackupStart(service, filename)
3333

3434
host, _ := binding.CredentialString("host")
3535
username, _ := binding.CredentialString("full_access_username")
@@ -58,7 +58,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
5858
outPipe, err := cmd.StdoutPipe()
5959
if err != nil {
6060
log.Errorf("could not get stdout pipe for elasticdump: %v", err)
61-
state.BackupFailure(service)
61+
state.BackupFailure(service, filename)
6262
return err
6363
}
6464
defer outPipe.Close()
@@ -94,7 +94,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
9494
err = s3.UploadWithContext(uploadCtx, objectPath, pr, -1)
9595
if err != nil {
9696
log.Errorf("could not upload service backup [%s] to S3: %v", service.Name, err)
97-
state.BackupFailure(service)
97+
state.BackupFailure(service, filename)
9898
}
9999
}()
100100
time.Sleep(2 * time.Second) // wait for upload goroutine to be ready
@@ -105,12 +105,12 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
105105

106106
if err := cmd.Start(); err != nil {
107107
log.Errorf("could not run elasticdump: %v", err)
108-
state.BackupFailure(service)
108+
state.BackupFailure(service, filename)
109109
return err
110110
}
111111

112112
if err := cmd.Wait(); err != nil {
113-
state.BackupFailure(service)
113+
state.BackupFailure(service, filename)
114114
// check for timeout error
115115
if ctx.Err() == context.DeadlineExceeded {
116116
return fmt.Errorf("elasticdump: timeout: %v", ctx.Err())
@@ -122,7 +122,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
122122

123123
uploadWait.Wait() // wait for upload to have finished
124124
if err == nil {
125-
state.BackupSuccess(service)
125+
state.BackupSuccess(service, filename)
126126
}
127127
return err
128128
}

service/elasticsearch/restore.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"os"
1010
"os/exec"
11+
"path/filepath"
1112
"strings"
1213

1314
"github.com/cloudfoundry-community/go-cfenv"
@@ -24,7 +25,8 @@ func Restore(ctx context.Context, s3 *s3.Client, service util.Service, binding *
2425
esMutex.Lock()
2526
defer esMutex.Unlock()
2627

27-
state.RestoreStart(service)
28+
filename := filepath.Base(objectPath)
29+
state.RestoreStart(service, filename)
2830

2931
host, _ := binding.CredentialString("host")
3032
username, _ := binding.CredentialString("full_access_username")
@@ -56,14 +58,14 @@ func Restore(ctx context.Context, s3 *s3.Client, service util.Service, binding *
5658
reader, err := s3.DownloadWithContext(downloadCtx, objectPath)
5759
if err != nil {
5860
log.Errorf("could not download service backup [%s] from S3: %v", service.Name, err)
59-
state.RestoreFailure(service)
61+
state.RestoreFailure(service, filename)
6062
return err
6163
}
6264
defer reader.Close()
6365
gr, err := gzip.NewReader(reader)
6466
if err != nil {
6567
log.Errorf("could not open gzip reader: %v", err)
66-
state.RestoreFailure(service)
68+
state.RestoreFailure(service, filename)
6769
return err
6870
}
6971
defer gr.Close()
@@ -75,12 +77,12 @@ func Restore(ctx context.Context, s3 *s3.Client, service util.Service, binding *
7577

7678
if err := cmd.Start(); err != nil {
7779
log.Errorf("could not run elasticsearch restore: %v", err)
78-
state.RestoreFailure(service)
80+
state.RestoreFailure(service, filename)
7981
return err
8082
}
8183

8284
if err := cmd.Wait(); err != nil {
83-
state.RestoreFailure(service)
85+
state.RestoreFailure(service, filename)
8486
// check for timeout error
8587
if ctx.Err() == context.DeadlineExceeded {
8688
return fmt.Errorf("elasticsearch restore: timeout: %v", ctx.Err())
@@ -89,7 +91,7 @@ func Restore(ctx context.Context, s3 *s3.Client, service util.Service, binding *
8991
}
9092

9193
if err == nil {
92-
state.RestoreSuccess(service)
94+
state.RestoreSuccess(service, filename)
9395
}
9496
return err
9597
}

service/mongodb/backup.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
2828
mongoMutex.Lock()
2929
defer mongoMutex.Unlock()
3030

31-
state.BackupStart(service)
31+
state.BackupStart(service, filename)
3232

3333
uri, _ := binding.CredentialString("uri")
3434

@@ -49,7 +49,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
4949
outPipe, err := cmd.StdoutPipe()
5050
if err != nil {
5151
log.Errorf("could not get stdout pipe for mongodump: %v", err)
52-
state.BackupFailure(service)
52+
state.BackupFailure(service, filename)
5353
return err
5454
}
5555
defer outPipe.Close()
@@ -75,7 +75,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
7575
err = s3.UploadWithContext(uploadCtx, objectPath, pr, -1)
7676
if err != nil {
7777
log.Errorf("could not upload service backup [%s] to S3: %v", service.Name, err)
78-
state.BackupFailure(service)
78+
state.BackupFailure(service, filename)
7979
}
8080
}()
8181
time.Sleep(2 * time.Second) // wait for upload goroutine to be ready
@@ -86,12 +86,12 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
8686

8787
if err := cmd.Start(); err != nil {
8888
log.Errorf("could not run mongodump: %v", err)
89-
state.BackupFailure(service)
89+
state.BackupFailure(service, filename)
9090
return err
9191
}
9292

9393
if err := cmd.Wait(); err != nil {
94-
state.BackupFailure(service)
94+
state.BackupFailure(service, filename)
9595
// check for timeout error
9696
if ctx.Err() == context.DeadlineExceeded {
9797
return fmt.Errorf("mongodump: timeout: %v", ctx.Err())
@@ -103,7 +103,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c
103103

104104
uploadWait.Wait() // wait for upload to have finished
105105
if err == nil {
106-
state.BackupSuccess(service)
106+
state.BackupSuccess(service, filename)
107107
}
108108
return err
109109
}

0 commit comments

Comments
 (0)