controller

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2017 License: MIT Imports: 23 Imported by: 0

README

Backup Controller

介绍

backup controller的定位是为了结合Lain扩充backupd的功能。如从lainlet中获取备份任务;记录任务执行结果等。 对用户而言,是不知道backupd的存在的,所有的请求都是发给controller,然后controller再转发给backupd拿到相应的备份结果。

设计

controller的实现很简单,一个goroutine通过watch lainlet获取最新的备份任务。然后把任务发送给指定的backupd。backupd执行完任务后再讲结果post回给controller。controller使用嵌入式数据库将任务执行记录存放到本地,并对外提供查询功能。

API

获取备份列表
curl /api/v1/backup/json/app/:appname/proc/:proc?volume=<volume1>&volume=<volume2>
手动执行一次备份
curl -XPOST /api/v1/cron/once/app/:appname/id/:id
执行一次恢复
curl -XPOST /api/v1/backup/recover/app/:appname/proc/:proc/file/:file
查看调度任务
curl /api/v1/cron/jobs/app/:appname
查看所有调度任务
curl /api/v1/cron/jobs/all
查看备份和恢复任务的历史
curl /api/v1/cron/records/app/:appname
查看备份和恢复任务的历史(指定id)
curl /api/v1/cron/record/app/:appname/id/:id
备份迁移到指定机器
curl -XPOST /api/v1/backup/migrate/app/:appname/proc/:proc/file/:file

postdata:
    volume: <volume>
    from: <instanceNo>
    to: <instanceNo>
增量备份恢复
curl -XPOST /api/v1/backup/recover/increment/app/:appname/proc/:proc/dir/:dir

postdata:
    instanceNo: intance number
    files: files to recover
增量备份迁移
curl -XPOST /api/v1/backup/migrate/increment/app/:appname/proc/:proc/dir/:dir

postdata:
    from: intance number
    to: instance number
    volume: migrate dir
    files: files to migrate
获取增量备份内的文件列表
curl /api/v1/backup/filelist/app/:app/proc/:proc/dir/:dir

API v2

新的API,其实和旧的没什么区别,只是url看起来舒服些.

v2的api中的proc值不需要写类似于hello.web.web的全名,直接写web就ok

注:所有的api前面都要加/api/v2前缀

获取备份列表
GET /app/:app/proc/:proc/backups
获取一个备份文件的信息
GET /app/:app/proc/:proc/backups/:filename?open=false

参数open可选,默认为false, 表示查看增量备份文件夹内文件列表。 如果filename指定的增量备份目录不存在,返回错误.

删除备份文件
POST /app/:app/proc/:proc/backups/actions/delete

postdata:
    files: []string 要删除的文件
备份恢复
POST /app/:app/proc/:proc/backups/:file/actions/recover

postdata:(可选)
    files: 列表  # 如果<:file>是增量备份, 则该参数指定备份目录下的文件列表, 全量备份不用

备份迁移
POST /app/:app/proc/:proc/backups/:file/actions/migrate

postdata:
    volume: <volume>
    to: <instanceNo>
    files(可选): 如果指定的是增量备份,则需要指定要迁移的文件
获取app的任务列表
GET /app/:app/cron/jobs
获取一个app下的某一个任务的详情
GET /app/:app/cron/jobs/:id
获取一个app的任务记录
GET /app/:app/cron/records
获取一条任务记录
GET /app/:app/cron/records/:rid
对某一条任务执行特定动作

action 支持 run

  • run表示立刻执行一次任务
POST /app/:app/cron/jobs/:id/actions/:action
查看一台机器上backupd的所有任务
GET /server/:ip/cron/jobs
查看一台机器上backupd的debug信息
GET /server/:ip/debug

Documentation

Index

Constants

View Source
const (
	VOLUME_ROOT    = "/data/lain/volumes"
	BackupFunc     = "backup"
	ExpireFunc     = "backup_expire"
	ExpireSchedule = "* * * * *"
	NotifyURI      = "/api/v2/system/notify"
)

Variables

View Source
var (
	DaemonPort      = 9002
	DaemonApiPrefix = "/api/v1"
)

Functions

func BackupDB

func BackupDB(r render.Render, req *http.Request)

func BackupDelete

func BackupDelete(r render.Render, params martini.Params, let *Lainlet, req *http.Request)

func BackupFileInfoOrFileList

func BackupFileInfoOrFileList(r render.Render, params martini.Params, let *Lainlet, req *http.Request)

func BackupMigrate

func BackupMigrate(r render.Render, req *http.Request, params martini.Params, let *Lainlet)

func BackupMigrateIncrement

func BackupMigrateIncrement(r render.Render, req *http.Request, params martini.Params, let *Lainlet)

