diff --git a/README.md b/README.md index 4fd8a7a..5c96b44 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Parameters: - `schedule`: cronjob schedule. Example: `0 * * * *` - `retention`: max retention. Example: `2d`, `1w`, `1M`, `720h` - `timeout`: mongodb dump timeout +- `tmpPath`: path to store tempory backup before s3 upload - `mongodb`: - `host`: MongoDB host - `port`: MongoDB port @@ -55,6 +56,7 @@ name: integration retention: 1w schedule: '0 0 * * *' timeout: 15m +tmpPath: /tmp mongodb: host: localhost port: 27017 diff --git a/k8s/configmap.yaml b/k8s/configmap.yaml index 4f116ab..d09944c 100644 --- a/k8s/configmap.yaml +++ b/k8s/configmap.yaml @@ -10,6 +10,7 @@ data: retention: 1w schedule: '0 0 * * *' timeout: 15m + tmpPath: /tmp mongodb: host: localhost port: 27017 diff --git a/pkg/config/plan.go b/pkg/config/plan.go index f044538..07cf9ad 100644 --- a/pkg/config/plan.go +++ b/pkg/config/plan.go @@ -2,18 +2,20 @@ package config import ( "errors" - "gopkg.in/yaml.v2" "io/ioutil" "os" + + "gopkg.in/yaml.v2" ) type Plan struct { - Name string `json:"name"` - Schedule string `json:"schedule"` - Retention string `json:"retention"` - Timeout string `json:"timeout"` - MongoDB MongoDB `json:"mongodb"` - Bucket Bucket `json:"buckets"` + Name string `json:"name"` + Schedule string `json:"schedule"` + Retention string `json:"retention"` + Timeout string `json:"timeout"` + TmpPath string `json:"tmpPath"` + MongoDB MongoDB `json:"mongodb"` + Bucket Bucket `json:"buckets"` } type Bucket struct { @@ -22,7 +24,7 @@ type Bucket struct { } type S3 struct { - Name string `json:"name"` + Name string `json:"name"` Region string `json:"region"` } type GS struct { @@ -34,8 +36,6 @@ type MongoDB struct { Port string `json:"port"` } - - func (plan *Plan) GetPlan(filename string) (*Plan, error) { _, err := os.Stat(filename) if err != nil { diff --git a/pkg/mongodb/dump.go b/pkg/mongodb/dump.go index 31b179d..731153a 100644 --- a/pkg/mongodb/dump.go +++ b/pkg/mongodb/dump.go @@ -2,26 +2,27 @@ package mongodb import ( "fmt" + "path" + "time" + "github.com/codeskyblue/go-sh" "github.com/neo9/mongodb-backups/pkg/config" "github.com/neo9/mongodb-backups/pkg/utils" "github.com/prometheus/common/log" - "path" - "time" ) type MongoDBDump struct { ArchiveFile string - LogFile string - Duration float64 + LogFile string + Duration float64 } func CreateDump(plan *config.Plan) (MongoDBDump, error) { dumpName := getDumpName() - outputFile := path.Join("/tmp", dumpName) + outputFile := path.Join(plan.TmpPath, dumpName) mongoDBDump := MongoDBDump{ ArchiveFile: outputFile + ".gz", - LogFile: outputFile + ".log", + LogFile: outputFile + ".log", } authArgs := getAuthenticationArguments() @@ -44,7 +45,6 @@ func CreateDump(plan *config.Plan) (MongoDBDump, error) { CombinedOutput() mongoDBDump.Duration = time.Since(startTime).Seconds() - if err != nil { log.Errorf("Error creating dump: %v, %s", err, output) log.Errorf("Dump timeout: %s", duration) @@ -64,4 +64,3 @@ func CreateDump(plan *config.Plan) (MongoDBDump, error) { func getDumpName() string { return fmt.Sprintf("mongodb-snapshot-%d", time.Now().Unix()) } -