From 62d83d2df05feba4637f0fb3cfc1b9c535414727 Mon Sep 17 00:00:00 2001 From: Abin Date: Mon, 6 Feb 2023 13:42:38 +0530 Subject: [PATCH] Add a flag to toggle OneDrive delta incrementals This will help us while this is still in development. We should be able to add in features without affecting anything else. Once we have it in a more or less stable state this can be removed completely. --- src/cli/backup/onedrive.go | 1 + src/cli/options/options.go | 19 +++++++++++++++++-- src/internal/operations/backup.go | 5 +++++ src/pkg/control/options.go | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/cli/backup/onedrive.go b/src/cli/backup/onedrive.go index 64f328c7d..76c6a8e9a 100644 --- a/src/cli/backup/onedrive.go +++ b/src/cli/backup/onedrive.go @@ -81,6 +81,7 @@ func addOneDriveCommands(cmd *cobra.Command) *cobra.Command { case createCommand: c, fs = utils.AddCommand(cmd, oneDriveCreateCmd()) options.AddFeatureToggle(cmd, options.EnablePermissionsBackup()) + options.AddFeatureToggle(cmd, options.EnableOneDriveDeltaIncrementals()) c.Use = c.Use + " " + oneDriveServiceCommandCreateUseSuffix c.Example = oneDriveServiceCommandCreateExamples diff --git a/src/cli/options/options.go b/src/cli/options/options.go index 2b423836c..aae7840b6 100644 --- a/src/cli/options/options.go +++ b/src/cli/options/options.go @@ -16,6 +16,7 @@ func Control() control.Options { opt.RestorePermissions = restorePermissions opt.ToggleFeatures.DisableIncrementals = disableIncrementals opt.ToggleFeatures.EnablePermissionsBackup = enablePermissionsBackup + opt.ToggleFeatures.EnableOneDriveDeltaIncrementals = enableOneDriveDeltaIncrentals return opt } @@ -57,8 +58,9 @@ func AddRestorePermissionsFlag(cmd *cobra.Command) { // --------------------------------------------------------------------------- var ( - disableIncrementals bool - enablePermissionsBackup bool + disableIncrementals bool + enablePermissionsBackup bool + enableOneDriveDeltaIncrentals bool ) type exposeFeatureFlag func(*pflag.FlagSet) @@ -97,3 +99,16 @@ func EnablePermissionsBackup() func(*pflag.FlagSet) { cobra.CheckErr(fs.MarkHidden("enable-permissions-backup")) } } + +// Adds the hidden '--enable-onedrive-delta-incrementals' cli flag which, when +// set, enables delta incrementals for OneDrive. +func EnableOneDriveDeltaIncrementals() func(*pflag.FlagSet) { + return func(fs *pflag.FlagSet) { + fs.BoolVar( + &enableOneDriveDeltaIncrentals, + "enable-onedrive-delta-incrementals", + false, + "Enables delta based incrementals for OneDrive") + cobra.CheckErr(fs.MarkHidden("enable-onedrive-delta-incrementals")) + } +} diff --git a/src/internal/operations/backup.go b/src/internal/operations/backup.go index e0fe73870..399cd5552 100644 --- a/src/internal/operations/backup.go +++ b/src/internal/operations/backup.go @@ -289,6 +289,11 @@ func (op *BackupOperation) do( // checker to see if conditions are correct for incremental backup behavior such as // retrieving metadata like delta tokens and previous paths. func useIncrementalBackup(sel selectors.Selector, opts control.Options) bool { + // TODO(meain): remove this once we stabilize delta incrementals for OneDrive + if sel.Service == selectors.ServiceOneDrive { + return opts.ToggleFeatures.EnableOneDriveDeltaIncrementals + } + // Delta-based incrementals currently only supported for Exchange if sel.Service != selectors.ServiceExchange { return false diff --git a/src/pkg/control/options.go b/src/pkg/control/options.go index 7348e8fa6..a8e86aef7 100644 --- a/src/pkg/control/options.go +++ b/src/pkg/control/options.go @@ -80,4 +80,10 @@ type Toggles struct { // permissions. Permission metadata increases graph api call count, // so disabling their retrieval when not needed is advised. EnablePermissionsBackup bool `json:"enablePermissionsBackup,omitempty"` + + // EnableOneDriveDeltaIncrementals is used to enable OneDrive + // delta incrementals. It is set to false by default as OneDrive + // delta incrementals is still in development. This flag works + // independent of DisableIncrementals. + EnableOneDriveDeltaIncrementals bool `json:"enableOneDriveDeltaIncrementals,omitempty"` }