restic-scheduler/job.go

96 lines
2.2 KiB
Go
Raw Normal View History

2022-02-18 22:37:51 +00:00
package main
// JobConfig is all configuration to be sent to Restic
type JobConfig struct {
Repo string `hcl:"repo"`
Passphrase string `hcl:"passphrase"`
Env map[string]string `hcl:"env,optional"`
2022-02-20 06:09:23 +00:00
Args []string `hcl:"args"`
2022-02-18 22:37:51 +00:00
}
// JobTaskScript is a sript to be executed as part of a job task
type JobTaskScript struct {
2022-02-20 06:09:23 +00:00
ScriptPath string `hcl:"path,optional"`
2022-02-18 22:37:51 +00:00
Body string `hcl:"body,optional"`
}
// JobTaskMySQL is a sqlite backup task that performs required pre and post tasks
type JobTaskMySQL struct {
Hostname string `hcl:"hostname,optional"`
Database string `hcl:"database,optional"`
Username string `hcl:"username,optional"`
Password string `hcl:"password,optional"`
}
// JobTaskSqlite is a sqlite backup task that performs required pre and post tasks
type JobTaskSqlite struct {
Path string `hcl:"path,label"`
}
// JobTask represents a single task within a backup job
type JobTask struct {
Name string `hcl:"name,label"`
OnBackup []JobTaskScript `hcl:"on_backup,block"`
OnRestore []JobTaskScript `hcl:"on_restore,block"`
MySql []JobTaskMySQL `hcl:"mysql,block"`
Sqlite []JobTaskSqlite `hcl:"sqlite,block"`
2022-02-20 06:09:23 +00:00
Files []string `hcl:"files,optional"`
2022-02-18 22:37:51 +00:00
}
// Job contains all configuration required to construct and run a backup
// and restore job
type Job struct {
Name string `hcl:"name,label"`
Schedule string `hcl:"schedule"`
Config JobConfig `hcl:"config,block"`
Tasks []JobTask `hcl:"task,block"`
Validate bool `hcl:"validate,optional"`
}
2022-02-20 06:09:23 +00:00
func (job Job) NewRestic() ResticCmd {
return ResticCmd{
LogPrefix: job.Name,
Repo: job.Config.Repo,
Env: job.Config.Env,
Passphrase: job.Config.Passphrase,
}
}
2022-02-18 22:37:51 +00:00
type Config struct {
2022-02-20 06:09:23 +00:00
Jobs []Job `hcl:"job,block"`
2022-02-18 22:37:51 +00:00
}
/***
job "My App" {
2022-02-20 06:09:23 +00:00
schedule = "* * * * *"
config {
repo = "s3://..."
passphrase = "foo"
}
2022-02-18 22:37:51 +00:00
2022-02-20 06:09:23 +00:00
task "Dump mysql" {
mysql {
hostname = "foo"
username = "bar"
2022-02-18 22:37:51 +00:00
}
2022-02-20 06:09:23 +00:00
}
2022-02-18 22:37:51 +00:00
2022-02-20 06:09:23 +00:00
task "Create biz file" {
on_backup {
body = <<EOF
echo foo > /biz.txt
EOF
2022-02-18 22:37:51 +00:00
}
2022-02-20 06:09:23 +00:00
}
2022-02-18 22:37:51 +00:00
2022-02-20 06:09:23 +00:00
task "Backup data files" {
files = [
"/foo/bar",
"/biz.txt",
]
}
2022-02-18 22:37:51 +00:00
}
***/