|
7 | 7 |
|
8 | 8 | "github.com/percona/percona-backup-mongodb/pbm/backup"
|
9 | 9 | "github.com/percona/percona-backup-mongodb/pbm/config"
|
| 10 | + "github.com/percona/percona-backup-mongodb/pbm/connect" |
10 | 11 | "github.com/percona/percona-backup-mongodb/pbm/ctrl"
|
11 | 12 | "github.com/percona/percona-backup-mongodb/pbm/defs"
|
12 | 13 | "github.com/percona/percona-backup-mongodb/pbm/errors"
|
@@ -93,13 +94,22 @@ func (a *Agent) Restore(ctx context.Context, r *ctrl.RestoreCmd, opid ctrl.OPID,
|
93 | 94 | // XXX: why is backup searched on storage?
|
94 | 95 | bcp, err = restore.LookupBackupMeta(ctx, a.leadConn, r.BackupName, a.brief.Me)
|
95 | 96 | if err != nil {
|
96 |
| - l.Error("define base backup: %v", err) |
| 97 | + err1 := addRestoreMetaWithError(ctx, a.leadConn, l, opid, r, nodeInfo.SetName, |
| 98 | + "define base backup: %v", err) |
| 99 | + if err1 != nil { |
| 100 | + l.Error("failed to save meta: %v", err1) |
| 101 | + } |
97 | 102 | return
|
98 | 103 | }
|
99 | 104 |
|
100 | 105 | if !r.OplogTS.IsZero() && bcp.LastWriteTS.Compare(r.OplogTS) >= 0 {
|
101 |
| - l.Error("snapshot's last write is later than the target time. " + |
102 |
| - "Try to set an earlier snapshot. Or leave the snapshot empty so PBM will choose one.") |
| 106 | + err1 := addRestoreMetaWithError(ctx, a.leadConn, l, opid, r, nodeInfo.SetName, |
| 107 | + "snapshot's last write is later than the target time. "+ |
| 108 | + "Try to set an earlier snapshot. Or leave the snapshot empty "+ |
| 109 | + "so PBM will choose one.") |
| 110 | + if err1 != nil { |
| 111 | + l.Error("failed to save meta: %v", err) |
| 112 | + } |
103 | 113 | return
|
104 | 114 | }
|
105 | 115 | bcpType = bcp.Type
|
@@ -172,3 +182,46 @@ func (a *Agent) Restore(ctx context.Context, r *ctrl.RestoreCmd, opid ctrl.OPID,
|
172 | 182 |
|
173 | 183 | l.Info("recovery successfully finished")
|
174 | 184 | }
|
| 185 | + |
| 186 | +func addRestoreMetaWithError( |
| 187 | + ctx context.Context, |
| 188 | + conn connect.Client, |
| 189 | + l log.LogEvent, |
| 190 | + opid ctrl.OPID, |
| 191 | + cmd *ctrl.RestoreCmd, |
| 192 | + setName string, |
| 193 | + errStr string, |
| 194 | + args ...any, |
| 195 | +) error { |
| 196 | + l.Error(errStr, args...) |
| 197 | + |
| 198 | + meta := &restore.RestoreMeta{ |
| 199 | + Type: defs.LogicalBackup, |
| 200 | + OPID: opid.String(), |
| 201 | + Name: cmd.Name, |
| 202 | + Backup: cmd.BackupName, |
| 203 | + PITR: int64(cmd.OplogTS.T), |
| 204 | + StartTS: time.Now().UTC().Unix(), |
| 205 | + Status: defs.StatusError, |
| 206 | + Error: errStr, |
| 207 | + Replsets: []restore.RestoreReplset{}, |
| 208 | + } |
| 209 | + err := restore.SetRestoreMetaIfNotExists(ctx, conn, meta) |
| 210 | + if err != nil { |
| 211 | + return errors.Wrap(err, "write restore meta to db") |
| 212 | + } |
| 213 | + |
| 214 | + rs := restore.RestoreReplset{ |
| 215 | + Name: setName, |
| 216 | + StartTS: time.Now().UTC().Unix(), |
| 217 | + Status: defs.StatusError, |
| 218 | + Error: errStr, |
| 219 | + Conditions: restore.Conditions{}, |
| 220 | + } |
| 221 | + err = restore.AddRestoreRSMeta(ctx, conn, cmd.Name, rs) |
| 222 | + if err != nil { |
| 223 | + return errors.Wrap(err, "write backup meta to db") |
| 224 | + } |
| 225 | + |
| 226 | + return nil |
| 227 | +} |
0 commit comments