Skip to content

Commit

Permalink
cleaning, cleaning everything!
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabz committed Jan 6, 2016
1 parent 20b62be commit c2e9f78
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
13 changes: 7 additions & 6 deletions src/github.com/Dabz/mongobackup/copy.go
Expand Up @@ -5,7 +5,7 @@
** Login gaspar_d <d.gasparina@gmail.com>
**
** Started on Thu 24 Dec 23:43:24 2015 gaspar_d
** Last update Sun 3 Jan 15:18:21 2016 gaspar_d
** Last update Wed 6 Jan 20:05:17 2016 gaspar_d
*/

package mongobackup
Expand All @@ -15,6 +15,7 @@ import (
"io"
"strings"
"github.com/pierrec/lz4"
"github.com/Dabz/utils"
)


Expand Down Expand Up @@ -84,9 +85,9 @@ func (e *BackupEnv) GetDirSize(source string) (int64) {
// Copy a directory into another and compress all files if required
func (e *BackupEnv) CopyDir(source string, dest string) (err error, backedByte int64) {
totalSize := e.GetDirSize(source)
pb := ProgressBar{}
pb.title = "backup"
pb.scale = 3
pb := utils.ProgressBar{}
pb.Title = "backup"
pb.Scale = 3
err, _ = e.recCopyDir(source, dest, 0, totalSize, &pb)

pb.End();
Expand All @@ -100,7 +101,7 @@ func (e *BackupEnv) CopyDir(source string, dest string) (err error, backedByte i


// Recursive copy directory function
func (e *BackupEnv) recCopyDir(source string, dest string, backedByte int64, totalSize int64, pb *ProgressBar) (err error, oBackedByte int64) {
func (e *BackupEnv) recCopyDir(source string, dest string, backedByte int64, totalSize int64, pb *utils.ProgressBar) (err error, oBackedByte int64) {
sourceinfo, err := os.Stat(source);

if err != nil {
Expand Down Expand Up @@ -145,7 +146,7 @@ func (e *BackupEnv) recCopyDir(source string, dest string, backedByte int64, tot


// restore & uncompress a backup to a specific location
func (e *BackupEnv) RestoreCopyDir(entry *BackupEntry, source string, dest string, restoredByte int64, totalRestored int64, pb *ProgressBar) (error, int64) {
func (e *BackupEnv) RestoreCopyDir(entry *BackupEntry, source string, dest string, restoredByte int64, totalRestored int64, pb *utils.ProgressBar) (error, int64) {
directory, _ := os.Open(source)
objects, err := directory.Readdir(-1)

Expand Down
17 changes: 9 additions & 8 deletions src/github.com/Dabz/mongobackup/oplog.go
Expand Up @@ -5,7 +5,7 @@
** Login gaspar_d <d.gasparina@gmail.com>
**
** Started on Sat 26 Dec 22:49:07 2015 gaspar_d
** Last update Sun 3 Jan 15:16:41 2016 gaspar_d
** Last update Wed 6 Jan 20:03:36 2016 gaspar_d
*/

package mongobackup
Expand All @@ -15,7 +15,8 @@ import (
"io"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"github.com/pierrec/lz4"
"github.com/pierrec/lz4"
"github.com/Dabz/utils"
)

const (
Expand All @@ -34,7 +35,7 @@ func (e *BackupEnv) BackupOplogToDir(cursor *mgo.Iter, dir string) (error, float
opcount float32
counter float32
dest string
pb ProgressBar
pb utils.ProgressBar
lastop bson.MongoTimestamp
firstop bson.MongoTimestamp
)
Expand All @@ -47,7 +48,7 @@ func (e *BackupEnv) BackupOplogToDir(cursor *mgo.Iter, dir string) (error, float
dest = dir + "/" + OPLOG_FILE
opcount = float32(e.getOplogCount())
counter = 0
pb.title = "oplog dump"
pb.Title = "oplog dump"
lastop = e.homeval.lastOplog
firstop = e.homeval.lastOplog

Expand Down Expand Up @@ -116,8 +117,8 @@ func (e *BackupEnv) DumpOplogsToDir(from, to *BackupEntry) error {
destdir := e.Options.Output + "/" + OPLOG_DIR
oplogfile := destdir + OPLOG_FILE
err := os.MkdirAll(destdir, 0700)
pb := ProgressBar{}
pb.scale = 3
pb := utils.ProgressBar{}
pb.Scale = 3
if err != nil {
return err
}
Expand Down Expand Up @@ -148,12 +149,12 @@ func (e *BackupEnv) DumpOplogsToDir(from, to *BackupEntry) error {
}
}

pb.title = "dumping " + entry.Id
pb.Title = "dumping " + entry.Id
pb.Show(float32(index) / float32(total))

io.Copy(destfile, reader)
}
pb.title = "dumping"
pb.Title = "dumping"
pb.Show(1)
pb.End()
return nil
Expand Down
9 changes: 5 additions & 4 deletions src/github.com/Dabz/mongobackup/restore.go
Expand Up @@ -5,7 +5,7 @@
** Login gaspar_d <d.gasparina@gmail.com>
**
** Started on Mon 28 Dec 23:33:35 2015 gaspar_d
** Last update Wed 6 Jan 07:43:17 2016 gaspar_d
** Last update Wed 6 Jan 20:05:22 2016 gaspar_d
*/

package mongobackup
Expand All @@ -15,6 +15,7 @@ import (
"strings"
"strconv"
"time"
"github.com/Dabz/utils"
)

// perform the restore & dump the oplog if required
Expand Down Expand Up @@ -77,7 +78,7 @@ func (e *BackupEnv) performFullRestore(entry *BackupEntry) {
var (
entryFull *BackupEntry
err error
pb ProgressBar
pb utils.ProgressBar
dirSize int64
)
err = e.checkIfDirExist(e.Options.Output)
Expand All @@ -100,8 +101,8 @@ func (e *BackupEnv) performFullRestore(entry *BackupEntry) {
entryFull = entry
}

pb.title = "restoring"
pb.scale = 3
pb.Title = "restoring"
pb.Scale = 3
dirSize = e.GetDirSize(entryFull.Dest)

pb.Show(0)
Expand Down
Expand Up @@ -5,10 +5,10 @@
** Login gaspar_d <d.gasparina@gmail.com>
**
** Started on Thu 24 Dec 23:55:40 2015 gaspar_d
** Last update Tue 29 Dec 22:21:52 2015 gaspar_d
** Last update Wed 6 Jan 20:04:57 2016 gaspar_d
*/

package mongobackup
package utils

import (
"fmt"
Expand All @@ -18,9 +18,9 @@ import (
)

type ProgressBar struct {
title string
scale uint16
ended bool
Title string // displayed label for the progressbar
Scale uint16 // width of the bar (3 means that 1/3% of the terminal size)
Ended bool // true if the 100% has been reached
}

type WinSize struct {
Expand All @@ -41,11 +41,11 @@ func (p *ProgressBar) GetWinSize() (*WinSize, error) {
uintptr(unsafe.Pointer(ws)),
)

if p.scale == 0 {
p.scale = 3
if p.Scale == 0 {
p.Scale = 3
}

ws.Ws_col = ws.Ws_col / p.scale
ws.Ws_col = ws.Ws_col / p.Scale

if err != 0 {
return nil, err
Expand Down Expand Up @@ -92,7 +92,7 @@ func (p *ProgressBar) Show(percent float32) error {
l int
)

if p.ended {
if p.Ended {
return nil;
}

Expand Down Expand Up @@ -123,19 +123,19 @@ func (p *ProgressBar) Show(percent float32) error {

p.Clear()

if int(percent) == 1 && !p.ended {
fmt.Print(fmt.Sprintf("%s |%s| %s\n", p.title, ps, num))
p.ended = true
if int(percent) == 1 && !p.Ended {
fmt.Print(fmt.Sprintf("%s |%s| %s\n", p.Title, ps, num))
p.Ended = true
} else {
fmt.Print(fmt.Sprintf("%s |%s| %s", p.title, ps, num))
fmt.Print(fmt.Sprintf("%s |%s| %s", p.Title, ps, num))
}

return nil
}

func (p *ProgressBar) End() {
if (!p.ended) {
if (!p.Ended) {
fmt.Print("\n")
p.ended = true
p.Ended = true
}
}

0 comments on commit c2e9f78

Please sign in to comment.