コード例 #1
0
ファイル: restoreJob.go プロジェクト: sethjback/gobl
// Configure the restore job
func (r *RestoreJob) Configure(rp spec.RestoreParamiter) error {

	//configure modificaitons and reverse
	mods, err := modifications.GetModifications(rp.BackupParamiters.Modifications, true)
	if err != nil {
		return err
	}

	r.Modifications = mods

	//Confirm the Engine we want to restore from was part of the job and configure
	for _, e := range rp.BackupParamiters.Engines {
		if e.Name == rp.From.Name {
			be, err := engines.GetBackupEngines([]engines.Definition{e})
			if err != nil {
				return errors.New("Could not create restore from engine instance: " + err.Error())
			}
			r.From = &be[0]
		}
	}

	if r.From == nil {
		return errors.New("Engine to restore from must have been part of the original backup")
	}

	re, err := engines.GetRestoreEngine(rp.To)
	if err != nil {
		return err
	}
	r.To = &re

	return nil
}
コード例 #2
0
ファイル: restores.go プロジェクト: sethjback/gobl
func RunRestore(rr *spec.RestoreRequest) (int, error) {
	if _, err := engines.GetRestoreEngine(rr.To); err != nil {
		return -1, err
	}

	backupJob, err := gDb.GetJob(rr.JobID)
	if err != nil {
		return -1, err
	}

	found := false
	fromEngine := strings.ToLower(rr.From.Name)
	for _, engine := range backupJob.Definition.(spec.BackupParamiter).Engines {
		fmt.Println(fromEngine, engine)
		if fromEngine == strings.ToLower(engine.Name) {
			found = true
			break
		}
	}

	if !found {
		return -1, errors.New("From engine must have been used in the original backup job")
	}

	agent, err := gDb.GetAgent(backupJob.AgentID)
	if err != nil {
		return -1, err
	}

	jobfiles, err := gDb.JobFileSignatures(rr.JobID, rr.Files)
	if err != nil {
		return -1, err
	}

	fmt.Println("JobFiles: ", jobfiles)

	job, err := gDb.CreateRestoreJob(backupJob.AgentID, rr)

	rp := &spec.RestoreParamiter{
		To:               rr.To,
		From:             rr.From,
		FileSignatures:   jobfiles,
		BackupParamiters: backupJob.Definition.(spec.BackupParamiter)}

	request := &spec.RestoreJobRequest{
		ID:         job.ID,
		Paramiters: *rp}

	bString, err := json.Marshal(request)
	if err != nil {
		return -1, err
	}

	sig, err := keyManager.Sign(string(bString))
	if err != nil {
		return -1, err
	}

	req := &httpapi.APIRequest{
		Address:   agent.Address,
		Body:      bString,
		Signature: sig}

	_, err = req.POST("/restores")
	if err != nil {
		return -1, err
	}

	return job.ID, nil
}