Exemplo n.º 1
0
func indexLocalFiles(planName string) error {
	if localFilesIndexByPlan == nil {
		localFilesIndexByPlan = make(map[string]map[string]core.NodeMetaInfo)
	}

	if _, exists := localFilesIndexByPlan[planName]; exists {
		return nil
	}

	plan, err := core.GetBackupPlan(planName)
	if err != nil {
		return err
	}

	localFilesIndexByPlan[plan.Name] = make(map[string]core.NodeMetaInfo)
	var nodes core.NodeList
	for _, path := range plan.NodesToArchive {
		if _, err = os.Stat(path); err != nil {
			if os.IsNotExist(err) {
				continue
			} else {
				return err
			}
		}
		err = filepath.Walk(path, nodes.AddNodeToList)
		if err != nil {
			return err
		}
	}
	for _, node := range nodes.GetList() {
		localFilesIndexByPlan[plan.Name][node.GetNodePath()] = node
	}
	return nil
}
Exemplo n.º 2
0
func mainHandler(w http.ResponseWriter, r *http.Request) {
	parts := strings.Split(r.URL.Path, "/")
	if len(parts) > 1 && parts[1] == "plan" {
		planName := ""
		if len(parts) > 2 {
			planName = parts[2]
		}

		if !core.IsBackupPlanExists(planName) {
			fmt.Fprintf(w, "Plan \"%s\" is not exists", planName)
			return
		}
		currentPlanName = planName

		plan, err := core.GetBackupPlan(planName)
		if err != nil {
			fmt.Fprintf(w, "Error occured with getting info about plan \"%s\": %v", planName, err)
			return
		}

		cmds := []string{"archived_list"}
		defaultCmd := cmds[0]

		cmd := ""
		if len(parts) > 3 {
			cmd = parts[3]
		}
		if cmd != "" {
			switch cmd {
			case "archived_list":
				cmd_ArchivedList(w, r, plan)
			default:
				http.NotFound(w, r)
			}
		} else {
			http.Redirect(w, r, "/plan/"+planName+"/"+defaultCmd, 302)
		}
	} else {
		http.Redirect(w, r, "/plan/"+currentPlanName, 302)
	}
}
Exemplo n.º 3
0
func parseCmd() {
	var planName = flag.String("plan", "", "")
	var createPlan = flag.Bool("create-plan", false, "")
	cmd_flags := make(map[string]*bool)
	cmd_list := []string{"edit", "view", "status", "backup", "restore", "sync", "web-ui"}
	for _, cmd := range cmd_list {
		cmd_flags[cmd] = flag.Bool(cmd, false, "")
	}

	flag.Usage = func() {
		fmt.Printf("usage: %s --create-plan\n", os.Args[0])
		fmt.Printf("       %s --plan my_plan_name --<command>\n", os.Args[0])
		fmt.Println("possible commands:")
		for _, cmd := range cmd_list {
			fmt.Printf("    --%v\n", cmd)
		}
		// flag.PrintDefaults()
		os.Exit(0)
	}

	flag.Parse()

	if *createPlan {
		cmds.Create()
	} else if *planName != "" {
		plan, err := core.GetBackupPlan(*planName)
		if err != nil {
			fmt.Println(err)
			return
		} else {
			cmd_selected := ""
			for cmd, sel := range cmd_flags {
				if *sel {
					if cmd_selected == "" {
						cmd_selected = cmd
					} else {
						fmt.Println("Only one command must be selected to run for plan\n")
						flag.Usage()
						return
					}
				}
			}
			switch cmd_selected {
			case "edit":
				cmds.Edit(plan)
			case "view":
				cmds.View(plan)
			case "status":
				cmds.Status(plan)
			case "backup":
				cmds.Backup(plan)
			case "restore":
				cmds.Restore(plan)
			case "sync":
				cmds.Sync(plan)
			case "web-ui":
				cmds.WebUI(plan)
			case "":
				fmt.Println("One command must be selected to run for plan\n")
				flag.Usage()
				return
			}

		}
	} else {
		flag.Usage()
		return
	}

}