Skip to content

Commit

Permalink
chore: support continuous backup and restore (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Nov 17, 2023
1 parent ec00651 commit 7fb3539
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/cmd/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ func setBackup(o *CreateOptions, components []map[string]interface{}) error {
if err := cluster.GetK8SClientObject(o.Dynamic, backup, types.BackupGVR(), o.Namespace, backupName); err != nil {
return err
}
if backup.Status.Phase != dpv1alpha1.BackupPhaseCompleted {
if backup.Status.Phase != dpv1alpha1.BackupPhaseCompleted &&
backup.Labels[dptypes.BackupTypeLabelKey] != string(dpv1alpha1.BackupTypeContinuous) {
return fmt.Errorf(`backup "%s" is not completed`, backup.Name)
}
restoreTimeStr, err := restore.FormatRestoreTimeAndValidate(o.RestoreTime, backup)
Expand Down
13 changes: 12 additions & 1 deletion pkg/cmd/cluster/dataprotection.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@ func PrintBackupList(o ListBackupOptions) error {
if len(o.Names) > 0 && !backupNameMap[backup.Name] {
continue
}
var availableReplicas *int32
for _, v := range backup.Status.Actions {
if v.ActionType == dpv1alpha1.ActionTypeStatefulSet {
availableReplicas = v.AvailableReplicas
break
}
}
if availableReplicas != nil {
statusString = fmt.Sprintf("%s(AvailablePods: %d)", statusString, availableReplicas)
}
tbl.AddRow(backup.Name, backup.Namespace, sourceCluster, backup.Spec.BackupMethod, statusString, backup.Status.TotalSize,
durationStr, util.TimeFormat(&backup.CreationTimestamp), util.TimeFormat(backup.Status.CompletionTimestamp),
util.TimeFormat(backup.Status.Expiration))
Expand Down Expand Up @@ -542,7 +552,8 @@ func (o *CreateRestoreOptions) runRestoreFromBackup() error {
if err := cluster.GetK8SClientObject(o.Dynamic, backup, types.BackupGVR(), o.Namespace, o.Backup); err != nil {
return err
}
if backup.Status.Phase != dpv1alpha1.BackupPhaseCompleted {
if backup.Status.Phase != dpv1alpha1.BackupPhaseCompleted &&
backup.Labels[dptypes.BackupTypeLabelKey] != string(dpv1alpha1.BackupTypeContinuous) {
return errors.Errorf(`backup "%s" is not completed.`, backup.Name)
}
if len(backup.Labels[constant.AppInstanceLabelKey]) == 0 {
Expand Down

0 comments on commit 7fb3539

Please sign in to comment.