func BackupRecover

func BackupRecover(r render.Render, req *http.Request, params martini.Params, let *Lainlet)

func BackupRecoverIncrement

func BackupRecoverIncrement(r render.Render, req *http.Request, params martini.Params, let *Lainlet)

func CronAction

func CronAction(r render.Render, params martini.Params, let *Lainlet)

func CronOnce

func CronOnce(r render.Render, params martini.Params, let *Lainlet)

func GetAllCronJobs

func GetAllCronJobs(r render.Render, let *Lainlet)

func GetBackup

func GetBackup(r render.Render, params martini.Params, req *http.Request, let *Lainlet)

func GetCronJob

func GetCronJob(r render.Render, params martini.Params, let *Lainlet)

func GetCronJobs

func GetCronJobs(r render.Render, req *http.Request, params martini.Params, let *Lainlet)

func GetCronRecord

func GetCronRecord(r render.Render, params martini.Params, let *Lainlet)

func GetCronRecordV2

func GetCronRecordV2(r render.Render, params martini.Params)

func GetCronRecords

func GetCronRecords(r render.Render, req *http.Request, params martini.Params, let *Lainlet)

func GetCronRecordsV2

func GetCronRecordsV2(r render.Render, params martini.Params, req *http.Request)

func GetIncrementBackupFileList

func GetIncrementBackupFileList(r render.Render, params martini.Params, let *Lainlet)

func NotFound

func NotFound(r render.Render)

func Notify

func Notify(r render.Render, req *http.Request)

func Serve

func Serve(addr string, lainlet *Lainlet)

func ServerCronJobs

func ServerCronJobs(r render.Render, params martini.Params, let *Lainlet)

func ServerCronStats

func ServerCronStats(r render.Render, params martini.Params)

func ServerDebug

func ServerDebug(r render.Render, params martini.Params)

Types

type Annotation

type Annotation struct {
	Mountpoint []string     `json:"mountpoint"`
	Backup     []BackupInfo `json:"backup"`
}

annotation in body shoule be like this:

{
  "mountpoint": [
    "hello.lain.local/foo",
    "hello.lain"
  ],
  "backup": [
    {
      "procname": "hello.web.web",
      "expire": "30d",
      "schedule": "0 0 5 0 0",
      "volume": "/dev/registry",
      "preRun": "./backup.sh",
      "postRun": "end.sh",
    }
  ]
}

type Backend

type Backend struct {
	Addr   string
	Prefix string
}

func NewBackend

func NewBackend(addr, prefix string) *Backend

func (*Backend) BackupDelete

func (end *Backend) BackupDelete(files []string) error

func (*Backend) BackupInfo

func (end *Backend) BackupInfo(file string) (BackupEntity, error)

func (*Backend) BackupRecover

func (end *Backend) BackupRecover(namespace, file, destDir string, extra map[string]string) (string, error)

func (*Backend) BackupRecoverIncrement

func (end *Backend) BackupRecoverIncrement(namespace, dir, destDir string, files []string, extra map[string]string) (string, error)

func (*Backend) CronAction

func (end *Backend) CronAction(id, action string) (string, error)

func (*Backend) CronOnce

func (end *Backend) CronOnce(id string) (string, error)

func (*Backend) Debug

func (end *Backend) Debug() (map[string]interface{}, error)

func (*Backend) FixCronJobArgs

func (end *Backend) FixCronJobArgs(action string, args crond.FuncArg)

func (*Backend) GetBackup

func (end *Backend) GetBackup(volumes ...string) ([]BackupEntity, error)

func (*Backend) GetBackupInfo

func (end *Backend) GetBackupInfo(file string) (BackupEntity, error)

func (*Backend) GetCronJob

func (end *Backend) GetCronJob(id string) (crond.Job, error)

func (*Backend) GetCronJobs

func (end *Backend) GetCronJobs(appname string, query map[string]string) ([]crond.EntrySpec, error)

func (*Backend) GetCronRecordById

func (end *Backend) GetCronRecordById(id string) (crond.JobRecord, error)

func (*Backend) GetCronRecords

func (end *Backend) GetCronRecords(appname string, query map[string]string) ([]crond.JobRecord, error)

func (*Backend) GetNotify

func (end *Backend) GetNotify() ([]string, error)

func (*Backend) IncrementBackupFileList

func (end *Backend) IncrementBackupFileList(dir string) ([]api.FInfo, error)

func (*Backend) RawRequest

func (end *Backend) RawRequest(method, uri string, data url.Values) ([]byte, error)

func (*Backend) RemoveNotify

func (end *Backend) RemoveNotify(addr string) error

func (*Backend) SetCronJobs

