db

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2017 License: MIT Imports: 13 Imported by: 7

Documentation

Index

Constants

View Source
const (
	BackupOperation  = "backup"
	RestoreOperation = "restore"
	PurgeOperation   = "purge"

	PendingStatus  = "pending"
	RunningStatus  = "running"
	CanceledStatus = "canceled"
	FailedStatus   = "failed"
	DoneStatus     = "done"
)

Variables

View Source
var CurrentSchema int = currentSchema()
View Source
var Schemas = map[int]Schema{
	1: v1Schema{},
	2: v2Schema{},
	3: v3Schema{},
}

Functions

func Pattern added in v0.4.1

func Pattern(glob string) string

Turns globs ('*search*') into SQL patterns ('%search%')

func ValidateEffectiveUnix added in v0.4.1

func ValidateEffectiveUnix(effective time.Time) int64

Types

type Archive added in v0.6.4

type Archive struct {
	UUID           uuid.UUID `json:"uuid"`
	StoreKey       string    `json:"key"`
	TakenAt        Timestamp `json:"taken_at"`
	ExpiresAt      Timestamp `json:"expires_at"`
	Notes          string    `json:"notes"`
	Status         string    `json:"status"`
	PurgeReason    string    `json:"purge_reason"`
	TargetUUID     uuid.UUID `json:"target_uuid"`
	TargetName     string    `json:"target_name"`
	TargetPlugin   string    `json:"target_plugin"`
	TargetEndpoint string    `json:"target_endpoint"`
	StoreUUID      uuid.UUID `json:"store_uuid"`
	StoreName      string    `json:"store_name"`
	StorePlugin    string    `json:"store_plugin"`
	StoreEndpoint  string    `json:"store_endpoint"`
}

type ArchiveFilter

type ArchiveFilter struct {
	ForTarget     string
	ForStore      string
	Before        *time.Time
	After         *time.Time
	ExpiresBefore *time.Time
	WithStatus    []string
	WithOutStatus []string
	Limit         string
}

func (*ArchiveFilter) Query

func (f *ArchiveFilter) Query() (string, []interface{})

type DB

type DB struct {
	Driver string
	DSN    string
	// contains filtered or unexported fields
}

func (*DB) Alias

func (db *DB) Alias(name string, sql string) error

Register a SQL query alias

func (*DB) AnnotateArchive

func (db *DB) AnnotateArchive(id uuid.UUID, notes string) error

func (*DB) AnnotateJob

func (db *DB) AnnotateJob(id uuid.UUID, name string, summary string) error

func (*DB) AnnotateRetentionPolicy

func (db *DB) AnnotateRetentionPolicy(id uuid.UUID, name string, summary string) error

func (*DB) AnnotateSchedule

func (db *DB) AnnotateSchedule(id uuid.UUID, name string, summary string) error

func (*DB) AnnotateStore

func (db *DB) AnnotateStore(id uuid.UUID, name string, summary string) error

func (*DB) AnnotateTarget

func (db *DB) AnnotateTarget(id uuid.UUID, name string, summary string) error

func (*DB) CancelTask

func (db *DB) CancelTask(id uuid.UUID, effective time.Time) error

func (*DB) CheckCurrentSchema

func (db *DB) CheckCurrentSchema() error

func (*DB) CompleteTask

func (db *DB) CompleteTask(id uuid.UUID, effective time.Time) error

func (*DB) Connect

func (db *DB) Connect() error

Connect to the backend database

func (*DB) Connected

func (db *DB) Connected() bool

Are we connected?

func (*DB) Copy

func (db *DB) Copy() *DB

func (*DB) Count

func (db *DB) Count(sql_or_name string, args ...interface{}) (uint, error)

Execute a data query (SELECT) and return how many rows were returned

func (*DB) CreateBackupTask

func (db *DB) CreateBackupTask(owner string, job *Job) (*Task, error)

func (*DB) CreateJob

func (db *DB) CreateJob(target, store, schedule, retention string, paused bool) (uuid.UUID, error)

func (*DB) CreatePurgeTask

