Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to schedule recurring incremental backups #359

Merged
merged 12 commits into from
Nov 9, 2021
48 changes: 48 additions & 0 deletions api/v1beta1/solrbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ type SolrBackupSpec struct {
// +optional
Location string `json:"location,omitempty"`

// Set this backup to be taken recurrently, with options for scheduling and storage.
//
// NOTE: This is only supported for Solr Clouds version 8.9+, as it uses the incremental backup API.
//
// +optional
Recurrence *BackupRecurrence `json:"recurrence,omitempty"`

// Persistence is the specification on how to persist the backup data.
// +optional
Persistence *PersistenceSource `json:"persistence,omitempty"`
Expand All @@ -64,6 +71,29 @@ func (spec *SolrBackupSpec) withDefaults(backupName string) (changed bool) {
return changed
}

// BackupRecurrence defines the recurrence of the incremental backup
type BackupRecurrence struct {
// Perform a backup on the given schedule, in CRON format.
//
// Multiple CRON syntaxes are supported
// - Standard CRON (e.g. "CRON_TZ=Asia/Seoul 0 6 * * ?")
// - Predefined Schedules (e.g. "@yearly", "@weekly", "@daily", etc.)
// - Intervals (e.g. "@every 10h30m")
//
// For more information please check this reference:
// https://pkg.go.dev/github.com/robfig/cron/v3?utm_source=godoc#hdr-CRON_Expression_Format
Schedule string `json:"schedule"`

// Define the number of backup points to save for this backup at any given time.
// The oldest backups will be deleted if too many exist when a backup is taken.
// If not provided, this defaults to 10.
//
// +kubebuilder:default:=10
// +kubebuilder:validation:Minimum:=1
// +optional
MaxSaved int `json:"maxSaved,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[0] This is mostly subjective preference, but I'd vote for a smaller default value here. For collections with a lot of churn, 10 backups might be a lot of data to store by default. Would you be open to a lower default like 3 or 5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very open. I literally just chose a number here. I am very happy to differ to whatever you think it should be. Give the call and it is done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set the default to 5

}

// PersistenceSource defines the location and method of persisting the backup data.
// Exactly one member must be specified.
type PersistenceSource struct {
Expand Down Expand Up @@ -198,9 +228,27 @@ func (spec *VolumePersistenceSource) withDefaults(backupName string) (changed bo

// SolrBackupStatus defines the observed state of SolrBackup
type SolrBackupStatus struct {
// The current Backup Status, which all fields are added to this struct
Current IndividualSolrBackupStatus `json:",inline"`

// The scheduled time for the next backup to occur
// +optional
NextScheduledTime *metav1.Time `json:"nextScheduledTime,omitempty"`

// The status history of recurring backups
// +optional
History []IndividualSolrBackupStatus `json:"history,omitempty"`
}

// IndividualSolrBackupStatus defines the observed state of a single issued SolrBackup
type IndividualSolrBackupStatus struct {
// Version of the Solr being backed up
SolrVersion string `json:"solrVersion"`

// The time that this backup was initiated
// +optional
StartTime metav1.Time `json:"startTimestamp,omitempty"`

// The status of each collection's backup progress
// +optional
CollectionBackupStatuses []CollectionBackupStatus `json:"collectionBackupStatuses,omitempty"`
Expand Down
1 change: 0 additions & 1 deletion api/v1beta1/solrcloud_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const (
DefaultSolrReplicas = int32(3)
DefaultSolrRepo = "library/solr"
DefaultSolrVersion = "8.9"
DefaultSolrStorage = "5Gi"
DefaultSolrJavaMem = "-Xms1g -Xmx2g"
DefaultSolrOpts = ""
DefaultSolrLogLevel = "INFO"
Expand Down
82 changes: 65 additions & 17 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions config/crd/bases/solr.apache.org_solrbackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,20 @@ spec:
- source
type: object
type: object
recurrence:
description: "Set this backup to be taken recurrently, with options for scheduling and storage. \n NOTE: This is only supported for Solr Clouds version 8.9+, as it uses the incremental backup API."
properties:
maxSaved:
default: 10
description: Define the number of backup points to save for this backup at any given time. The oldest backups will be deleted if too many exist when a backup is taken. If not provided, this defaults to 10.
minimum: 1
type: integer
schedule:
description: "Perform a backup on the given schedule, in CRON format. \n Multiple CRON syntaxes are supported - Standard CRON (e.g. \"CRON_TZ=Asia/Seoul 0 6 * * ?\") - Predefined Schedules (e.g. \"@yearly\", \"@weekly\", \"@daily\", etc.) - Intervals (e.g. \"@every 10h30m\") \n For more information please check this reference: https://pkg.go.dev/github.com/robfig/cron/v3?utm_source=godoc#hdr-CRON_Expression_Format"
type: string
required:
- schedule
type: object
repositoryName:
description: The name of the repository to use for the backup. Defaults to "legacy_local_repository" if not specified (the auto-configured repository for legacy singleton volumes).
type: string
Expand Down Expand Up @@ -1105,6 +1119,92 @@ spec:
finished:
description: Whether the backup has finished
type: boolean
history:
description: The status history of recurring backups
items:
description: IndividualSolrBackupStatus defines the observed state of a single issued SolrBackup
properties:
collectionBackupStatuses:
description: The status of each collection's backup progress
items:
description: CollectionBackupStatus defines the progress of a Solr Collection's backup
properties:
asyncBackupStatus:
description: The status of the asynchronous backup call to solr
type: string
backupName:
description: BackupName of this collection's backup in Solr
type: string
collection:
description: Solr Collection name
type: string
finishTimestamp:
description: Time that the collection backup finished at
format: date-time
type: string
finished:
description: Whether the backup has finished
type: boolean
inProgress:
description: Whether the collection is being backed up
type: boolean
startTimestamp:
description: Time that the collection backup started at
format: date-time
type: string
successful:
description: Whether the backup was successful
type: boolean
required:
- collection
type: object
type: array
finishTimestamp:
description: Version of the Solr being backed up
format: date-time
type: string
finished:
description: Whether the backup has finished
type: boolean
persistenceStatus:
description: Whether the backups are in progress of being persisted
properties:
finishTimestamp:
description: Time that the collection backup finished at
format: date-time
type: string
finished:
description: Whether the persistence has finished
type: boolean
inProgress:
description: Whether the collection is being backed up
type: boolean
startTimestamp:
description: Time that the collection backup started at
format: date-time
type: string
successful:
description: Whether the backup was successful
type: boolean
type: object
solrVersion:
description: Version of the Solr being backed up
type: string
startTimestamp:
description: The time that this backup was initiated
format: date-time
type: string
successful:
description: Whether the backup was successful
type: boolean
required:
- solrVersion
type: object
type: array
nextScheduledTime:
description: The scheduled time for the next backup to occur
format: date-time
type: string
persistenceStatus:
description: Whether the backups are in progress of being persisted
properties:
Expand All @@ -1129,6 +1229,10 @@ spec:
solrVersion:
description: Version of the Solr being backed up
type: string
startTimestamp:
description: The time that this backup was initiated
format: date-time
type: string
successful:
description: Whether the backup was successful
type: boolean
Expand Down
3 changes: 3 additions & 0 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (

// Set the requeueAfter if it has not been set, or is greater than the new time to requeue at
func updateRequeueAfter(requeueOrNot *reconcile.Result, newWait time.Duration) {
if newWait <= 0 {
requeueOrNot.RequeueAfter = 0
}
if requeueOrNot.RequeueAfter <= 0 || requeueOrNot.RequeueAfter > newWait {
requeueOrNot.RequeueAfter = newWait
}
Expand Down
Loading