func (end *Backend) SetCronJobs(jobs []crond.Job) error

func (*Backend) SetNotify

func (end *Backend) SetNotify(addr string) error

func (*Backend) StartCrond

func (end *Backend) StartCrond() error

func (*Backend) StopCrond

func (end *Backend) StopCrond() error

type BackupEntity

type BackupEntity struct {
	Volume     string    `json:"volume"`
	Name       string    `json:"name"`
	Size       uint64    `json:"size"`
	Created    time.Time `json:"created"`
	InstanceNo int       `json:"instanceNo"`
}

type BackupInfo

type BackupInfo struct {
	AppName    string   `json:"appname"`
	ProcName   string   `json:"procname"`
	Containers []string `json:"containers"`
	InstanceNo int      `json:"instanceNo"`
	Volume     string   `json:"volume"`
	Expire     string   `json:"expire"`
	Schedule   string   `json:"schedule"`
	PreRun     string   `json:"preRun"`
	PostRun    string   `json:"postRun"`
	Mode       string   `json:"mode"`
}

func (*BackupInfo) ArchiveName

func (bi *BackupInfo) ArchiveName() string

func (*BackupInfo) Dir

func (bi *BackupInfo) Dir() string

func (*BackupInfo) Valid

func (bi *BackupInfo) Valid() bool

type Controller

type Controller struct {
	App string
	// contains filtered or unexported fields
}

func NewController

func NewController(app string, lainlet *Lainlet) *Controller

func (*Controller) BackupFileInfo

func (c *Controller) BackupFileInfo(proc, file string) (BackupEntity, error)

func (*Controller) BackupRecover

func (c *Controller) BackupRecover(proc, volume, file string, from int, to int) (string, error)

func (*Controller) CronAction

func (c *Controller) CronAction(id, action string) (string, error)

func (*Controller) CronOnce

func (c *Controller) CronOnce(id string) (string, error)

func (*Controller) DeleteBackup

func (c *Controller) DeleteBackup(proc string, files []string) error

func (*Controller) GetBackup

func (c *Controller) GetBackup(proc string, volumes ...string) ([]BackupEntity, error)

func (*Controller) GetCronJob

func (c *Controller) GetCronJob(id string) (crond.Job, error)

func (*Controller) GetCronJobs

func (c *Controller) GetCronJobs(query map[string]string) ([]crond.EntrySpec, error)

func (*Controller) GetCronRecordById

func (c *Controller) GetCronRecordById(id string) (crond.JobRecord, error)

func (*Controller) GetCronRecords

func (c *Controller) GetCronRecords(query map[string]string) ([]crond.JobRecord, error)

func (*Controller) IncrementBackupFileList

func (c *Controller) IncrementBackupFileList(proc, dir string) ([]api.FInfo, error)

func (*Controller) IncrementBackupRecover

func (c *Controller) IncrementBackupRecover(proc, volume string, from, to int, backupDir string, files []string) (string, error)

type Lainlet

type Lainlet struct {
	Addr string
	// contains filtered or unexported fields
}

func NewLainlet

func NewLainlet(addr string) *Lainlet

func (*Lainlet) AbsDir

func (ll *Lainlet) AbsDir(app, proc string, instanceNo int, volume string) string

func (*Lainlet) BroadcastCronJobs

func (ll *Lainlet) BroadcastCronJobs(nodes []string)

func (*Lainlet) CheckBackend

func (ll *Lainlet) CheckBackend()

func (*Lainlet) DictKey

func (ll *Lainlet) DictKey(app, proc string) string

func (*Lainlet) GetCoreInfo

func (ll *Lainlet) GetCoreInfo(app string) map[string][]lainlet.PodInfoForBackupctl

func (*Lainlet) GetJobs

func (ll *Lainlet) GetJobs() map[string][]crond.Job

func (*Lainlet) GetNode

func (ll *Lainlet) GetNode(app, proc string, instanceNo int) (string, error)

func (*Lainlet) GetNodes

func (ll *Lainlet) GetNodes(app, proc string) ([]string, error)

func (*Lainlet) ProcFullName

func (ll *Lainlet) ProcFullName(app, proc string) (string, bool)

func (*Lainlet) UpdateCronJobs

func (ll *Lainlet) UpdateCronJobs() []string

iterate the Lainlet.data, generate jobs for every node jobs stored into Lainlet.cronJobs

func (*Lainlet) VolumeAbs

func (ll *Lainlet) VolumeAbs(app, proc string, volumes ...string) ([]string, error)

func (*Lainlet) Volumes

func (ll *Lainlet) Volumes(app, proc string) ([]string, error)

func (*Lainlet) Watcher

func (ll *Lainlet) Watcher()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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