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

DRAFT: Allows to mount backups using FUSE #628

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Binary file added duplicacy/duplicacy
Binary file not shown.
100 changes: 93 additions & 7 deletions duplicacy/duplicacy_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"io/ioutil"

"github.com/gilbertchen/duplicacy/src"
duplicacy "github.com/gilbertchen/duplicacy/src"
)

const (
Expand Down Expand Up @@ -1015,7 +1015,6 @@ func printFile(context *cli.Context) {
snapshotID = context.String("id")
}


backupManager := duplicacy.CreateBackupManager(preference.SnapshotID, storage, repository, password, "", "", false)
duplicacy.SavePassword(*preference, "password", password)

Expand Down Expand Up @@ -1262,7 +1261,7 @@ func copySnapshots(context *cli.Context) {
destinationStorage.SetRateLimits(0, context.Int("upload-limit-rate"))

destinationManager := duplicacy.CreateBackupManager(destination.SnapshotID, destinationStorage, repository,
destinationPassword, "", "", false)
destinationPassword, "", "", false)
duplicacy.SavePassword(*destination, "password", destinationPassword)
destinationManager.SetupSnapshotCache(destination.Name)

Expand Down Expand Up @@ -1387,7 +1386,87 @@ func benchmark(context *cli.Context) {
if storage == nil {
return
}
duplicacy.Benchmark(repository, storage, int64(fileSize) * 1024 * 1024, chunkSize * 1024 * 1024, chunkCount, uploadThreads, downloadThreads)
duplicacy.Benchmark(repository, storage, int64(fileSize)*1024*1024, chunkSize*1024*1024, chunkCount, uploadThreads, downloadThreads)
}

func mountFUSE(context *cli.Context) {
setGlobalOptions(context)
defer duplicacy.CatchLogException()

if len(context.Args()) != 2 {
fmt.Fprintf(context.App.Writer, "The %s command requires mount directory and backup revision arguments.\n\n", context.Command.Name)
cli.ShowCommandHelp(context, context.Command.Name)
os.Exit(ArgumentExitCode)
}

setGlobalOptions(context)
defer duplicacy.CatchLogException()

revision, _ := strconv.Atoi(context.Args()[1])
if revision <= 0 {
fmt.Fprintf(context.App.Writer, "The revision flag is not specified or invalid\n\n")
cli.ShowCommandHelp(context, context.Command.Name)
os.Exit(ArgumentExitCode)
}

repository, preference := getRepositoryPreference(context, "")

if preference.RestoreProhibited {
duplicacy.LOG_ERROR("RESTORE_DISABLED", "Restore from %s to this repository was disabled by the preference",
preference.StorageURL)
return
}

runScript(context, preference.Name, "pre")

threads := context.Int("threads")
if threads < 1 {
threads = 1
}

duplicacy.LOG_INFO("STORAGE_SET", "Storage set to %s", preference.StorageURL)
storage := duplicacy.CreateStorage(*preference, false, threads)
if storage == nil {
return
}

password := ""
if preference.Encrypted {
password = duplicacy.GetPassword(*preference, "password", "Enter storage password:", false, false)
}

var patterns []string
for _, pattern := range context.Args() {

pattern = strings.TrimSpace(pattern)

for strings.HasPrefix(pattern, "--") {
pattern = pattern[1:]
}

for strings.HasPrefix(pattern, "++") {
pattern = pattern[1:]
}

patterns = append(patterns, pattern)
}

patterns = duplicacy.ProcessFilterLines(patterns, make([]string, 0))

duplicacy.LOG_DEBUG("REGEX_DEBUG", "There are %d compiled regular expressions stored", len(duplicacy.RegexMap))

duplicacy.LOG_INFO("SNAPSHOT_FILTER", "Loaded %d include/exclude pattern(s)", len(patterns))

storage.SetRateLimits(context.Int("limit-rate"), 0)
backupManager := duplicacy.CreateBackupManager(preference.SnapshotID, storage, repository, password, preference.NobackupFile, preference.FiltersFile, preference.ExcludeByAttribute)
duplicacy.SavePassword(*preference, "password", password)

loadRSAPrivateKey(context.String("key"), context.String("key-passphrase"), preference, backupManager, false)

backupManager.SetupSnapshotCache(preference.Name)

_, cleanup := duplicacy.MountFileSystem(context.Args()[0], revision, backupManager)
defer cleanup()
}

func main() {
Expand Down Expand Up @@ -1565,7 +1644,7 @@ func main() {
cli.BoolFlag{
Name: "persist",
Usage: "continue processing despite chunk errors or existing files (without -overwrite), reporting any affected files",
},
},
cli.StringFlag{
Name: "key-passphrase",
Usage: "the passphrase to decrypt the RSA private key",
Expand Down Expand Up @@ -2138,6 +2217,13 @@ func main() {
ArgsUsage: " ",
Action: benchmark,
},

{
Name: "fusemount",
Usage: "Mount the backup into a FUSE filesystem",
ArgsUsage: "<mount path> <backup revision>",
Action: mountFUSE,
},
}

app.Flags = []cli.Flag{
Expand Down Expand Up @@ -2176,8 +2262,8 @@ func main() {
Usage: "add a comment to identify the process",
},
cli.StringSliceFlag{
Name: "suppress, s",
Usage: "suppress logs with the specified id",
Name: "suppress, s",
Usage: "suppress logs with the specified id",
Argument: "<id>",
},
}
Expand Down
62 changes: 62 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module github.com/gilbertchen/duplicacy

go 1.18

require (
cloud.google.com/go v0.38.0
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a
github.com/aws/aws-sdk-go v1.30.7
github.com/bkaradzic/go-lz4 v1.0.0
github.com/gilbertchen/azure-sdk-for-go v14.1.2-0.20180323033227-8fd4663cab7c+incompatible
github.com/gilbertchen/cli v1.2.1-0.20160223210219-1de0a1836ce9
github.com/gilbertchen/go-dropbox v0.0.0-20201103213208-2233fa1dd846
github.com/gilbertchen/go-ole v1.2.0
github.com/gilbertchen/goamz v0.0.0-20170712012135-eada9f4e8cc2
github.com/gilbertchen/gopass v0.0.0-20170109162249-bf9dde6d0d2c
github.com/gilbertchen/keyring v0.0.0-20170923175943-8855f5632086
github.com/gilbertchen/xattr v0.0.0-20160926155429-68e7a6806b01
github.com/klauspost/reedsolomon v1.9.9
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/minio/highwayhash v1.0.1
github.com/ncw/swift v1.0.50
github.com/pkg/sftp v1.11.0
github.com/pkg/xattr v0.4.1
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20200822124328-c89045814202
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
google.golang.org/api v0.21.0
)

require (
github.com/Azure/go-autorest v10.15.5+incompatible // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dnaeon/go-vcr v1.2.0 // indirect
github.com/gilbertchen/go.dbus v0.0.0-20190607191240-8591994fa32f // indirect
github.com/goamz/goamz v0.0.0-20180131231218-8b901b531db8 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.3.5 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/guelfey/go.dbus v0.0.0-20220105183920-7084538c37af // indirect
github.com/hanwen/go-fuse v1.0.0 // indirect
github.com/hanwen/go-fuse/v2 v2.1.0 // indirect
github.com/jmespath/go-jmespath v0.3.0 // indirect
github.com/klauspost/cpuid v1.3.1 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/marstr/guid v1.1.0 // indirect
github.com/mmcloughlin/avo v0.0.0-20200803215136-443f81d77104 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/segmentio/go-env v1.1.0 // indirect
github.com/tj/go-dropbox v0.0.0-20171107035848-42dd2be3662d // indirect
github.com/tmc/keyring v0.0.0-20171121202319-839169085ae1 // indirect
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect
go.opencensus.io v0.22.3 // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20200409111301-baae70f3302d // indirect
google.golang.org/grpc v1.28.1 // indirect
)
Loading