backup

package
v0.0.0-...-43b4f2a Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNoProvider = errors.New("Provider is not set")
)

Functions

func RegisterProvider

func RegisterProvider(providerName string, factory ProviderFactory)

RegisterProvider registers a backup provider with a unique name

Types

type AuthService

type AuthService interface {
	SignIn() (string, error)
}

AuthService is the interface that the backup provider needs in order to function. Because the authentication can be in many forms (also multiple platforms) it can't be implemented as part of the backup provider but rather should be passed from the running app/platform. For example in Android the authentication would be done by using the AccountManager API.

type BackupInfo

type BackupInfo struct {
	BackupDir string
	Info      *SnapshotInfo
}

type BackupRequest

type BackupRequest struct {
	BackupNodeData bool
	BackupAppData  bool
}

type DataPreparer

type DataPreparer func() (paths []string, nodeID string, err error)

DataPreparer should be responsible to prepare the data needed to be backed up. The data contains the file paths and the nodeID.

type Error

type Error struct {
	// Exception contains the type of the exception returned by
	// the server.
	Exception string `xml:"exception"`

	// Message contains the error message string from the server.
	Message string `xml:"message"`
}

Error type encapsulates the returned error messages from the server.

func (*Error) Error

func (e *Error) Error() string

type FileInfo

type FileInfo struct {
	XMLName xml.Name `xml:"response"`
	Href    string   `xml:"href"`
	Path    string
	Stat    FilePropStats `xml:"propstat"`
}

type FileProp

type FileProp struct {
	XMLName      xml.Name `xml:"prop"`
	LastModified string   `xml:"getlastmodified"`
}

type FilePropStats

type FilePropStats struct {
	XMLName xml.Name   `xml:"propstat"`
	Props   []FileProp `xml:"prop"`
}

type GoogleDriveProvider

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

GoogleDriveProvider is an implementation of backup.Provider interface. It uses app data in google drive as a storage mechanism. Backups are stored in the following manner:

  1. Nodes backup will be saved directly under "appDataFolder", which is the user data directory in google drive. Folders will be named by the convention: "snapshot-<node_id>".
  2. When a request for backup lands, this provider will do the following: 2.1 Create a nested folder under the node folder. 2.2 Save all the backup files under this created folder. 2.3 Update the "activeBackupFolderProperty" metadata property of the node folder to be the newly created folder id. 2.4 Delete stale backup folder that are not in use anymore for this node id.
  3. When a request for restore (download) lands, this provider will do the following: 3.1 Identify the "active backup folder" by reading the metadata property of the node folder. 3.2 Download the files 3.3 Mark this backup as "restored by this instance" by assign the value "backupID" to the node metadata property "backupIDProperty". This value will be used to detect the problematic case where two nodes are running the same backup...

func NewGoogleDriveProvider

func NewGoogleDriveProvider(authService AuthService, log btclog.Logger) (*GoogleDriveProvider, error)

NewGoogleDriveProvider creates a new instance of GoogleDriveProvider. It needs AuthService that will provide the access token, and refresh access token functionality It implements the backup.Provider interface by using google drive as storage.

func (*GoogleDriveProvider) AvailableSnapshots

func (p *GoogleDriveProvider) AvailableSnapshots() ([]SnapshotInfo, error)

AvailableSnapshots fetches all existing backup snapshots that exist in the user app data. There is only one snapshot per node id.

func (*GoogleDriveProvider) DownloadBackupFiles

func (p *GoogleDriveProvider) DownloadBackupFiles(nodeID, backupID string) ([]string, error)

DownloadBackupFiles is responsible for download a specific node backup and updating. that this backup was now restored by this instance represented by "backupID"

func (*GoogleDriveProvider) GetProviderTimestamp

func (p *GoogleDriveProvider) GetProviderTimestamp(nodeID string) (time.Time, error)

GetProviderTimestamp edits the timestamp metadata for the given node's file and returns a time if successfull.

func (*GoogleDriveProvider) SetTor

func (p *GoogleDriveProvider) SetTor(torConfig *tor.TorConfig)

func (*GoogleDriveProvider) TestAuth

func (p *GoogleDriveProvider) TestAuth() error

func (*GoogleDriveProvider) UploadBackupFiles

