Skip to content

Commit c3a3637

Browse files
committed
fixup! Handle recovery target when recovering from backup
1 parent 9ab6175 commit c3a3637

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

internal/pgbackrest/api/stanza.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@ type Archive struct {
3232
Start string `json:"start"`
3333
Stop string `json:"stop"`
3434
}
35+
type DatabaseInfo struct {
36+
Id int64 `json:"id"`
37+
RepoKey int64 `json:"repo-key"`
38+
}
3539

3640
type BackupInfo struct {
37-
Archive Archive `json:"archive"`
38-
Label string `json:"label"`
39-
Lsn Lsn `json:"lsn"`
40-
Prior string `json:"prior"`
41-
Timestamp Timestamp `json:"timestamp"`
42-
Type string `json:"type"`
41+
Archive Archive `json:"archive"`
42+
Database DatabaseInfo `json:"database"`
43+
Label string `json:"label"`
44+
Lsn Lsn `json:"lsn"`
45+
Prior string `json:"prior"`
46+
Timestamp Timestamp `json:"timestamp"`
47+
Type string `json:"type"`
4348
}
4449

4550
type RecoveryWindow struct {

internal/restore/restore.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ func (impl JobHookImpl) GetCapabilities(
4141

4242
func recoveryTargetToRestoreOptions(
4343
cluster *cnpgv1.Cluster,
44-
) ([]string, error) {
44+
) (pgbackrest.RestoreOptions, error) {
4545
// empty slice if no bootstrap or recovery target
4646
b := cluster.Spec.Bootstrap
4747
if b == nil || b.Recovery == nil || b.Recovery.RecoveryTarget == nil {
48-
return []string{}, nil
48+
return pgbackrest.RestoreOptions{}, nil
4949
}
5050

5151
// otherwise try to converrt the RecoveryTarget to
@@ -79,7 +79,7 @@ func recoveryTargetToRestoreOptions(
7979

8080
// then convert it to list of envvar
8181
// (should be done by the caller ?)
82-
return res.ToEnv()
82+
return res, nil
8383
}
8484

8585
func (impl JobHookImpl) Restore(
@@ -104,12 +104,15 @@ func (impl JobHookImpl) Restore(
104104
if err != nil {
105105
return nil, err
106106
}
107-
recoveryOption, err := recoveryTargetToRestoreOptions(cConfig.Cluster)
107+
recovOption, err := recoveryTargetToRestoreOptions(cConfig.Cluster)
108108
if err != nil {
109109
return nil, err
110110
}
111-
env = append(env, recoveryOption...)
112-
contextLogger.Info("recoveryOption are", "recov", env)
111+
recovEnv, err := recovOption.ToEnv()
112+
if err != nil {
113+
return nil, err
114+
}
115+
env = append(env, recovEnv...)
113116
pgb := pgbackrest.NewPgBackrest(env)
114117
errCh := pgb.Restore(ctx)
115118
if err := <-errCh; err != nil {

0 commit comments

Comments
 (0)