MCPcopy
hub / github.com/pocketbase/pocketbase / backupRestore

Function backupRestore

apis/backup.go:124–160  ·  view source on GitHub ↗
(e *core.RequestEvent)

Source from the content-addressed store, hash-verified

122}
123
124func backupRestore(e *core.RequestEvent) error {
125 if e.App.Store().Has(core.StoreKeyActiveBackup) {
126 return e.BadRequestError("Try again later - another backup/restore process has already been started.", nil)
127 }
128
129 key := e.Request.PathValue("key")
130
131 existsCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
132 defer cancel()
133
134 fsys, err := e.App.NewBackupsFilesystem()
135 if err != nil {
136 return e.InternalServerError("Failed to load backups filesystem.", err)
137 }
138 defer fsys.Close()
139
140 fsys.SetContext(existsCtx)
141
142 if exists, err := fsys.Exists(key); !exists {
143 return e.BadRequestError("Missing or invalid backup file.", err)
144 }
145
146 routine.FireAndForget(func() {
147 // give some optimistic time to write the response before restarting the app
148 time.Sleep(1 * time.Second)
149
150 // wait max 10 minutes to fetch the backup
151 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
152 defer cancel()
153
154 if err := e.App.RestoreBackup(ctx, key); err != nil {
155 e.App.Logger().Error("Failed to restore backup", "key", key, "error", err.Error())
156 }
157 })
158
159 return e.NoContent(http.StatusNoContent)
160}

Callers

nothing calls this directly

Calls 13

FireAndForgetFunction · 0.92
BadRequestErrorMethod · 0.80
InternalServerErrorMethod · 0.80
NoContentMethod · 0.80
StoreMethod · 0.65
NewBackupsFilesystemMethod · 0.65
CloseMethod · 0.65
SetContextMethod · 0.65
RestoreBackupMethod · 0.65
ErrorMethod · 0.65
LoggerMethod · 0.65
HasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…