Skip to content

Commit

Permalink
Rewrite the backup procedure to reduce memory usage
Browse files Browse the repository at this point in the history
Main changes:

* Change the listing order of files/directories so that the local and remote
  snapshots can be compared on-the-fly.

* Introduce a new struct called EntryList that maintains a list of
  files/directories, which are kept in memory when the number is lower, and
  serialized into a file when there are too many.

* EntryList can also be turned into an on-disk incomplete snapshot quickly,
  to support fast-resume on next run.

* ChunkOperator can now download and upload chunks, thus replacing original
  ChunkDownloader and ChunkUploader.  The new ChunkDownloader is only used
  to prefetch chunks during the restore operation.
  • Loading branch information
gilbertchen committed Oct 25, 2021
1 parent f83e4f3 commit d9f6545
Show file tree
Hide file tree
Showing 20 changed files with 2,706 additions and 1,693 deletions.
26 changes: 25 additions & 1 deletion duplicacy/duplicacy_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func setGlobalOptions(context *cli.Context) {
duplicacy.SetLoggingLevel(duplicacy.DEBUG)
}

if context.GlobalBool("print-memory-usage") {
go duplicacy.PrintMemoryUsage()
}

ScriptEnabled = true
if context.GlobalBool("no-script") {
ScriptEnabled = false
Expand Down Expand Up @@ -781,7 +785,10 @@ func backupRepository(context *cli.Context) {

backupManager.SetupSnapshotCache(preference.Name)
backupManager.SetDryRun(dryRun)
backupManager.Backup(repository, quickMode, threads, context.String("t"), showStatistics, enableVSS, vssTimeout, enumOnly)

metadataChunkSize := context.Int("metadata-chunk-size")
maximumInMemoryEntries := context.Int("max-in-memory-entries")
backupManager.Backup(repository, quickMode, threads, context.String("t"), showStatistics, enableVSS, vssTimeout, enumOnly, metadataChunkSize, maximumInMemoryEntries)

runScript(context, preference.Name, "post")
}
Expand Down Expand Up @@ -1506,6 +1513,19 @@ func main() {
Name: "enum-only",
Usage: "enumerate the repository recursively and then exit",
},
cli.IntFlag{
Name: "metadata-chunk-size",
Value: 1024 * 1024,
Usage: "the average size of metadata chunks (defaults to 1M)",
Argument: "<size>",
},
cli.IntFlag{
Name: "max-in-memory-entries",
Value: 1024 * 1024,
Usage: "the maximum number of entries kept in memory (defaults to 1M)",
Argument: "<number>",
},

},
Usage: "Save a snapshot of the repository to the storage",
ArgsUsage: " ",
Expand Down Expand Up @@ -2180,6 +2200,10 @@ func main() {
Usage: "suppress logs with the specified id",
Argument: "<id>",
},
cli.BoolFlag{
Name: "print-memory-usage",
Usage: "print memory usage every second",
},
}

app.HideVersion = true
Expand Down
Loading

0 comments on commit d9f6545

Please sign in to comment.