func (db *DB) CreatePurgeTask(owner string, archive *Archive, agent string) (*Task, error)

func (*DB) CreateRestoreTask

func (db *DB) CreateRestoreTask(owner string, archive *Archive, target *Target) (*Task, error)

func (*DB) CreateRetentionPolicy

func (db *DB) CreateRetentionPolicy(expiry uint) (uuid.UUID, error)

func (*DB) CreateSchedule

func (db *DB) CreateSchedule(ts string) (uuid.UUID, error)

func (*DB) CreateStore

func (db *DB) CreateStore(plugin string, endpoint interface{}) (uuid.UUID, error)

func (*DB) CreateTarget

func (db *DB) CreateTarget(plugin string, endpoint interface{}, agent string) (uuid.UUID, error)

func (*DB) CreateTaskArchive

func (db *DB) CreateTaskArchive(id uuid.UUID, key string, effective time.Time) (uuid.UUID, error)

func (*DB) DeleteArchive

func (db *DB) DeleteArchive(id uuid.UUID) (bool, error)

func (*DB) DeleteJob

func (db *DB) DeleteJob(id uuid.UUID) (bool, error)

func (*DB) DeleteRetentionPolicy

func (db *DB) DeleteRetentionPolicy(id uuid.UUID) (bool, error)

func (*DB) DeleteSchedule

func (db *DB) DeleteSchedule(id uuid.UUID) (bool, error)

func (*DB) DeleteStore

func (db *DB) DeleteStore(id uuid.UUID) (bool, error)

func (*DB) DeleteTarget

func (db *DB) DeleteTarget(id uuid.UUID) (bool, error)

func (*DB) Disconnect

func (db *DB) Disconnect() error

Disconnect from the backend database

func (*DB) Exec

func (db *DB) Exec(sql_or_name string, args ...interface{}) error

Execute a named, non-data query (INSERT, UPDATE, DELETE, etc.)

func (*DB) ExpireArchive

func (db *DB) ExpireArchive(id uuid.UUID) error

func (*DB) FailTask

func (db *DB) FailTask(id uuid.UUID, effective time.Time) error

func (*DB) GetAllArchives added in v0.6.4

func (db *DB) GetAllArchives(filter *ArchiveFilter) ([]*Archive, error)

func (*DB) GetAllJobs added in v0.6.4

func (db *DB) GetAllJobs(filter *JobFilter) ([]*Job, error)

func (*DB) GetAllRetentionPolicies added in v0.6.4

func (db *DB) GetAllRetentionPolicies(filter *RetentionFilter) ([]*RetentionPolicy, error)

func (*DB) GetAllSchedules added in v0.6.4

func (db *DB) GetAllSchedules(filter *ScheduleFilter) ([]*Schedule, error)

func (*DB) GetAllStores added in v0.6.4

func (db *DB) GetAllStores(filter *StoreFilter) ([]*Store, error)

func (*DB) GetAllTargets added in v0.6.4

func (db *DB) GetAllTargets(filter *TargetFilter) ([]*Target, error)

func (*DB) GetAllTasks added in v0.6.4

func (db *DB) GetAllTasks(filter *TaskFilter) ([]*Task, error)

func (*DB) GetArchive added in v0.6.4

func (db *DB) GetArchive(id uuid.UUID) (*Archive, error)

func (*DB) GetArchivesNeedingPurge

func (db *DB) GetArchivesNeedingPurge() ([]*Archive, error)

func (*DB) GetExpiredArchives

func (db *DB) GetExpiredArchives() ([]*Archive, error)

func (*DB) GetJob added in v0.6.4

func (db *DB) GetJob(id uuid.UUID) (*Job, error)

func (*DB) GetRestoreTaskDetails

func (db *DB) GetRestoreTaskDetails(archive, target uuid.UUID, storePlugin, storeEndpoint, storeKey, targetPlugin, targetEndpoint, agent *string) error

func (*DB) GetRetentionPolicy added in v0.6.4

func (db *DB) GetRetentionPolicy(id uuid.UUID) (*RetentionPolicy, error)

func (*DB) GetSchedule added in v0.6.4

