Skip to content

Commit

Permalink
Minor fixes to support SSE
Browse files Browse the repository at this point in the history
  • Loading branch information
pshima committed Aug 25, 2016
1 parent ebe61c4 commit 8a78a44
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.2
* Add hostname to backup file
* Add optional prefix configured via env var
* Add optional SSE for S3 backups

## 0.2.1
* Bug fix for restore path

Expand Down
24 changes: 12 additions & 12 deletions backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,7 @@ func (b *Backup) writeBackupRemote() {

t := time.Unix(b.StartTime, 0)

if b.Config.ObjectPrefix == "" {
objectPrefix = "backups"
} else {
objectPrefix = b.Config.ObjectPrefix
}

b.RemoteFilePath = fmt.Sprintf("%s/%v/%d/%v/%v", objectPrefix, t.Year(), t.Month(), t.Day(), filepath.Base(b.FullFilename))
b.RemoteFilePath = fmt.Sprintf("%s/%v/%d/%v/%v", b.Config.ObjectPrefix, t.Year(), t.Month(), t.Day(), filepath.Base(b.FullFilename))

// re-read the compressed file. There is probably a better way to do this
localFileContents, err := ioutil.ReadFile(b.FullFilename)
Expand All @@ -320,11 +314,17 @@ func (b *Backup) writeBackupRemote() {

// Create the params to pass into the actual uploader
params := &s3manager.UploadInput{
Bucket: &b.Config.S3Bucket,
Key: &b.RemoteFilePath,
Body: bytes.NewReader(localFileContents),
ServerSideEncryption: &b.Config.S3ServerSideEncryption,
SSEKMSKeyId: &b.Config.S3KmsKeyID,
Bucket: &b.Config.S3Bucket,
Key: &b.RemoteFilePath,
Body: bytes.NewReader(localFileContents),
}

if b.Config.S3ServerSideEncryption != "" {
params.ServerSideEncryption = &b.Config.S3ServerSideEncryption
}

if b.Config.S3KmsKeyID != "" {
params.SSEKMSKeyId = &b.Config.S3KmsKeyID
}

log.Printf("[INFO] Uploading %v/%v to S3 in %v", string(b.Config.S3Bucket), b.RemoteFilePath, string(b.Config.S3Region))
Expand Down
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func setEnvVars(conf *Config, tests bool) error {
conf.TmpDir = "/tmp"
}

// If no prefix is set, set the bucket prefix to "/backups"
if conf.ObjectPrefix == "" {
conf.ObjectPrefix = "backups"
}

// If no backup interval is set, set it to 60s as a string which is converted
// to a time.Duration
if backupInterval == "" {
backupInterval = "60"
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
version = "0.2.1"
version = "0.2.2"
)

func main() {
Expand Down

0 comments on commit 8a78a44

Please sign in to comment.