Restore restores a PostgreSQL cluster from a backup into the object storage
(ctx context.Context, cli client.Client)
| 268 | |
| 269 | // Restore restores a PostgreSQL cluster from a backup into the object storage |
| 270 | func (info InitInfo) Restore(ctx context.Context, cli client.Client) error { |
| 271 | contextLogger := log.FromContext(ctx) |
| 272 | |
| 273 | cluster, err := info.loadCluster(ctx, cli) |
| 274 | if err != nil { |
| 275 | return err |
| 276 | } |
| 277 | |
| 278 | coredumpFilter := cluster.GetCoredumpFilter() |
| 279 | if err := system.SetCoredumpFilter(coredumpFilter); err != nil { |
| 280 | return err |
| 281 | } |
| 282 | |
| 283 | if cluster.ShouldRecoveryCreateApplicationDatabase() { |
| 284 | info.ApplicationUser = cluster.GetApplicationDatabaseOwner() |
| 285 | info.ApplicationDatabase = cluster.GetApplicationDatabaseName() |
| 286 | } |
| 287 | |
| 288 | var envs []string |
| 289 | var config string |
| 290 | |
| 291 | //nolint:nestif |
| 292 | if pluginConfiguration := cluster.GetRecoverySourcePlugin(); pluginConfiguration != nil { |
| 293 | contextLogger.Info("Restore through plugin detected, proceeding...") |
| 294 | res, err := restoreViaPlugin(ctx, cluster, pluginConfiguration) |
| 295 | if err != nil { |
| 296 | return err |
| 297 | } |
| 298 | if res == nil { |
| 299 | return errors.New("empty response from restoreViaPlugin, programmatic error") |
| 300 | } |
| 301 | |
| 302 | processEnvironment, err := envmap.ParseEnviron() |
| 303 | if err != nil { |
| 304 | return fmt.Errorf("error while parsing the process environment: %w", err) |
| 305 | } |
| 306 | |
| 307 | pluginEnvironment, err := envmap.Parse(res.Envs) |
| 308 | if err != nil { |
| 309 | return fmt.Errorf("error while parsing the plugin environment: %w", err) |
| 310 | } |
| 311 | |
| 312 | envs = envmap.Merge(processEnvironment, pluginEnvironment).StringSlice() |
| 313 | config = res.RestoreConfig |
| 314 | } else { |
| 315 | // Before starting the restore we check if the archive destination is safe to use |
| 316 | // otherwise, we stop creating the cluster |
| 317 | err = info.checkBackupDestination(ctx, cli, cluster) |
| 318 | if err != nil { |
| 319 | return err |
| 320 | } |
| 321 | |
| 322 | // If we need to download data from a backup, we do it |
| 323 | backup, env, err := info.loadBackup(ctx, cli, cluster) |
| 324 | if err != nil { |
| 325 | return err |
| 326 | } |
| 327 |
nothing calls this directly
no test coverage detected