in oracle/controllers/instancecontroller/instance_controller_restore_pitr.go [33:85]
func (r *InstanceReconciler) findPITRBackupForRestore(ctx context.Context, inst v1alpha1.Instance, log logr.Logger) (*v1alpha1.Backup, error) {
// Preflight check for PITR restore
PITRRestoreSpec := inst.Spec.Restore.PITRRestore
if PITRRestoreSpec.SCN == "" && PITRRestoreSpec.Timestamp == nil {
return nil, fmt.Errorf("PITR preflight check: must specify either .PITRRestore.SCN or .PITRRestore.Time")
}
if PITRRestoreSpec.SCN != "" && PITRRestoreSpec.Timestamp != nil {
return nil, fmt.Errorf("PITR preflight check: .PITRRestore.SCN and .PITRRestore.Time cannot be specified at the same time")
}
p, err := r.findRestorePITR(ctx, &inst)
if err != nil {
return nil, err
}
inc := PITRRestoreSpec.Incarnation
if inc == "" {
if PITRRestoreSpec.PITRRef != nil {
// PITRRef was specified.
inc = p.Status.CurrentDatabaseIncarnation
} else {
inc = inst.Status.CurrentDatabaseIncarnation
}
}
// Find closest backup with timestamp/scn smaller than restore point in target incarnation
var backupList v1alpha1.BackupList
targetLabels := client.MatchingLabels{
controllers.PITRLabel: p.GetName(),
controllers.IncarnationLabel: inc,
}
if err := r.List(ctx, &backupList, client.InNamespace(p.GetNamespace()), targetLabels); err != nil {
return nil, fmt.Errorf("failed to get backups for a PITR restore: %v", err)
}
if len(backupList.Items) == 0 {
return nil, fmt.Errorf("failed to find any backup for a PITR restore")
}
b, err := findPITRBackup(backupList.Items, PITRRestoreSpec, log)
if err == nil {
return b, nil
}
// Try to find closest backup in parent incarnation
targetLabels = client.MatchingLabels{
controllers.PITRLabel: p.GetName(),
controllers.IncarnationLabel: backupList.Items[0].Labels[controllers.ParentIncarnationLabel],
}
if err := r.List(ctx, &backupList, client.InNamespace(p.GetNamespace()), targetLabels); err != nil {
return nil, fmt.Errorf("failed to get backups for a PITR restore: %v", err)
}
return findPITRBackup(backupList.Items, PITRRestoreSpec, log)
}