Skip to content

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
proofrock committed Nov 3, 2021
2 parents 177785b + 1739af0 commit 22bda41
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 🗃️ snapkup v0.3.0
# 🗃️ snapkup v0.3.1

Snapkup is a simple backup tool that takes snapshots of your filesystem (or the parts that you'll decide), storing them
efficiently and conveniently.
Expand Down Expand Up @@ -57,8 +57,8 @@ this flag will need to be repeated for every command.

`snapkup -d C:\MySnapkupDir init`

Requires an empty directory. Creates a shallow dir structure to divide the files, and a `snapkup.dat` file (encrypted)
that will store all the data. Also, generates the encryption and checksum keys.
It requires an empty directory and creates a shallow dir structure to organize the files, and a `snapkup.dat` file (encrypted)
that will store all the metadata. Also, generates the encryption and checksum keys.

### Register the directory to back up as a root

Expand Down
4 changes: 3 additions & 1 deletion src/commands/snap/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func Delete(bkpDir string, toDel int) func(modl *model.Model) error {

blobsToDel := make(map[string]bool)
for _, blob := range modl.Blobs {
blobsToDel[blob.Hash] = true
if blob.AggloRef == nil {
blobsToDel[blob.Hash] = true
}
}

for _, item := range modl.Items {
Expand Down
57 changes: 35 additions & 22 deletions src/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"math/rand"
"os"
Expand All @@ -19,7 +20,7 @@ import (
"github.com/proofrock/snapkup/util"
)

const version = "v0.3.0"
const version = "v0.3.1"

var (
relBkpDir = kingpin.Flag("backup-dir", "The directory to store backups into.").Required().Short('d').ExistingDir()
Expand Down Expand Up @@ -81,7 +82,12 @@ func init() {
rand.Seed(time.Now().UnixMilli())
}

func exec(pwd, bkpDir string, save bool, block func(modl *model.Model) error) error {
func exec(bkpDir string, save bool, block func(modl *model.Model) error) error {
pwd, errGettingPwd := getPwd()
if errGettingPwd != nil {
return errGettingPwd
}

modl, errLoadingModel := model.LoadModel(pwd, bkpDir)
if errLoadingModel != nil {
return errLoadingModel
Expand All @@ -97,7 +103,7 @@ func exec(pwd, bkpDir string, save bool, block func(modl *model.Model) error) er
return nil
}

func app(pwd string) (errApp error) {
func app() (errApp error) {
kingpin.Version(util.Banner(version))

cliResult := kingpin.Parse()
Expand All @@ -108,71 +114,78 @@ func app(pwd string) (errApp error) {
switch cliResult {

case initCmd.FullCommand():
errApp = initcmd.Init(pwd, bkpDir)

if pwd, errGettingPwd := getPwd(); errGettingPwd != nil {
errApp = errGettingPwd
} else {
errApp = initcmd.Init(pwd, bkpDir)
}

case addRootCmd.FullCommand():
if rootToAdd, errAbsolutizing := filepath.Abs(*relRootToAdd); errAbsolutizing != nil {
errApp = errAbsolutizing
} else {
errApp = exec(pwd, bkpDir, true, root.Add(rootToAdd))
errApp = exec(bkpDir, true, root.Add(rootToAdd))
}

case listRootsCmd.FullCommand():
errApp = exec(pwd, bkpDir, false, root.List())
errApp = exec(bkpDir, false, root.List())

case delRootCmd.FullCommand():
errApp = exec(pwd, bkpDir, true, root.Delete(*rootToDel))
errApp = exec(bkpDir, true, root.Delete(*rootToDel))

case snapCmd.FullCommand():
errApp = exec(pwd, bkpDir, true, snap.Do(bkpDir, *snapNoCompress, *snapLabel))
errApp = exec(bkpDir, true, snap.Do(bkpDir, *snapNoCompress, *snapLabel))

case listSnapsCmd.FullCommand():
errApp = exec(pwd, bkpDir, false, snap.List())
errApp = exec(bkpDir, false, snap.List())

case delSnapCmd.FullCommand():
errApp = exec(pwd, bkpDir, true, snap.Delete(bkpDir, *snapToDel))
errApp = exec(bkpDir, true, snap.Delete(bkpDir, *snapToDel))

case restoreCmd.FullCommand():
if dirToRestore, errAbsolutizing := filepath.Abs(*relDirToRestore); errAbsolutizing != nil {
errApp = errAbsolutizing
} else {
errApp = exec(pwd, bkpDir, false, snap.Restore(bkpDir, *snapToRestore, dirToRestore, restorePrefixPath))
errApp = exec(bkpDir, false, snap.Restore(bkpDir, *snapToRestore, dirToRestore, restorePrefixPath))
}

case infoSnapCmd.FullCommand():
errApp = exec(pwd, bkpDir, false, snap.Info(*snapToInfo))
errApp = exec(bkpDir, false, snap.Info(*snapToInfo))

case listSnapCmd.FullCommand():
errApp = exec(pwd, bkpDir, false, snap.FileList(*snapToList))
errApp = exec(bkpDir, false, snap.FileList(*snapToList))

case labelSnapCmd.FullCommand():
errApp = exec(pwd, bkpDir, true, snap.Label(*snapToLabel, *labelSnapLabel))
errApp = exec(bkpDir, true, snap.Label(*snapToLabel, *labelSnapLabel))

case checkSnapCmd.FullCommand():
errApp = exec(pwd, bkpDir, false, snap.Check(bkpDir))
errApp = exec(bkpDir, false, snap.Check(bkpDir))

case aggloCalcCmd.FullCommand():
errApp = exec(pwd, bkpDir, false, agglo.Calc(*acThreshold*util.Mega, *acTarget*util.Mega))
errApp = exec(bkpDir, false, agglo.Calc(*acThreshold*util.Mega, *acTarget*util.Mega))

case aggloDoCmd.FullCommand():
errApp = exec(pwd, bkpDir, true, agglo.Do(bkpDir, *adThreshold*util.Mega, *adTarget*util.Mega))
errApp = exec(bkpDir, true, agglo.Do(bkpDir, *adThreshold*util.Mega, *adTarget*util.Mega))

case aggloUnpackCmd.FullCommand():
errApp = exec(pwd, bkpDir, true, agglo.Unpack(bkpDir))
errApp = exec(bkpDir, true, agglo.Unpack(bkpDir))
}
}

return errApp
}

func main() {
func getPwd() (string, error) {
pwd := os.Getenv("SNAPKUP_PASSWORD")
if pwd == "" {
fmt.Fprint(os.Stderr, "ERROR: password not declared\n")
os.Exit(1)
return "", errors.New("password not declared")
}
return pwd, nil
}

if errApp := app(pwd); errApp != nil {
func main() {
if errApp := app(); errApp != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", errApp)
os.Exit(1)
}
Expand Down

0 comments on commit 22bda41

Please sign in to comment.