Skip to content

Commit

Permalink
Allow backup storage locations to specify backup sync period
Browse files Browse the repository at this point in the history
Signed-off-by: Antony Bett <[email protected]>
  • Loading branch information
betta1 committed Oct 3, 2019
1 parent aa9ca9a commit dec3131
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/cloudprovider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import (

// ValidateObjectStoreConfigKeys ensures that an object store's config
// is valid by making sure each `config` key is in the `validKeys` list.
// The special keys "bucket" and "prefix" are always considered valid.
// The special keys "bucket", "prefix" and "backupSyncPeriod" are always
// considered valid.
func ValidateObjectStoreConfigKeys(config map[string]string, validKeys ...string) error {
// `bucket` and `prefix` are automatically added to all object
// store config by velero, so add them as valid keys.
return validateConfigKeys(config, append(validKeys, "bucket", "prefix")...)
// `bucket`, `prefix` are automatically added to all object store
// config by velero, so add them as valid keys. Object store config
// can also specify a `backupSyncPeriod` so add this as a valid key.
return validateConfigKeys(config, append(validKeys, "bucket", "prefix", "backupSyncPeriod")...)
}

// ValidateVolumeSnapshotterConfigKeys ensures that a volume snapshotter's
Expand Down
24 changes: 24 additions & 0 deletions pkg/controller/backup_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import (
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt"
)

const (
backupSyncPeriodKey = "backupSyncPeriod"
)

type backupSyncController struct {
*genericController

Expand Down Expand Up @@ -134,6 +138,26 @@ func (c *backupSyncController) run() {

for _, location := range locations {
log := c.logger.WithField("backupLocation", location.Name)

if backupSyncPeriod, ok := location.Spec.Config[backupSyncPeriodKey]; ok {
syncDuration, err := time.ParseDuration(backupSyncPeriod)
if err != nil {
log.WithError(err).Error("Error parsing backup sync period for this location")
continue
}

log.Debug("Checking if backups need to be synced at this time for this location")
lastSync := location.Status.LastSyncedTime
nextSync := lastSync.Add(syncDuration)
if time.Now().UTC().Before(nextSync) {
c.logger.WithFields(logrus.Fields{
"backupLocation": location.Name,
"lastSync": lastSync,
"nextSync": nextSync}).Debug("Sync not required at this time")
continue
}
}

log.Debug("Checking backup location for backups to sync into cluster")

backupStore, err := c.newBackupStore(location, pluginManager, log)
Expand Down
2 changes: 2 additions & 0 deletions site/docs/master/api-types/backupstoragelocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ spec:
config:
region: us-west-2
profile: "default"
backupSyncPeriod: 5m0s
```
### Parameter Reference
Expand All @@ -36,6 +37,7 @@ The configurable parameters are as follows:
| `objectStorage/bucket` | String | Required Field | The storage bucket where backups are to be uploaded. |
| `objectStorage/prefix` | String | Optional Field | The directory inside a storage bucket where backups are to be uploaded. |
| `config` | map[string]string<br><br>(See the corresponding [AWS][0], [GCP][1], and [Azure][2]-specific configs or your provider's documentation.) | None (Optional) | Configuration keys/values to be passed to the cloud provider for backup storage. |
| `config/backupSyncPeriod` | time.Duration | Optional Field | How frequently Velero should synchronize backups in object storage. Default is Velero's server global backup sync period. |
| `accessMode` | String | `ReadWrite` | How Velero can access the backup storage location. Valid values are `ReadWrite`, `ReadOnly`. |


Expand Down

0 comments on commit dec3131

Please sign in to comment.