Skip to content

Commit

Permalink
Adding support for logRestoreStartTs option in PITR restore spec (#5667)
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-japate authored Jun 26, 2024
1 parent 9ef26f8 commit 2bc2eee
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
9 changes: 6 additions & 3 deletions cmd/backup-manager/app/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ func (ro *Options) restoreData(
// init pitr restore args
args = append(args, fmt.Sprintf("--restored-ts=%s", ro.PitrRestoredTs))

if fullBackupArgs, err := pkgutil.GenStorageArgsForFlag(restore.Spec.PitrFullBackupStorageProvider, "full-backup-storage"); err != nil {
return err
fullBackupArgs, err := pkgutil.GenStorageArgsForFlag(restore.Spec.PitrFullBackupStorageProvider, "full-backup-storage")
if err != nil {
if restore.Spec.LogRestoreStartTs == "" {
return fmt.Errorf("error: Either pitrFullBackupStorageProvider or logRestoreStartTs option needs to be passed in pitr mode")
}
args = append(args, fmt.Sprintf("--start-ts=%s", restore.Spec.LogRestoreStartTs))
} else {
// parse full backup path
args = append(args, fullBackupArgs...)
}
restoreType = "point"
Expand Down
8 changes: 6 additions & 2 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,8 @@ string
</em>
</td>
<td>
<p>LogRestoreStartTs is the start timestamp which log restore from and it will be used in the future.</p>
<em>(Optional)</em>
<p>LogRestoreStartTs is the start timestamp which log restore from.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -1405,6 +1406,7 @@ StorageProvider
</em>
</td>
<td>
<em>(Optional)</em>
<p>PitrFullBackupStorageProvider configures where and how pitr dependent full backup should be stored.</p>
</td>
</tr>
Expand Down Expand Up @@ -14491,7 +14493,8 @@ string
</em>
</td>
<td>
<p>LogRestoreStartTs is the start timestamp which log restore from and it will be used in the future.</p>
<em>(Optional)</em>
<p>LogRestoreStartTs is the start timestamp which log restore from.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -14560,6 +14563,7 @@ StorageProvider
</em>
</td>
<td>
<em>(Optional)</em>
<p>PitrFullBackupStorageProvider configures where and how pitr dependent full backup should be stored.</p>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pingcap/v1alpha1/openapi_generated.go

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

4 changes: 3 additions & 1 deletion pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,8 @@ type RestoreSpec struct {
Mode RestoreMode `json:"restoreMode,omitempty"`
// PitrRestoredTs is the pitr restored ts.
PitrRestoredTs string `json:"pitrRestoredTs,omitempty"`
// LogRestoreStartTs is the start timestamp which log restore from and it will be used in the future.
// LogRestoreStartTs is the start timestamp which log restore from.
// +optional
LogRestoreStartTs string `json:"logRestoreStartTs,omitempty"`
// FederalVolumeRestorePhase indicates which phase to execute in federal volume restore
// +optional
Expand All @@ -2645,6 +2646,7 @@ type RestoreSpec struct {
// StorageProvider configures where and how backups should be stored.
StorageProvider `json:",inline"`
// PitrFullBackupStorageProvider configures where and how pitr dependent full backup should be stored.
// +optional
PitrFullBackupStorageProvider StorageProvider `json:"pitrFullBackupStorageProvider,omitempty"`
// The storageClassName of the persistent volume for Restore data storage.
// Defaults to Kubernetes default storage class.
Expand Down
12 changes: 12 additions & 0 deletions pkg/backup/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,18 @@ func ValidateRestore(restore *v1alpha1.Restore, tikvImage string, acrossK8s bool
return fmt.Errorf("DB should be configured for BR with restore type %s in spec of %s/%s", restore.Spec.Type, ns, name)
}

if restore.Spec.Mode == v1alpha1.RestoreModePiTR {
_, err := GetStoragePath(restore.Spec.PitrFullBackupStorageProvider)
// err is nil when there is a valid storage provider
if err == nil && restore.Spec.LogRestoreStartTs != "" {
return fmt.Errorf("pitrFullBackupStorageProvider and logRestoreStartTs option can not co-exists in pitr mode")
}

if err != nil && restore.Spec.LogRestoreStartTs == "" {
return fmt.Errorf("either pitrFullBackupStorageProvider or logRestoreStartTs option needs to be passed in pitr mode")
}
}

if restore.Spec.Type == v1alpha1.BackupTypeTable && restore.Spec.BR.Table == "" {
return fmt.Errorf("table should be configured for BR with restore type table in spec of %s/%s", ns, name)
}
Expand Down

0 comments on commit 2bc2eee

Please sign in to comment.