func (db *DB) GetSchedule(id uuid.UUID) (*Schedule, error)

func (*DB) GetStore added in v0.6.4

func (db *DB) GetStore(id uuid.UUID) (*Store, error)

func (*DB) GetTarget added in v0.6.4

func (db *DB) GetTarget(id uuid.UUID) (*Target, error)

func (*DB) GetTask added in v0.6.4

func (db *DB) GetTask(id uuid.UUID) (*Task, error)

func (*DB) InvalidateArchive

func (db *DB) InvalidateArchive(id uuid.UUID) error

func (*DB) IsTaskRunnable added in v0.6.6

func (db *DB) IsTaskRunnable(task *Task) (bool, error)

func (*DB) PauseJob

func (db *DB) PauseJob(id uuid.UUID) (bool, error)

func (*DB) PauseOrUnpauseJob

func (db *DB) PauseOrUnpauseJob(id uuid.UUID, pause bool) (bool, error)

func (*DB) PurgeArchive

func (db *DB) PurgeArchive(id uuid.UUID) error

func (*DB) Query

func (db *DB) Query(sql_or_name string, args ...interface{}) (*sql.Rows, error)

Execute a named, data query (SELECT)

func (*DB) SchemaVersion

func (db *DB) SchemaVersion() (int, error)

func (*DB) Setup

func (db *DB) Setup() error

func (*DB) StartTask

func (db *DB) StartTask(id uuid.UUID, effective time.Time) error

func (*DB) UnpauseJob

func (db *DB) UnpauseJob(id uuid.UUID) (bool, error)

func (*DB) UpdateJob

func (db *DB) UpdateJob(id uuid.UUID, target, store, schedule, retention string) error

func (*DB) UpdateRetentionPolicy

func (db *DB) UpdateRetentionPolicy(id uuid.UUID, expiry uint) error

func (*DB) UpdateSchedule

func (db *DB) UpdateSchedule(id uuid.UUID, ts string) error

func (*DB) UpdateStore

func (db *DB) UpdateStore(id uuid.UUID, plugin string, endpoint interface{}) error

func (*DB) UpdateTarget

func (db *DB) UpdateTarget(id uuid.UUID, plugin string, endpoint interface{}, agent string) error

func (*DB) UpdateTaskLog

func (db *DB) UpdateTaskLog(id uuid.UUID, more string) error

type Job added in v0.6.4

type Job struct {
	UUID           uuid.UUID `json:"uuid"`
	Name           string    `json:"name"`
	Summary        string    `json:"summary"`
	RetentionName  string    `json:"retention_name"`
	RetentionUUID  uuid.UUID `json:"retention_uuid"`
	Expiry         int       `json:"expiry"`
	ScheduleName   string    `json:"schedule_name"`
	ScheduleUUID   uuid.UUID `json:"schedule_uuid"`
	ScheduleWhen   string    `json:"schedule_when"`
	Paused         bool      `json:"paused"`
	StoreUUID      uuid.UUID `json:"store_uuid"`
	StoreName      string    `json:"store_name"`
	StorePlugin    string    `json:"store_plugin"`
	StoreEndpoint  string    `json:"store_endpoint"`
	TargetUUID     uuid.UUID `json:"target_uuid"`
	TargetName     string    `json:"target_name"`
	TargetPlugin   string    `json:"target_plugin"`
	TargetEndpoint string    `json:"target_endpoint"`
	Agent          string    `json:"agent"`
	LastRun        Timestamp `json:"last_run"`
	LastTaskStatus string    `json:"last_task_status"`

	Spec    *timespec.Spec `json:"-"`
	NextRun time.Time      `json:"-"`
}

func (*Job) Reschedule added in v0.6.4

func (j *Job) Reschedule() (err error)

func (*Job) Runnable added in v0.6.4

func (j *Job) Runnable() bool

type JobFilter

type JobFilter struct {
	SkipPaused   bool
	SkipUnpaused bool

	SearchName string

	ForTarget    string
	ForStore     string
	ForSchedule  string
	ForRetention string
	ExactMatch   bool
}

func (*JobFilter) Query