func (p *GoogleDriveProvider) UploadBackupFiles(file string, nodeID string, encryptionType string, timestamp time.Time) (string, error)

UploadBackupFiles uploads the backup files related to a specific node to google drive. It does the following:

  1. Creates a fresh new folder under the node folder.
  2. Uploads all files to the newly created folder.
  3. update the node folder metadata property "activeBackupFolderProperty" to contain the id of the new folder.

type ListFileResponse

type ListFileResponse struct {
	XMLName xml.Name   `xml:"multistatus"`
	Files   []FileInfo `xml:"response"`
}

type Manager

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

Manager holds the data needed for the backup to execute its work.

func NewManager

func NewManager(
	providerName string,
	authService AuthService,
	onServiceEvent func(event data.NotificationEvent),
	prepareData DataPreparer,
	config *config.Config,
	log btclog.Logger) (*Manager, error)

NewManager creates a new Manager

func (*Manager) AvailableSnapshots

func (b *Manager) AvailableSnapshots() ([]SnapshotInfo, error)

AvailableSnapshots returns a list of snsapshot that the backup provider reports it has. Every snapshot is for a specific node id.

func (*Manager) Download

func (b *Manager) Download(nodeID string) ([]string, error)

Download handles all the download process: 1. Downloading the backed up files for a specific node id.

func (*Manager) EnsureLatestBackup

func (b *Manager) EnsureLatestBackup(nodeID string) (bool, error)

EnsureLatestBackup checks whenever a given local state is newer than our snapshot. if there is no local state, it returns true.

func (*Manager) GetProvider

func (b *Manager) GetProvider() Provider

func (*Manager) IsSafeToRunNode

func (b *Manager) IsSafeToRunNode(nodeID string) (bool, error)

IsSafeToRunNode checks if it is safe for this breez instance to run a specific node. It is considered safe if we don't know of another instance which is the last to restore this node (nodeID)

func (*Manager) LatestBackupTime

func (b *Manager) LatestBackupTime() (time.Time, error)

LatestBackupInfo returns the latest backup time which is saved locally. If the file does not exist, it returns the zero time and an error.

func (*Manager) RequestAppDataBackup

func (b *Manager) RequestAppDataBackup()

func (*Manager) RequestCommitmentChangedBackup

func (b *Manager) RequestCommitmentChangedBackup()

RequestCommitmentChangedBackup is called when the commitment transaction of the channel is changed. We add a small delay because we know such changes are coming in batch

func (*Manager) RequestFullBackup

func (b *Manager) RequestFullBackup()

func (*Manager) RequestNodeBackup

func (b *Manager) RequestNodeBackup()

RequestBackup push a request for the backup files of breez

func (*Manager) Restore

func (b *Manager) Restore(nodeID string, key []byte) ([]string, error)

Restore handles all the restoring process: 1. Downloading the backed up files for a specific node id. 2. Put the backed up files in the right place according to the configuration

func (*Manager) SetBackupProvider

func (b *Manager) SetBackupProvider(providerName, authData string) error

func (*Manager) SetEncryptionKey

func (b *Manager) SetEncryptionKey(encKey []byte, encryptionType string) error

SetEncryptionKey sets the key which should be used to encrypt the backup files

func (*Manager) SetLatestBackupTime

func (b *Manager) SetLatestBackupTime(time time.Time, nodeID string) error

SetLatestBackupTime takes two pararms time.Time, nodeID and saves it locally. If the file already exists it overwrite it.

func (*Manager) SetProvider

func (b *Manager) SetProvider(p Provider)

func (*Manager) SetTorConfig

func (b *Manager) SetTorConfig(torConfig *tor.TorConfig)

func (*Manager) Start

func (b *Manager) Start() error

Start is the main go routine that listens to backup requests and is resopnsible for executing it.

func (*Manager) Stop

func (b *Manager) Stop() error

Stop stops the BackupService and wait for complete shutdown.

func (*Manager) UpdateLatestBackupTime

func (b *Manager) UpdateLatestBackupTime(nodeID string) error

type Provider

