Permalink
Browse files

Introduce `--min-pack-size` option

  • Loading branch information...
kayrus committed Apr 25, 2018
1 parent 2aa6b49 commit 71c13bab23ecb45f23cafb57609930fb9ffba806
Showing with 16 additions and 7 deletions.
  1. +4 −0 cmd/restic/cmd_backup.go
  2. +0 −2 internal/repository/packer_manager.go
  3. +12 −5 internal/repository/repository.go
@@ -66,6 +66,7 @@ type BackupOptions struct {
FilesFrom string
TimeStamp string
WithAtime bool
MinPackSize uint
}

var backupOptions BackupOptions
@@ -88,6 +89,7 @@ func init() {
f.StringVar(&backupOptions.FilesFrom, "files-from", "", "read the files to backup from file (can be combined with file args)")
f.StringVar(&backupOptions.TimeStamp, "time", "", "time of the backup (ex. '2012-11-01 22:08:41') (default: now)")
f.BoolVar(&backupOptions.WithAtime, "with-atime", false, "store the atime for all files and directories")
f.UintVar(&backupOptions.MinPackSize, "min-pack-size", 4, "minimal pack size in MiB")
}

func newScanProgress(gopts GlobalOptions) *restic.Progress {
@@ -411,6 +413,8 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
return err
}

repo.SetMinPackSize(opts.MinPackSize * 1024 * 1024)

// exclude restic cache
if repo.Cache != nil {
f, err := rejectResticCache(repo)
@@ -36,8 +36,6 @@ type packerManager struct {
packers []*Packer
}

const minPackSize = 4 * 1024 * 1024

// newPackerManager returns an new packer manager which writes temporary files
// to a temporary directory
func newPackerManager(be Saver, key *crypto.Key) *packerManager {
@@ -29,6 +29,7 @@ type Repository struct {
keyName string
idx *MasterIndex
restic.Cache
minPackSize uint

treePM *packerManager
dataPM *packerManager
@@ -37,10 +38,11 @@ type Repository struct {
// New returns a new repository with backend be.
func New(be restic.Backend) *Repository {
repo := &Repository{
be: be,
idx: NewMasterIndex(),
dataPM: newPackerManager(be, nil),
treePM: newPackerManager(be, nil),
be: be,
idx: NewMasterIndex(),
dataPM: newPackerManager(be, nil),
treePM: newPackerManager(be, nil),
minPackSize: 1024 * 1024 * 4,
}

return repo
@@ -51,6 +53,11 @@ func (r *Repository) Config() restic.Config {
return r.cfg
}

// SetMinPackSize sets the minimal pack size
func (r *Repository) SetMinPackSize(size uint) {
r.minPackSize = size
}

// UseCache replaces the backend with the wrapped cache.
func (r *Repository) UseCache(c restic.Cache) {
if c == nil {
@@ -247,7 +254,7 @@ func (r *Repository) SaveAndEncrypt(ctx context.Context, t restic.BlobType, data
}

// if the pack is not full enough, put back to the list
if packer.Size() < minPackSize {
if packer.Size() < r.minPackSize {
debug.Log("pack is not full enough (%d bytes)", packer.Size())
pm.insertPacker(packer)
return *id, nil

0 comments on commit 71c13ba

Please sign in to comment.