Skip to content

Commit

Permalink
Introduce --min-pack-size option
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus committed Apr 25, 2018
1 parent 2aa6b49 commit 71c13ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cmd/restic/cmd_backup.go
Expand Up @@ -66,6 +66,7 @@ type BackupOptions struct {
FilesFrom string
TimeStamp string
WithAtime bool
MinPackSize uint
}

var backupOptions BackupOptions
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions internal/repository/packer_manager.go
Expand Up @@ -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 {
Expand Down
17 changes: 12 additions & 5 deletions internal/repository/repository.go
Expand Up @@ -29,6 +29,7 @@ type Repository struct {
keyName string
idx *MasterIndex
restic.Cache
minPackSize uint

treePM *packerManager
dataPM *packerManager
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 71c13ba

Please sign in to comment.