MCPcopy
hub / github.com/benbjohnson/litestream / loadFromConfig

Method loadFromConfig

cmd/litestream/restore.go:328–359  ·  view source on GitHub ↗

loadFromConfig returns a replica & updates the restore options from a DB reference.

(_ context.Context, dbPath, configPath string, expandEnv, ifDBNotExists bool, opt *litestream.RestoreOptions)

Source from the content-addressed store, hash-verified

326
327// loadFromConfig returns a replica & updates the restore options from a DB reference.
328func (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.
362func (c *RestoreCommand) Usage() {

Callers 1

RunMethod · 0.95

Calls 4

ReadConfigFileFunction · 0.85
expandFunction · 0.85
NewDBFromConfigFunction · 0.85
DBConfigMethod · 0.80

Tested by

no test coverage detected