func (f *JobFilter) Query(driver string) (string, []interface{})

type NullUUID added in v0.6.4

type NullUUID struct {
	Valid bool
	UUID  uuid.UUID
}

func (*NullUUID) Scan added in v0.6.4

func (v *NullUUID) Scan(value interface{}) error

func (NullUUID) Value added in v0.6.4

func (v NullUUID) Value() (driver.Value, error)

type RetentionFilter

type RetentionFilter struct {
	SkipUsed   bool
	SkipUnused bool
	SearchName string
	ExactMatch bool
}

func (*RetentionFilter) Query

func (f *RetentionFilter) Query() (string, []interface{})

type RetentionPolicy added in v0.6.4

type RetentionPolicy struct {
	UUID    uuid.UUID `json:"uuid"`
	Name    string    `json:"name"`
	Summary string    `json:"summary"`
	Expires uint      `json:"expires"`
}

type Schedule added in v0.6.4

type Schedule struct {
	UUID    uuid.UUID `json:"uuid"`
	Name    string    `json:"name"`
	Summary string    `json:"summary"`
	When    string    `json:"when"`
}

type ScheduleFilter

type ScheduleFilter struct {
	SkipUsed   bool
	SkipUnused bool
	SearchName string
	ExactMatch bool
}

func (*ScheduleFilter) Query

func (f *ScheduleFilter) Query() (string, []interface{})

type Schema

type Schema interface {
	Deploy(*DB) error
}

type Store added in v0.6.4

type Store struct {
	UUID     uuid.UUID `json:"uuid"`
	Name     string    `json:"name"`
	Summary  string    `json:"summary"`
	Plugin   string    `json:"plugin"`
	Endpoint string    `json:"endpoint"`
}

type StoreFilter

type StoreFilter struct {
	SkipUsed   bool
	SkipUnused bool
	SearchName string
	ForPlugin  string
	ExactMatch bool
}

func (*StoreFilter) Query

func (f *StoreFilter) Query() (string, []interface{})

type Target added in v0.6.4

type Target struct {
	UUID     uuid.UUID `json:"uuid"`
	Name     string    `json:"name"`
	Summary  string    `json:"summary"`
	Plugin   string    `json:"plugin"`
	Endpoint string    `json:"endpoint"`
	Agent    string    `json:"agent"`
}

type TargetFilter

type TargetFilter struct {
	SkipUsed   bool
	SkipUnused bool
	SearchName string
	ForPlugin  string
	ExactMatch bool
}

func (*TargetFilter) Query

func (f *TargetFilter) Query() (string, []interface{})

type Task added in v0.6.4

type Task struct {
	UUID           uuid.UUID      `json:"uuid"`
	Owner          string         `json:"owner"`
	Op             string         `json:"type"`
	JobUUID        uuid.UUID      `json:"job_uuid"`
	ArchiveUUID    uuid.UUID      `json:"archive_uuid"`
	StoreUUID      uuid.UUID      `json:"-"`
	StorePlugin    string         `json:"-"`
	StoreEndpoint  string         `json:"-"`
	TargetUUID     uuid.UUID      `json:"-"`
	TargetPlugin   string         `json:"-"`
	TargetEndpoint string         `json:"-"`
	Status         string         `json:"status"`
	StartedAt      Timestamp      `json:"started_at"`
	StoppedAt      Timestamp      `json:"stopped_at"`
	TimeoutAt      Timestamp      `json:"-"`
	Attempts       int            `json:"-"`
	RestoreKey     string         `json:"-"`
	Agent          string         `json:"-"`
	Log            string         `json:"log"`
	TaskUUIDChan   chan *TaskInfo `json:"-"`
}

type TaskFilter

type TaskFilter struct {
	UUID         string
	SkipActive   bool
	SkipInactive bool
	ForStatus    string
	Limit        string
}

func (*TaskFilter) Query

func (f *TaskFilter) Query() (string, []interface{})

type TaskInfo added in v0.6.4

type TaskInfo struct {
	Info string //UUID if not Err. Error message if Err.
	Err  bool
}

Jump to

Keyboard shortcuts

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