(e *core.RequestEvent)
| 122 | } |
| 123 | |
| 124 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…