Commit ffa8e204 authored by Joan Piles's avatar Joan Piles Committed by root

Added -schedFile command line option for specifying additional schedules

parent f7e96278
......@@ -47,6 +47,7 @@ type Config struct {
NoPurge bool
NoWait bool
NoLogDate bool
SchedFile string
}
// WriteCache writes the global configuration to disk as a json file.
......@@ -78,6 +79,10 @@ func (c *Config) ReadCache() error {
}
c.RsyncPath = t.RsyncPath
c.RsyncOpts = t.RsyncOpts
if t.SchedFile != "" {
c.SchedFile = t.SchedFile
schedules.AddFromFile(c.SchedFile)
}
c.Origin = t.Origin
if _, ok := schedules[t.Schedule]; ok == false {
log.Fatalln("no such schedule:", t.Schedule)
......@@ -96,6 +101,7 @@ func usage() {
Commands:
run Periodically create snapshots
list List snapshots
scheds List schedules
help Show usage instructions
Use <command> -h to show possible options for <command>.
Examples:
......@@ -142,8 +148,14 @@ func LoadConfig() *Config {
flags.BoolVar(&(config.NoLogDate),
"noLogDate", false,
"if set, does not print date and time in the log output. Useful if output is redirected to syslog")
flags.Parse(os.Args[2:])
if _, ok := schedules[config.Schedule]; ok == false {
flags.StringVar(&(config.SchedFile),
"schedFile", "",
"path to rsync binary")
flags.Parse(os.Args[2:])
if config.SchedFile != "" {
schedules.AddFromFile(config.SchedFile)
}
if _, ok := schedules[config.Schedule]; ok == false {
log.Fatalln("no such schedule:", config.Schedule)
}
path := filepath.Join(config.repository, DATA_SUBDIR)
......@@ -173,8 +185,14 @@ func LoadConfig() *Config {
flags.StringVar(&(config.Schedule),
"schedule", "longterm",
"one of "+schedules.String())
flags.Parse(os.Args[2:])
err := config.ReadCache()
flags.StringVar(&(config.SchedFile),
"schedFile", "",
"path to rsync binary")
flags.Parse(os.Args[2:])
if config.SchedFile != "" {
schedules.AddFromFile(config.SchedFile)
}
err := config.ReadCache()
if err != nil {
log.Println("error reading cached settings (using defaults):", err)
}
......@@ -186,6 +204,18 @@ func LoadConfig() *Config {
usage()
os.Exit(0)
}
case "scheds":
{
flags := flag.NewFlagSet(subcmd, flag.ExitOnError)
flags.StringVar(&(config.SchedFile),
"schedFile", "",
"path to rsync binary")
flags.Parse(os.Args[2:])
if config.SchedFile != "" {
schedules.AddFromFile(config.SchedFile)
}
return config
}
default:
{
log.Println("unknown subcommand:", subcmd)
......
......@@ -193,7 +193,6 @@ func subcmdList() {
func main() {
logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile)
schedules.AddFromFile("/root/test.sched")
config = LoadConfig()
if config == nil {
log.Fatal("no config, don't know what to do!")
......@@ -214,6 +213,8 @@ func main() {
case "list":
fmt.Printf("### Repository: %s, Origin: %s, Schedule: %s\n", config.repository, config.Origin, config.Schedule)
subcmdList()
case "scheds":
schedules.List()
}
os.Exit(0)
}
......@@ -62,7 +62,7 @@ var schedules = scheduleList{
"testing2": {second * 5, second * 20, second * 40, second * 80, long},
}
func (schl *scheduleList) AddFromFile(file string) {
func (schl scheduleList) AddFromFile(file string) {
schedFile, err := ioutil.ReadFile(file)
if err != nil {
fmt.Printf("Error opening schedule file: %v\n", err)
......@@ -76,6 +76,12 @@ func (schl *scheduleList) AddFromFile(file string) {
}
for k,v := range readData {
schedules[k] = v
schl[k] = v
}
}
func (schl scheduleList) List() {
for name,sched := range schl {
fmt.Println(name,": ", sched);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment