source

package
v1.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseExcludeFile

func ParseExcludeFile(path string) ([]string, error)

ParseExcludeFile reads patterns from a file (one per line) and returns them. Comment lines (#) and blank lines are preserved for NewExcludeMatcher to handle.

Types

type ChangeType

type ChangeType string

ChangeType describes the kind of change reported by an IncrementalSource.

const (
	ChangeUpsert ChangeType = "upsert"
	ChangeDelete ChangeType = "delete"
)

type ExcludeMatcher

type ExcludeMatcher struct {
	// contains filtered or unexported fields
}

ExcludeMatcher evaluates gitignore-style exclude patterns against relative file paths. Patterns are evaluated in order; the last matching rule wins.

func NewExcludeMatcher

func NewExcludeMatcher(patterns []string) *ExcludeMatcher

NewExcludeMatcher compiles the given pattern strings into a matcher. Supported syntax (subset of gitignore):

  • Blank lines and lines starting with '#' are ignored.
  • A trailing '/' matches only directories.
  • A leading '!' negates the pattern (re-includes a previously excluded path).
  • '*' matches anything except '/'.
  • '**' matches zero or more path segments.
  • Patterns without '/' match against the file/dir name in any directory.
  • Patterns with '/' are anchored to the root of the walk.

func (*ExcludeMatcher) Empty

func (m *ExcludeMatcher) Empty() bool

Empty returns true if the matcher has no rules.

func (*ExcludeMatcher) Excludes

func (m *ExcludeMatcher) Excludes(relPath string, isDir bool) bool

Excludes reports whether the given relative path should be excluded. isDir must be true when the path refers to a directory. relPath must use forward slashes as separators.

type FileChange

type FileChange struct {
	Type ChangeType
	Meta core.FileMeta
}

FileChange pairs a change type with file metadata. For deletions only Meta.FileID is required.

type GDriveChangeSource

type GDriveChangeSource struct {
	GDriveSource
}

GDriveChangeSource is an IncrementalSource backed by the Google Drive Changes API. It embeds GDriveSource to reuse authentication, full Walk, GetFileStream, and metadata conversion.

func NewGDriveChangeSource

func NewGDriveChangeSource(ctx context.Context, opts ...GDriveOption) (*GDriveChangeSource, error)

func (*GDriveChangeSource) GetStartPageToken

func (s *GDriveChangeSource) GetStartPageToken() (string, error)

GetStartPageToken returns the token representing the current head of the Google Drive change stream.

func (*GDriveChangeSource) Info

func (*GDriveChangeSource) WalkChanges

func (s *GDriveChangeSource) WalkChanges(ctx context.Context, token string, callback func(FileChange) error) (string, error)

WalkChanges iterates over all changes since the given page token. Folder changes are emitted before file changes so that the engine can resolve parent references incrementally.

type GDriveOption

type GDriveOption func(*gDriveOptions)

GDriveOption configures a Google Drive source.

func WithAccountEmail

func WithAccountEmail(email string) GDriveOption

WithAccountEmail explicitly sets the account email instead of calling the API.

func WithCredsPath

func WithCredsPath(path string) GDriveOption

WithCredsPath sets the path to the credentials JSON file. If empty, uses the built-in OAuth client.

func WithDriveID

func WithDriveID(id string) GDriveOption

WithDriveID sets the shared drive ID. If empty, defaults to "My Drive".

func WithGDriveExcludePatterns

func WithGDriveExcludePatterns(patterns []string) GDriveOption

WithGDriveExcludePatterns sets the patterns used to exclude files and folders.

func WithHTTPClient

func WithHTTPClient(client *http.Client) GDriveOption

WithHTTPClient sets a custom HTTP client for OAuth.

func WithRootFolderID

func WithRootFolderID(id string) GDriveOption

WithRootFolderID sets the root folder ID. If empty, defaults to the root of the specified drive.

func WithTokenPath

func WithTokenPath(path string) GDriveOption

WithTokenPath sets the path where the OAuth token is cached.

type GDriveSource

type GDriveSource struct {
	// contains filtered or unexported fields
}

GDriveSource implements Source for Google Drive. By default it backs up the entire "My Drive" root. Set DriveID in GDriveSourceConfig to back up a shared drive instead, and/or set RootFolderID to restrict to a specific folder within the selected drive.

func NewGDriveSource

func NewGDriveSource(ctx context.Context, opts ...GDriveOption) (*GDriveSource, error)

NewGDriveSource creates a new GDriveSource from the given options.

func (*GDriveSource) GetFileStream

func (s *GDriveSource) GetFileStream(fileID string) (io.ReadCloser, error)

func (*GDriveSource) Info

func (s *GDriveSource) Info() core.SourceInfo

func (*GDriveSource) Size

func (s *GDriveSource) Size(ctx context.Context) (*SourceSize, error)

Size returns the total size of the drive. For My Drive it uses the fast about.get endpoint. For shared drives it lists all files and sums sizes.

func (*GDriveSource) Walk

func (s *GDriveSource) Walk(ctx context.Context, callback func(core.FileMeta) error) error

Walk lists all files from Drive. Folders are accumulated in memory (necessary for topological sort) but files are streamed page-by-page to avoid holding the full file list in memory.

type IncrementalSource

type IncrementalSource interface {
	Source
	// GetStartPageToken returns the token representing the current head of
	// the change stream. Call this before a full Walk to capture the baseline.
	GetStartPageToken() (string, error)
	// WalkChanges emits only the entries that changed since token.
	// It returns the new token to persist for the next run.
	WalkChanges(ctx context.Context, token string, callback func(FileChange) error) (newToken string, err error)
}

IncrementalSource token stored in the snapshot. On the first run (empty token) the engine falls back to the full Walk; on subsequent runs only changed entries are emitted.

type LocalOption

type LocalOption func(*localOptions)

LocalOption configures a local filesystem source.

func WithLocalExcludePatterns

func WithLocalExcludePatterns(patterns []string) LocalOption

WithLocalExcludePatterns sets the patterns used to exclude files and folders.

type LocalSource

type LocalSource struct {
	// contains filtered or unexported fields
}

LocalSource implements Source for local filesystem.

func NewLocalSource

func NewLocalSource(rootPath string, opts ...LocalOption) *LocalSource

NewLocalSource creates a local filesystem source rooted at rootPath.

func (*LocalSource) GetFileStream

func (s *LocalSource) GetFileStream(fileID string) (io.ReadCloser, error)

func (*LocalSource) Info

func (s *LocalSource) Info() core.SourceInfo

func (*LocalSource) Size

func (s *LocalSource) Size(ctx context.Context) (*SourceSize, error)

func (*LocalSource) Walk

func (s *LocalSource) Walk(ctx context.Context, callback func(core.FileMeta) error) error

type OneDriveChangeSource

type OneDriveChangeSource struct {
	OneDriveSource
}

OneDriveChangeSource is an IncrementalSource backed by the Microsoft Graph delta API. It embeds OneDriveSource to reuse authentication, full Walk, GetFileStream, and metadata conversion.

func NewOneDriveChangeSource

func NewOneDriveChangeSource(ctx context.Context, opts ...OneDriveOption) (*OneDriveChangeSource, error)

func (*OneDriveChangeSource) GetStartPageToken

func (s *OneDriveChangeSource) GetStartPageToken() (string, error)

GetStartPageToken returns the current head of the OneDrive delta stream by requesting a "latest" delta token. The returned string is a full deltaLink URL.

func (*OneDriveChangeSource) Info

func (*OneDriveChangeSource) WalkChanges

func (s *OneDriveChangeSource) WalkChanges(ctx context.Context, token string, callback func(FileChange) error) (string, error)

WalkChanges iterates over all changes since the given delta token. Folder changes are emitted before file changes so that the engine can resolve parent references incrementally. Returns the new delta token for the next run.

type OneDriveOption

type OneDriveOption func(*oneDriveOptions)

OneDriveOption configures a OneDrive source.

func WithOneDriveClientID

func WithOneDriveClientID(id string) OneDriveOption

WithOneDriveClientID sets the OAuth client ID. If empty, uses the built-in default.

func WithOneDriveExcludePatterns

func WithOneDriveExcludePatterns(patterns []string) OneDriveOption

WithOneDriveExcludePatterns sets the patterns used to exclude files and folders.

func WithOneDriveTokenPath

func WithOneDriveTokenPath(path string) OneDriveOption

WithOneDriveTokenPath sets the path where the OAuth token is cached.

type OneDriveSource

type OneDriveSource struct {
	// contains filtered or unexported fields
}

func NewOneDriveSource

func NewOneDriveSource(ctx context.Context, opts ...OneDriveOption) (*OneDriveSource, error)

NewOneDriveSource creates a new OneDriveSource from the given config.

func (*OneDriveSource) GetFileStream

func (s *OneDriveSource) GetFileStream(fileID string) (io.ReadCloser, error)

func (*OneDriveSource) Info

func (s *OneDriveSource) Info() core.SourceInfo

func (*OneDriveSource) Size

func (s *OneDriveSource) Size(ctx context.Context) (*SourceSize, error)

Size returns the total storage usage for the OneDrive account by calling the /me/drive endpoint which includes quota information.

func (*OneDriveSource) Walk

func (s *OneDriveSource) Walk(ctx context.Context, callback func(core.FileMeta) error) error

type SFTPOption

type SFTPOption func(*sftpOptions)

SFTPOption configures an SFTP filesystem source.

func WithSFTPExcludePatterns

func WithSFTPExcludePatterns(patterns []string) SFTPOption

WithSFTPExcludePatterns sets the patterns used to exclude files and folders.

func WithSFTPSourceBasePath

func WithSFTPSourceBasePath(basePath string) SFTPOption

WithSFTPSourceBasePath sets the root directory on the SFTP server.

func WithSFTPSourceClient

func WithSFTPSourceClient(client *sftp.Client) SFTPOption

WithSFTPSourceClient provides a pre-configured SFTP client, skipping internal connection setup. When set, server and auth options are ignored.

func WithSFTPSourceKey

func WithSFTPSourceKey(keyPath string) SFTPOption

WithSFTPSourceKey sets the path to a PEM-encoded private key for authentication.

func WithSFTPSourcePassword

func WithSFTPSourcePassword(password string) SFTPOption

WithSFTPSourcePassword sets password authentication.

func WithSFTPSourcePort

func WithSFTPSourcePort(port string) SFTPOption

WithSFTPSourcePort sets the SSH port. Defaults to "22" when empty.

func WithSFTPSourceUser

func WithSFTPSourceUser(user string) SFTPOption

WithSFTPSourceUser sets the SSH user for authentication.

type SFTPSource

type SFTPSource struct {
	// contains filtered or unexported fields
}

SFTPSource implements Source for a remote SFTP filesystem.

func NewSFTPSource

func NewSFTPSource(host string, opts ...SFTPOption) (*SFTPSource, error)

NewSFTPSource creates an SFTP-backed source for the given host. Either WithSFTPSourceClient or authentication options must be provided, along with WithSFTPSourceBasePath.

func (*SFTPSource) Close

func (s *SFTPSource) Close() error

Close releases the underlying SFTP and SSH connections.

func (*SFTPSource) GetFileStream

func (s *SFTPSource) GetFileStream(fileID string) (io.ReadCloser, error)

func (*SFTPSource) Info

func (s *SFTPSource) Info() core.SourceInfo

func (*SFTPSource) Size

func (s *SFTPSource) Size(ctx context.Context) (*SourceSize, error)

func (*SFTPSource) Walk

func (s *SFTPSource) Walk(ctx context.Context, callback func(core.FileMeta) error) error

type Source

type Source interface {
	Walk(ctx context.Context, callback func(core.FileMeta) error) error
	GetFileStream(fileID string) (io.ReadCloser, error)
	Info() core.SourceInfo
	Size(ctx context.Context) (*SourceSize, error)
}

Source is the interface for a backup data source (local filesystem, Google Drive, OneDrive, etc.). Implementations MUST ensure that parent folders are visited before their children during Walk.

type SourceSize

type SourceSize struct {
	Bytes int64 `json:"bytes"`
	Files int64 `json:"files"`
}

SourceSize holds the total size of a source.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL