From e7f2271a6ae5b651a78398bedc2cee904ef583e4 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Thu, 6 Jun 2019 18:27:32 -0700 Subject: [PATCH] Use gzip compression in backups. --- ee/backup/backup.go | 8 +++++++- ee/backup/run.go | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ee/backup/backup.go b/ee/backup/backup.go index a27561d3479..b38ba9c5513 100644 --- a/ee/backup/backup.go +++ b/ee/backup/backup.go @@ -13,6 +13,7 @@ package backup import ( + "compress/gzip" "context" "encoding/json" "fmt" @@ -71,7 +72,8 @@ func (pr *Processor) WriteBackup(ctx context.Context) (*pb.BackupResponse, error stream := pr.DB.NewStreamAt(pr.Request.ReadTs) stream.LogPrefix = "Dgraph.Backup" - newSince, err := stream.Backup(handler, pr.Request.SinceTs) + gzWriter := gzip.NewWriter(handler) + newSince, err := stream.Backup(gzWriter, pr.Request.SinceTs) if err != nil { glog.Errorf("While taking backup: %v", err) @@ -84,6 +86,10 @@ func (pr *Processor) WriteBackup(ctx context.Context) (*pb.BackupResponse, error } glog.V(2).Infof("Backup group %d version: %d", pr.Request.GroupId, pr.Request.ReadTs) + if err = gzWriter.Close(); err != nil { + glog.Errorf("While closing gzipped writer: %v", err) + return &emptyRes, err + } if err = handler.Close(); err != nil { glog.Errorf("While closing handler: %v", err) return &emptyRes, err diff --git a/ee/backup/run.go b/ee/backup/run.go index 13b635cfea6..3856913ce68 100644 --- a/ee/backup/run.go +++ b/ee/backup/run.go @@ -13,6 +13,7 @@ package backup import ( + "compress/gzip" "context" "fmt" "io" @@ -241,7 +242,11 @@ func RunRestore(pdir, location string) (uint64, error) { fmt.Println("Creating new db:", bo.Dir) } } - return db.Load(r, 16) + gzReader, err := gzip.NewReader(r) + if err != nil { + return nil + } + return db.Load(gzReader, 16) }) }