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

config: Add variable to choose tmpPath #7

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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())
}