Skip to content

Commit a2f1731

Browse files
committed
Snapshotter type for encapsulating different types of snapshot streams
1 parent db8cf3f commit a2f1731

9 files changed

Lines changed: 132 additions & 87 deletions

File tree

cmd/ubackup/backup.go

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import (
1010
"github.com/function61/ubackup/pkg/ubbackup"
1111
"github.com/function61/ubackup/pkg/ubconfig"
1212
"github.com/function61/ubackup/pkg/ubtypes"
13-
"io"
1413
"log"
1514
"os"
16-
"os/exec"
1715
)
1816

1917
func runBackup(ctx context.Context, logger *log.Logger) error {
@@ -76,31 +74,28 @@ func runBackup(ctx context.Context, logger *log.Logger) error {
7674
for _, containerTarget := range containerTargets {
7775
if err := ubbackup.BackupAndStore(
7876
ctx,
79-
ubtypes.BackupForTarget(containerTarget.BackupTarget),
77+
ubtypes.BackupForTarget(containerTarget),
8078
*conf,
81-
containerTarget.Produce,
8279
logger,
8380
); err != nil {
84-
handleOneFailure(containerTarget.BackupTarget, err)
81+
handleOneFailure(containerTarget, err)
8582
}
8683
}
8784
}
8885

8986
for _, staticTarget := range conf.StaticTargets {
90-
staticTarget := staticTarget // pin
87+
target := ubtypes.BackupTarget{
88+
ServiceName: staticTarget.ServiceName,
89+
Snapshotter: newCommandOutputSnapshotter(staticTarget.BackupCommand, ""),
90+
}
9191

9292
if err := ubbackup.BackupAndStore(
9393
ctx,
94-
ubtypes.BackupForTarget(staticTarget),
94+
ubtypes.BackupForTarget(target),
9595
*conf,
96-
func(backupSink io.Writer) error {
97-
return copyCommandStdout(
98-
exec.Command(staticTarget.BackupCommand[0], staticTarget.BackupCommand[1:]...),
99-
backupSink)
100-
},
10196
logger,
10297
); err != nil {
103-
handleOneFailure(staticTarget, err)
98+
handleOneFailure(target, err)
10499
}
105100
}
106101

@@ -130,28 +125,6 @@ func runBackup(ctx context.Context, logger *log.Logger) error {
130125
return nil
131126
}
132127

133-
func copyCommandStdout(cmd *exec.Cmd, backupSink io.Writer) error {
134-
cmd.Stderr = os.Stderr
135-
stdout, err := cmd.StdoutPipe()
136-
if err != nil {
137-
return err
138-
}
139-
140-
if err := cmd.Start(); err != nil {
141-
return err
142-
}
143-
144-
if _, err := io.Copy(backupSink, stdout); err != nil {
145-
return err
146-
}
147-
148-
if err := cmd.Wait(); err != nil {
149-
return err
150-
}
151-
152-
return nil
153-
}
154-
155128
type alertSubjectsFactory struct {
156129
hostname string
157130
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/function61/ubackup/pkg/ubtypes"
6+
"io"
7+
"os"
8+
"os/exec"
9+
)
10+
11+
type commandOutputSnapshotter struct {
12+
command []string
13+
dir string
14+
}
15+
16+
func newCommandOutputSnapshotter(command []string, dir string) ubtypes.Snapshotter {
17+
return &commandOutputSnapshotter{command, dir}
18+
}
19+
20+
func (c *commandOutputSnapshotter) Describe() string {
21+
return fmt.Sprintf("command: %v", c.command)
22+
}
23+
24+
func (c *commandOutputSnapshotter) CreateSnapshot(backupSink io.Writer) error {
25+
command := exec.Command(c.command[0], c.command[1:]...)
26+
command.Dir = c.dir // if empty, current workdir will be used
27+
command.Stderr = os.Stderr
28+
29+
stdout, err := command.StdoutPipe()
30+
if err != nil {
31+
return err
32+
}
33+
34+
if err := command.Start(); err != nil {
35+
return err
36+
}
37+
38+
if _, err := io.Copy(backupSink, stdout); err != nil {
39+
return err
40+
}
41+
42+
return command.Wait()
43+
}

cmd/ubackup/dockerdiscovery.go

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,16 @@ import (
77
"github.com/function61/gokit/ezhttp"
88
"github.com/function61/gokit/udocker"
99
"github.com/function61/ubackup/pkg/ubtypes"
10-
"io"
1110
"net/http"
12-
"os/exec"
1311
"strings"
1412
)
1513

1614
const (
1715
backupCommandEnvKey = "BACKUP_COMMAND"
1816
)
1917

20-
type DockerTarget struct {
21-
BackupTarget ubtypes.BackupTarget
22-
Produce func(backupSink io.Writer) error
23-
}
24-
2518
// returns containers that have ENV var "BACKUP_COMMAND" defined
26-
func dockerDiscoverBackupTargets(ctx context.Context, dockerEndpoint string) ([]DockerTarget, error) {
19+
func dockerDiscoverBackupTargets(ctx context.Context, dockerEndpoint string) ([]ubtypes.BackupTarget, error) {
2720
dockerClient, base, err := udocker.Client(dockerEndpoint, nil, false)
2821
if err != nil {
2922
return nil, fmt.Errorf("udocker.Client: %v", err)
@@ -48,7 +41,7 @@ func dockerDiscoverBackupTargets(ctx context.Context, dockerEndpoint string) ([]
4841
return nil, err
4942
}
5043

51-
targets := []DockerTarget{}
44+
targets := []ubtypes.BackupTarget{}
5245

5346
for _, inspected := range inspecteds {
5447
foundBackupCommand := ""
@@ -69,32 +62,24 @@ func dockerDiscoverBackupTargets(ctx context.Context, dockerEndpoint string) ([]
6962
serviceName = "none"
7063
}
7164

72-
// FIXME
65+
// Docker CLI truncates ids to this long. using same here to shorten filenames
66+
taskId := inspected.Id[0:12]
67+
68+
// FIXME: this doesn't support spaces..
7369
backupCommandParsed := strings.Split(foundBackupCommand, " ")
7470

75-
target := ubtypes.BackupTarget{
76-
ServiceName: serviceName,
77-
TaskId: inspected.Id[0:12], // Docker CLI truncates ids to this long. using same here to shorten filenames
78-
BackupCommand: backupCommandParsed,
79-
}
71+
dockerExecCmd := append([]string{
72+
"docker",
73+
"exec",
74+
taskId,
75+
}, backupCommandParsed...)
8076

81-
producer := func(target ubtypes.BackupTarget) func(io.Writer) error {
82-
return func(backupSink io.Writer) error {
83-
dockerExecCmd := append([]string{
84-
"docker",
85-
"exec",
86-
target.TaskId,
87-
}, target.BackupCommand...)
88-
89-
return copyCommandStdout(
90-
exec.Command(dockerExecCmd[0], dockerExecCmd[1:]...),
91-
backupSink)
92-
}
93-
}(target)
77+
snapshotter := newCommandOutputSnapshotter(dockerExecCmd, "")
9478

95-
targets = append(targets, DockerTarget{
96-
Produce: producer,
97-
BackupTarget: target,
79+
targets = append(targets, ubtypes.BackupTarget{
80+
ServiceName: serviceName,
81+
TaskId: taskId,
82+
Snapshotter: snapshotter,
9883
})
9984
}
10085

cmd/ubackup/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ func manualEntry() *cobra.Command {
6161
}
6262
}
6363

64-
backup := ubtypes.BackupForTarget(ubtypes.BackupTarget{
64+
backup := ubtypes.BackupTarget{
6565
ServiceName: serviceName,
6666
TaskId: taskId,
67-
})
67+
Snapshotter: ubtypes.CustomStream(backupStream),
68+
}
6869

69-
return ubbackup.BackupAndStore(ctx, backup, *conf, func(backupSink io.Writer) error {
70-
_, err := io.Copy(backupSink, backupStream)
71-
return err
72-
}, logger)
70+
return ubbackup.BackupAndStore(
71+
ctx,
72+
ubtypes.BackupForTarget(backup),
73+
*conf,
74+
logger)
7375
}
7476

7577
return &cobra.Command{

go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
66
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
77
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
88
github.com/apcera/termtables v0.0.0-20170405184538-bcbc5dc54055/go.mod h1:8mHYHlOef9UC51cK1/WRvE/iQVM8O8QlYFa8eh8r5I8=
9+
github.com/apex/gateway v1.1.1 h1:dPE3y2LQ/fSJuZikCOvekqXLyn/Wrbgt10MSECobH/Q=
910
github.com/apex/gateway v1.1.1/go.mod h1:x7iPY22zu9D8sfrynawEwh1wZEO/kQTRaOM5ye02tWU=
1011
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
1112
github.com/aws/aws-lambda-go v1.13.2/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
13+
github.com/aws/aws-lambda-go v1.14.0 h1:kTr1VPabIgJsMVzHuZpNhs/5RR46LU6wyWUiHxtb3ag=
1214
github.com/aws/aws-lambda-go v1.14.0/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
1315
github.com/aws/aws-sdk-go v1.16.15 h1:kQyxfRyjAwIYjf0225sn/pn+WAlncKyI8dmT3+ItMFE=
1416
github.com/aws/aws-sdk-go v1.16.15/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
1517
github.com/aws/aws-sdk-go v1.29.0 h1:UFxrMQhDyLak6kVtOcr4PZxNRQV0s7pY/vKAyzRvi8c=
1618
github.com/aws/aws-sdk-go v1.29.0/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
1719
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
1820
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
21+
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
1922
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
2023
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
24+
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
2125
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
26+
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
2227
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
2328
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
2429
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
@@ -33,6 +38,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
3338
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3439
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3540
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
41+
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
3642
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
3743
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
3844
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -59,6 +65,7 @@ github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4er
5965
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
6066
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6167
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
68+
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
6269
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6370
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
6471
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -70,6 +77,7 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
7077
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
7178
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
7279
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
80+
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
7381
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
7482
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
7583
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
@@ -91,6 +99,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
9199
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
92100
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
93101
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
102+
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
94103
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
95104
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
96105
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
@@ -100,30 +109,36 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
100109
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
101110
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
102111
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
112+
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
103113
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
104114
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
105115
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
106116
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
117+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
107118
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
108119
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
109120
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
110121
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
111122
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
112123
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
113124
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
125+
github.com/prometheus/client_golang v1.4.1 h1:FFSuS004yOQEtDdTq+TAOLP5xUq63KqAFYyOi8zA+Y8=
114126
github.com/prometheus/client_golang v1.4.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
115127
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
116128
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
129+
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
117130
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
118131
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
119132
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
120133
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
121134
github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc=
135+
github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U=
122136
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
123137
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
124138
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
125139
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
126140
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
141+
github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8=
127142
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
128143
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
129144
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=

pkg/ubbackup/backup.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ func BackupAndStore(
2020
ctx context.Context,
2121
backup ubtypes.Backup,
2222
conf ubconfig.Config,
23-
produce func(io.Writer) error,
2423
logger *log.Logger,
2524
) error {
2625
logl := logex.Levels(logex.Prefix(backup.Target.ServiceName, logger))
2726

2827
logl.Info.Printf("starting (%s)", backup.Target.TaskId)
2928

30-
logl.Debug.Printf("command: %v", backup.Target.BackupCommand)
29+
logl.Debug.Printf("snapshotter: %s", backup.Target.Snapshotter.Describe())
3130

3231
// we've to create a temp file because some storages (I'm looking at you, S3) need a seekable reader
3332
tempFile, err := ioutil.TempFile("", "ubackup")
@@ -52,7 +51,7 @@ func BackupAndStore(
5251

5352
snapshotStartedAt := time.Now()
5453

55-
if err := produce(backupWriter); err != nil {
54+
if err := backup.Target.Snapshotter.CreateSnapshot(backupWriter); err != nil {
5655
return fmt.Errorf("snapshot failed (in %s): %v", time.Since(snapshotStartedAt), err)
5756
}
5857

pkg/ubconfig/config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import (
44
"bytes"
55
"github.com/function61/gokit/envvar"
66
"github.com/function61/gokit/jsonfile"
7-
"github.com/function61/ubackup/pkg/ubtypes"
87
)
98

109
type Config struct {
11-
EncryptionPublicKey string `json:"encryption_publickey"`
12-
DockerEndpoint *string `json:"docker_endpoint,omitempty"`
13-
StaticTargets []ubtypes.BackupTarget `json:"static_targets"`
14-
Storage StorageConfig `json:"storage"`
15-
AlertManager *AlertManagerConfig `json:"alertmanager,omitempty"`
10+
EncryptionPublicKey string `json:"encryption_publickey"`
11+
DockerEndpoint *string `json:"docker_endpoint,omitempty"`
12+
StaticTargets []StaticTarget `json:"static_targets"`
13+
Storage StorageConfig `json:"storage"`
14+
AlertManager *AlertManagerConfig `json:"alertmanager,omitempty"`
15+
}
16+
17+
type StaticTarget struct {
18+
ServiceName string `json:"service_name"`
19+
BackupCommand []string `json:"backup_command"`
1620
}
1721

1822
type StorageConfig struct {

pkg/ubconfig/defaultconfig.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package ubconfig
22

33
import (
44
"github.com/aws/aws-sdk-go/aws/endpoints"
5-
"github.com/function61/ubackup/pkg/ubtypes"
65
"io/ioutil"
76
)
87

@@ -20,7 +19,7 @@ func DefaultConfig(pubkeyFilePath string, kitchenSink bool) *Config {
2019

2120
dockerEndpoint := "unix:///var/run/docker.sock"
2221

23-
staticTargets := []ubtypes.BackupTarget{}
22+
staticTargets := []StaticTarget{}
2423

2524
var alertManager *AlertManagerConfig
2625

@@ -31,7 +30,7 @@ MIIBCgKCAQEA+xGZ/wcz9ugFpP07Nspo...
3130
-----END RSA PUBLIC KEY-----`
3231
}
3332

34-
staticTargets = append(staticTargets, ubtypes.BackupTarget{
33+
staticTargets = append(staticTargets, StaticTarget{
3534
ServiceName: "someapp",
3635
BackupCommand: []string{"cat", "/var/lib/someapp/file.log"},
3736
})

0 commit comments

Comments
 (0)