type Provider interface {
	UploadBackupFiles(file string, nodeID string, encryptionType string, timestamp time.Time) (string, error)
	AvailableSnapshots() ([]SnapshotInfo, error)
	DownloadBackupFiles(nodeID, backupID string) ([]string, error)
	SetTor(t *tor.TorConfig)
	GetProviderTimestamp(nodeID string) (time.Time, error)
	TestAuth() error
}

Provider represents the functionality needed to be implemented for any backend backup storage provider. This provider will be used and inststiated by the service.

type ProviderData

type ProviderData struct {
	User     string
	Password string
	Url      string
	BreezDir string
}

type ProviderError

type ProviderError interface {
	Error() string
	IsAuthError() bool
}

ProviderError is the error that is used by the Provider to tell the BackupService about the error happened and if there was an error in the authentication.

type ProviderFactory

type ProviderFactory func(providerFactoryInfo ProviderFactoryInfo) (Provider, error)

ProviderFactory is a factory for create a specific provider. This is the function needed to be implemented for a new provider to be registered and used.

type ProviderFactoryInfo

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

type RemoteServerProvider

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

func NewRemoteServerProvider

func NewRemoteServerProvider(
	authData ProviderData,
	log btclog.Logger,
	torConfig *tor.TorConfig,
) (*RemoteServerProvider, error)

func (*RemoteServerProvider) AvailableSnapshots

func (n *RemoteServerProvider) AvailableSnapshots() ([]SnapshotInfo, error)

func (*RemoteServerProvider) DownloadBackupFiles

func (n *RemoteServerProvider) DownloadBackupFiles(nodeID, backupID string) ([]string, error)

func (*RemoteServerProvider) GetProviderTimestamp

func (n *RemoteServerProvider) GetProviderTimestamp(nodeID string) (time.Time, error)

Upload a mock file to the breez server in order to be able to use the timestamp for the backup.

func (*RemoteServerProvider) SetTor

func (n *RemoteServerProvider) SetTor(torConfig *tor.TorConfig)

func (*RemoteServerProvider) TestAuth

func (n *RemoteServerProvider) TestAuth() (err error)

func (*RemoteServerProvider) UploadBackupFiles

func (n *RemoteServerProvider) UploadBackupFiles(file string, nodeID string, encryptionType string, timestamp time.Time) (
	string, error)

type Service

type Service interface {
	RequestBackup()
	Restore(nodeID string) error
	AvailableSnapshots() ([]SnapshotInfo, error)
}

Service is the interface to expose from this package as Backup Service API. These functions will be used from the application layer.

type SnapshotInfo

type SnapshotInfo struct {
	NodeID         string
	BackupID       string
	Encrypted      bool
	EncryptionType string
	ModifiedTime   time.Time
}

SnapshotInfo is an existing backup information for a specific node id.

type TokenSource

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

TokenSource is a structure that implements the auth2.TokenSource interface to be used by GoogleDriveBackupProvider

func (*TokenSource) Token

func (s *TokenSource) Token() (*oauth2.Token, error)

Token retrieved a token from the AuthService provided

type WebdavClient

type WebdavClient struct {
	Url       *url.URL
	Username  string
	Password  string
	TorConfig *tor.TorConfig
}

A client represents a client connection to a {own|next}cloud

func Dial

func Dial(host, username, password string) (*WebdavClient, error)

Dial connects to an {own|next}Cloud instance at the specified address using the given credentials.

func (*WebdavClient) Delete

func (c *WebdavClient) Delete(path string) error

Delete removes the specified folder from the cloud.

func (*WebdavClient) DirectoryExists

func (c *WebdavClient) DirectoryExists(path string) bool

func (*WebdavClient) Download

func (c *WebdavClient) Download(path string) ([]byte, error)

Download downloads a file from the specified path.

func (*WebdavClient) ListDir

func (c *WebdavClient) ListDir(path string) (*ListFileResponse, error)

func (*WebdavClient) Mkdir

func (c *WebdavClient) Mkdir(path string) error

Mkdir creates a new directory on the cloud with the specified name.

func (*WebdavClient) Upload

func (c *WebdavClient) Upload(src []byte, dest string) error

Upload uploads the specified source to the specified destination path on the cloud.

type WebdavRequestError

type WebdavRequestError struct {
	StatusCode int
}

func (*WebdavRequestError) Error

func (m *WebdavRequestError) Error() string

Jump to

Keyboard shortcuts

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