benbjohnson/litestream · error

cannot specify both 'meta-path' and 'meta-dir'

Error message

cannot specify both 'meta-path' and 'meta-dir'

What it means

Directory replication lets you place per-database metadata either under a meta directory derived from each DB's relative path ('meta-dir') or via an explicitly derived meta path ('meta-path'). Specifying both is ambiguous, so NewDBsFromDirectoryConfig rejects the config upfront to prevent silent state corruption.

Source

Thrown at cmd/litestream/main.go:824

	if err != nil {
		return nil, err
	}
	db.Replica = r

	return db, nil
}

// NewDBsFromDirectoryConfig scans a directory and creates DB instances for all SQLite databases found.
func NewDBsFromDirectoryConfig(dbc *DBConfig) ([]*litestream.DB, error) {
	if dbc.Dir == "" {
		return nil, fmt.Errorf("directory path is required for directory replication")
	}

	if dbc.Pattern == "" {
		return nil, fmt.Errorf("pattern is required for directory replication")
	}
	if dbc.MetaPath != nil && dbc.MetaDir != nil {
		return nil, fmt.Errorf("cannot specify both 'meta-path' and 'meta-dir'")
	}

	dirPath, err := expand(dbc.Dir)
	if err != nil {
		return nil, err
	}

	// Find all SQLite databases in the directory
	dbPaths, err := FindSQLiteDatabases(dirPath, dbc.Pattern, dbc.Recursive)
	if err != nil {
		return nil, fmt.Errorf("failed to scan directory %s: %w", dirPath, err)
	}

	if len(dbPaths) == 0 && !dbc.Watch {
		return nil, fmt.Errorf("no SQLite databases found in directory %s with pattern %s", dirPath, dbc.Pattern)
	}

	// Create DB instances for each found database

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Remove 'meta-path' and keep only 'meta-dir' (preferred for directory replication, since it derives per-DB paths automatically).
  2. Alternatively remove 'meta-dir' and keep 'meta-path' if you need a custom per-DB metadata layout.
  3. For single-database replication (no 'dir'), use 'meta-path' only.

Example fix

# before
dbs:
  - dir: /data
    pattern: "*.db"
    meta-path: /var/lib/litestream/meta
    meta-dir: /var/lib/litestream/meta

# after
dbs:
  - dir: /data
    pattern: "*.db"
    meta-dir: /var/lib/litestream/meta
Defensive patterns

Strategy: validation

Validate before calling

if dbc.MetaPath != nil && dbc.MetaDir != nil {
    return fmt.Errorf("set only one of meta-path / meta-dir")
}

Prevention

When it happens

Trigger: Calling NewDBsFromDirectoryConfig with a DBConfig where both MetaPath and MetaDir are non-nil (both 'meta-path:' and 'meta-dir:' set in the same db stanza).

Common situations: Merging two example configs together; copying a single-DB config (which uses meta-path) into a directory-replication stanza (which uses meta-dir); enabling directory replication on an existing single-DB entry without removing the old meta-path key.

Related errors


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/5879f0de7b1eb15a. Report an issue: GitHub.