Skip to content

Commit

Permalink
br: add some log to record the CR we are processing (pingcap#5711) (p…
Browse files Browse the repository at this point in the history
…ingcap#5715)

Co-authored-by: csuzhangxc <csuzhangxc@gmail.com>
  • Loading branch information
ti-chi-bot and csuzhangxc authored Aug 23, 2024
1 parent dbe75c0 commit df24c47
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/backup-manager/app/backup/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
errorutils "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -101,6 +102,13 @@ func (bm *Manager) ProcessBackup() error {
return errorutils.NewAggregate(errs)
}

crData, err := json.Marshal(backup)
if err != nil {
klog.Errorf("failed to marshal backup %v to json, err: %v", backup, err)
} else {
klog.Infof("start to process backup: %s", string(crData))
}

// we treat snapshot backup as restarted if its status is not scheduled when backup pod just start to run
// we will clean backup data before run br command
if backup.Spec.Mode == v1alpha1.BackupModeSnapshot && (backup.Status.Phase != v1alpha1.BackupScheduled || v1alpha1.IsBackupRestart(backup)) {
Expand Down Expand Up @@ -132,6 +140,9 @@ func (bm *Manager) ProcessBackup() error {
return bm.performBackup(ctx, backup.DeepCopy(), nil)
}

klog.Infof("start to connect to tidb server (%s:%d) as the .spec.from field is specified",
backup.Spec.From.Host, backup.Spec.From.Port)

// validate and create from db
var db *sql.DB
db, err = bm.validateAndCreateFromDB(ctx, backup.DeepCopy())
Expand Down
8 changes: 8 additions & 0 deletions cmd/backup-manager/app/export/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
errorutils "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -99,6 +100,13 @@ func (bm *BackupManager) ProcessBackup() error {
return errorutils.NewAggregate(errs)
}

crData, err := json.Marshal(backup)
if err != nil {
klog.Errorf("failed to marshal backup %v to json, err: %v", backup, err)
} else {
klog.Infof("start to process backup: %s", string(crData))
}

reason, err := bm.setOptions(backup)
if err != nil {
errs = append(errs, err)
Expand Down
8 changes: 8 additions & 0 deletions cmd/backup-manager/app/import/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
errorutils "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -87,6 +88,13 @@ func (rm *RestoreManager) ProcessRestore() error {
return errorutils.NewAggregate(errs)
}

crData, err := json.Marshal(restore)
if err != nil {
klog.Errorf("failed to marshal restore %v to json, err: %s", restore, err)
} else {
klog.Infof("start to process restore: %s", string(crData))
}

rm.setOptions(restore)

return rm.performRestore(ctx, restore.DeepCopy())
Expand Down
11 changes: 11 additions & 0 deletions cmd/backup-manager/app/restore/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
errorutils "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -96,12 +97,22 @@ func (rm *Manager) ProcessRestore() error {
return fmt.Errorf("no br config in %s", rm)
}

crData, err := json.Marshal(restore)
if err != nil {
klog.Errorf("failed to marshal restore %v to json, err: %s", restore, err)
} else {
klog.Infof("start to process restore: %s", string(crData))
}

if restore.Spec.To == nil {
return rm.performRestore(ctx, restore.DeepCopy(), nil)
}

rm.setOptions(restore)

klog.Infof("start to connect to tidb server (%s:%d) as the .spec.to field is specified",
restore.Spec.To.Host, restore.Spec.To.Port)

var db *sql.DB
var dsn string
err = wait.PollImmediate(constants.PollInterval, constants.CheckTimeout, func() (done bool, err error) {
Expand Down

0 comments on commit df24c47

Please sign in to comment.