Skip to content

Commit

Permalink
Merge pull request #7 from neo9/feat/tmp-path
Browse files Browse the repository at this point in the history
config: Add variable to choose tmpPath
  • Loading branch information
maximeancellin authored Jul 30, 2021
2 parents 77de4c2 + b079717 commit 4b22dba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,6 +56,7 @@ name: integration
retention: 1w
schedule: '0 0 * * *'
timeout: 15m
tmpPath: /tmp
mongodb:
host: localhost
port: 27017
Expand Down
1 change: 1 addition & 0 deletions k8s/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data:
retention: 1w
schedule: '0 0 * * *'
timeout: 15m
tmpPath: /tmp
mongodb:
host: localhost
port: 27017
Expand Down
20 changes: 10 additions & 10 deletions pkg/config/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
15 changes: 7 additions & 8 deletions pkg/mongodb/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -64,4 +64,3 @@ func CreateDump(plan *config.Plan) (MongoDBDump, error) {
func getDumpName() string {
return fmt.Sprintf("mongodb-snapshot-%d", time.Now().Unix())
}

0 comments on commit 4b22dba

Please sign in to comment.