loadFromConfig returns a replica & updates the restore options from a DB reference.
(_ context.Context, dbPath, configPath string, expandEnv, ifDBNotExists bool, opt *litestream.RestoreOptions)
| 326 | |
| 327 | // loadFromConfig returns a replica & updates the restore options from a DB reference. |
| 328 | func (c *RestoreCommand) loadFromConfig(_ context.Context, dbPath, configPath string, expandEnv, ifDBNotExists bool, opt *litestream.RestoreOptions) (*litestream.Replica, error) { |
| 329 | // Load configuration. |
| 330 | config, err := ReadConfigFile(configPath, expandEnv) |
| 331 | if err != nil { |
| 332 | return nil, err |
| 333 | } |
| 334 | |
| 335 | // Lookup database from configuration file by path. |
| 336 | if dbPath, err = expand(dbPath); err != nil { |
| 337 | return nil, err |
| 338 | } |
| 339 | dbConfig := config.DBConfig(dbPath) |
| 340 | if dbConfig == nil { |
| 341 | return nil, fmt.Errorf("database not found in config: %s", dbPath) |
| 342 | } |
| 343 | db, err := NewDBFromConfig(dbConfig) |
| 344 | if err != nil { |
| 345 | return nil, err |
| 346 | } |
| 347 | |
| 348 | // Restore into original database path if not specified. |
| 349 | if opt.OutputPath == "" { |
| 350 | opt.OutputPath = dbPath |
| 351 | } |
| 352 | |
| 353 | // Exit successfully if the output file already exists. |
| 354 | if _, err := os.Stat(opt.OutputPath); !os.IsNotExist(err) && ifDBNotExists { |
| 355 | return nil, errSkipDBExists |
| 356 | } |
| 357 | |
| 358 | return db.Replica, nil |
| 359 | } |
| 360 | |
| 361 | // Usage prints the help screen to STDOUT. |
| 362 | func (c *RestoreCommand) Usage() { |
no test coverage detected