MCPcopy
hub / github.com/dgraph-io/dgraph / ProcessBackupRequest

Function ProcessBackupRequest

worker/backup.go:238–427  ·  view source on GitHub ↗
(ctx context.Context, req *pb.BackupRequest)

Source from the content-addressed store, hash-verified

236}
237
238func ProcessBackupRequest(ctx context.Context, req *pb.BackupRequest) error {
239 if err := x.HealthCheck(); err != nil {
240 glog.Errorf("Backup canceled, not ready to accept requests: %s", err)
241 return err
242 }
243
244 // Grab the lock here to avoid more than one request to be processed at the same time.
245 backupLock.Lock()
246 defer backupLock.Unlock()
247
248 backupSuccessful := false
249 ostats.Record(ctx, x.NumBackups.M(1), x.PendingBackups.M(1))
250 defer func() {
251 if backupSuccessful {
252 ostats.Record(ctx, x.NumBackupsSuccess.M(1), x.PendingBackups.M(-1))
253 } else {
254 ostats.Record(ctx, x.NumBackupsFailed.M(1), x.PendingBackups.M(-1))
255 }
256 }()
257
258 ts, err := Timestamps(ctx, &pb.Num{ReadOnly: true})
259 if err != nil {
260 glog.Errorf("Unable to retrieve readonly timestamp for backup: %s", err)
261 return err
262 }
263
264 req.ReadTs = ts.ReadOnly
265 req.UnixTs = time.Now().UTC().Format("20060102.150405.000")
266
267 // Read the manifests to get the right timestamp from which to start the backup.
268 uri, err := url.Parse(req.Destination)
269 if err != nil {
270 return err
271 }
272 handler, err := NewUriHandler(uri, GetCredentialsFromRequest(req))
273 if err != nil {
274 return err
275 }
276 if !handler.DirExists("./") {
277 if err := handler.CreateDir("./"); err != nil {
278 return errors.Wrap(err, "while creating backup directory")
279 }
280 }
281 latestManifest, err := GetLatestManifest(handler, uri)
282 if err != nil {
283 return err
284 }
285
286 req.SinceTs = latestManifest.ValidReadTs()
287 // To force a full backup we'll set the sinceTs to zero.
288 if req.ForceFull {
289 req.SinceTs = 0
290 } else {
291 if err := checkBackupReadTsAdvanced(latestManifest, req.ReadTs); err != nil {
292 return err
293 }
294
295 if x.WorkerConfig.EncryptionKey != nil {

Callers 1

runMethod · 0.85

Calls 15

DirExistsMethod · 0.95
CreateDirMethod · 0.95
CloseMethod · 0.95
CompleteBackupMethod · 0.95
HealthCheckFunction · 0.92
GetRandomNameFunction · 0.92
TimestampsFunction · 0.85
NewUriHandlerFunction · 0.85
GetLatestManifestFunction · 0.85
UpdateMembershipStateFunction · 0.85

Tested by

no test coverage detected